From c38757aab19bc8589dbd93fc8df5431486519d6f Mon Sep 17 00:00:00 2001 From: CAM Gerlach Date: Wed, 8 Sep 2021 20:10:58 -0500 Subject: [PATCH] Add Github Actions workflows to build, test and deploy site (#9) * Add Github Actions workflows to build, test and deploy site Signed-off-by: C.A.M. Gerlach * 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 | 32 +++++++++++++++++++++++++++ .github/workflows/test-ghpages.yaml | 32 +++++++++++++++++++++++++++ assets/.nojekyll | 0 assets/index.html | 12 ++++++++++ ci/build.sh | 4 ++++ ci/check_dir_empty.py | 15 +++++++++++++ ci/install.sh | 4 ++++ requirements.txt | 1 + 8 files changed, 100 insertions(+) create mode 100644 .github/workflows/deploy-ghpages.yaml create mode 100644 .github/workflows/test-ghpages.yaml create mode 100644 assets/.nojekyll create mode 100644 assets/index.html create mode 100755 ci/build.sh create mode 100644 ci/check_dir_empty.py create mode 100755 ci/install.sh create mode 100644 requirements.txt diff --git a/.github/workflows/deploy-ghpages.yaml b/.github/workflows/deploy-ghpages.yaml new file mode 100644 index 0000000..442cc01 --- /dev/null +++ b/.github/workflows/deploy-ghpages.yaml @@ -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 index 0000000..95dd3ab --- /dev/null +++ b/.github/workflows/test-ghpages.yaml @@ -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 index 0000000..e69de29 diff --git a/assets/index.html b/assets/index.html new file mode 100644 index 0000000..81cfb7c --- /dev/null +++ b/assets/index.html @@ -0,0 +1,12 @@ + + + + + Redirecting to https://github.com/spdx/fsf-api + + + + + This API is documented at https://github.com/spdx/fsf-api. + + diff --git a/ci/build.sh b/ci/build.sh new file mode 100755 index 0000000..7e77abb --- /dev/null +++ b/ci/build.sh @@ -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 index 0000000..fe21f5f --- /dev/null +++ b/ci/check_dir_empty.py @@ -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 index 0000000..67c1dbc --- /dev/null +++ b/ci/install.sh @@ -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 index 0000000..ab90481 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +lxml -- 2.25.1