87 lines
3.7 KiB
YAML
87 lines
3.7 KiB
YAML
name: Validate
|
|
|
|
on:
|
|
push:
|
|
pull_request:
|
|
|
|
jobs:
|
|
validate:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: actions/setup-python@v5
|
|
with:
|
|
python-version: "3.12"
|
|
- run: python3 tools/validate.py
|
|
- run: python3 -m unittest discover tools/tests -p "test_places*.py"
|
|
|
|
# A change to a fact needs a new [[history]] entry (docs/schema.md), and trail-numbers.txt may
|
|
# only be appended to. The check compares the work with its base, so it needs the history of
|
|
# the base branch: a full clone, not the shallow one that checkout makes by default.
|
|
history:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
- uses: actions/setup-python@v5
|
|
with:
|
|
python-version: "3.12"
|
|
- name: Check the history
|
|
env:
|
|
EVENT: ${{ github.event_name }}
|
|
BASE_REF: ${{ github.base_ref }}
|
|
BEFORE: ${{ github.event.before }}
|
|
run: |
|
|
# A pull request is checked against its target branch; a push against the commit
|
|
# before it. A new branch has no such commit: the tool then uses origin/main.
|
|
if [ "$EVENT" = "pull_request" ]; then
|
|
base="origin/$BASE_REF"
|
|
else
|
|
base="$BEFORE"
|
|
fi
|
|
python3 tools/check_history.py --base "$base"
|
|
- run: python3 -m unittest discover tools/tests -p "test_history.py"
|
|
- run: python3 -m unittest discover tools/tests -p "test_trail_numbers.py"
|
|
- run: python3 -m unittest discover tools/tests -p "test_season*.py"
|
|
|
|
site:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: actions/setup-python@v5
|
|
with:
|
|
python-version: "3.12"
|
|
# Standard library only: no packages to install, and no ImageMagick.
|
|
# web/tools/make_thumbs.py and make_cards.py are manual tools; web/thumbs/ and
|
|
# web/cards/ are committed and the build only copies them (web/olt/thumbs.py, cards.py).
|
|
#
|
|
# The build's store (web/build.py) keeps each trail's derived files under a hash of
|
|
# everything they are made from, so a restored store can only ever save work: an entry is
|
|
# used when its hash is the hash of the files now in the checkout, and is otherwise ignored
|
|
# and replaced. The cache key follows the trails' files and the build's code, so a change
|
|
# to either makes a new cache from the nearest old one.
|
|
- uses: actions/cache@v4
|
|
with:
|
|
path: web/.cache/store
|
|
key: site-store-${{ hashFiles('*/trail.toml', '*/*.geojson', '*/shield.*', '*/elevation.json', 'web/build.py', 'web/olt/geo.py', 'web/olt/hike.py', 'web/olt/records.py', 'web/olt/words.py', 'web/olt/elevation.py', 'web/olt/markup.py', 'web/site.toml') }}
|
|
restore-keys: site-store-
|
|
# The same tests as `python3 -m unittest discover -s web/tests`, with the modules run side
|
|
# by side and the site built once for all of them (web/tests/run.py).
|
|
- run: python3 web/tests/run.py
|
|
# The plain build, as Netlify runs it: this is the second build of the job, so the store the
|
|
# tests filled makes it quick.
|
|
- run: python3 web/build.py --out _site
|
|
|
|
# Netlify builds the site from this repository when asked to. Asking only
|
|
# after both jobs above pass means a broken record or page is never deployed.
|
|
deploy:
|
|
needs: [validate, history, site]
|
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'swaits/longhikes'
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Ask Netlify to build and publish main
|
|
env:
|
|
NETLIFY_BUILD_HOOK: ${{ secrets.NETLIFY_BUILD_HOOK }}
|
|
run: curl -fsS -X POST -d '{}' "$NETLIFY_BUILD_HOOK"
|