Add Github Actions workflows to build, test and deploy site (#9)
authorCAM Gerlach <CAM.Gerlach@Gerlach.CAM>
Thu, 9 Sep 2021 01:10:58 +0000 (20:10 -0500)
committerGitHub <noreply@github.com>
Thu, 9 Sep 2021 01:10:58 +0000 (18:10 -0700)
* Add Github Actions workflows to build, test and deploy site

Signed-off-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
* Copy index and nojekyll assets into output dir on CIs

* Move dir empty check to modular script and improve error messages

.github/workflows/deploy-ghpages.yaml [new file with mode: 0644]
.github/workflows/test-ghpages.yaml [new file with mode: 0644]
assets/.nojekyll [new file with mode: 0644]
assets/index.html [new file with mode: 0644]
ci/build.sh [new file with mode: 0755]
ci/check_dir_empty.py [new file with mode: 0644]
ci/install.sh [new file with mode: 0755]
requirements.txt [new file with mode: 0644]

diff --git a/.github/workflows/deploy-ghpages.yaml b/.github/workflows/deploy-ghpages.yaml
new file mode 100644 (file)
index 0000000..442cc01
--- /dev/null
@@ -0,0 +1,32 @@
+# Build the project and deploy it to GitHub pages
+name: Deploy
+
+on:  # yamllint disable-line rule:truthy
+  push:
+    branches: [master, main, production]
+
+jobs:
+  deploy:
+    name: Build and Deploy API
+
+    runs-on: ubuntu-latest
+
+    steps:
+    - name: Checkout source repository
+      uses: actions/checkout@v2
+    - name: Set up Python
+      uses: actions/setup-python@v2
+      with:
+        python-version: '3.x'
+    - name: Install dependencies
+      shell: bash
+      run: ./ci/install.sh
+    - name: Build API content
+      shell: bash
+      run: ./ci/build.sh
+    - name: Deploy to GitHub Pages
+      uses: JamesIves/github-pages-deploy-action@v4
+      with:
+        BRANCH: gh-pages    # The branch the action should deploy to
+        FOLDER: ./fsf-api-build-output    # The folder the action should deploy
+        CLEAN: true    # Automatically remove deleted files from the deploy branch
diff --git a/.github/workflows/test-ghpages.yaml b/.github/workflows/test-ghpages.yaml
new file mode 100644 (file)
index 0000000..95dd3ab
--- /dev/null
@@ -0,0 +1,32 @@
+# Build the project and test that it works correctly
+# Based on https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
+
+name: Test
+
+on:  # yamllint disable-line rule:truthy
+  push:
+    branches: ['staging*']
+  pull_request:
+    branches: [master, main, '*.*', 'staging*', 'production']
+
+jobs:
+  build:
+    name: Build API
+
+    runs-on: ubuntu-latest
+
+    steps:
+    - name: Checkout source repository
+      uses: actions/checkout@v2
+    - name: Set up Python
+      uses: actions/setup-python@v2
+      with:
+        python-version: '3.x'
+    - name: Install dependencies
+      shell: bash
+      run: ./ci/install.sh
+    - name: Build API content
+      shell: bash
+      run: ./ci/build.sh
+    - name: Check output directory is not empty
+      run: python -bb -X dev -W error ./ci/check_dir_empty.py fsf-api-build-output
diff --git a/assets/.nojekyll b/assets/.nojekyll
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/assets/index.html b/assets/index.html
new file mode 100644 (file)
index 0000000..81cfb7c
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="UTF-8">
+    <title>Redirecting to https://github.com/spdx/fsf-api</title>
+    <meta http-equiv="refresh" content="0; URL=https://github.com/spdx/fsf-api">
+    <link rel="canonical" href="https://github.com/spdx/fsf-api">
+  </head>
+  <body>
+    This API is documented at <a href="https://github.com/spdx/fsf-api">https://github.com/spdx/fsf-api</a>.
+  </body>
+</html>
diff --git a/ci/build.sh b/ci/build.sh
new file mode 100755 (executable)
index 0000000..7e77abb
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/bash -ex
+
+python3 -bb -X dev -W error pull.py fsf-api-build-output
+cp -a assets/. fsf-api-build-output/
diff --git a/ci/check_dir_empty.py b/ci/check_dir_empty.py
new file mode 100644 (file)
index 0000000..fe21f5f
--- /dev/null
@@ -0,0 +1,15 @@
+#!/usr/bin/env python3
+#
+# SPDX-License-Identifier: MIT
+
+"""Trivial script to check if a passed directory exists and is not empty."""
+
+import sys
+from pathlib import Path
+
+DIR_PATH = Path(sys.argv[1])
+if not DIR_PATH.exists():
+    sys.exit(f"Output directory {DIR_PATH.as_posix()!r} does not exist")
+dir_empty = not any(DIR_PATH.iterdir())
+if dir_empty:
+    sys.exit(f"Output directory {DIR_PATH.as_posix()!r} was empty")
diff --git a/ci/install.sh b/ci/install.sh
new file mode 100755 (executable)
index 0000000..67c1dbc
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/bash -ex
+
+python3 -m pip install --upgrade pip setuptools wheel
+python3 -m pip install --upgrade -r requirements.txt
diff --git a/requirements.txt b/requirements.txt
new file mode 100644 (file)
index 0000000..ab90481
--- /dev/null
@@ -0,0 +1 @@
+lxml