website/.forgejo/workflows/generate.yml
Xavier Moffett fb3c175e34
All checks were successful
Generate Website / Generate Website (push) Successful in 16s
Designate scheduled action to execute once per year
- Schedule action runner to run once per year at midnight on
  the first day of January
- Use `sha256sum` instead of `git` commit hashes for revision hash
- Set modification time of `website.tar.zst` to UNIX epoch
- Use GNU tar instead of busybox tar
2024-12-23 02:20:54 -05:00

94 lines
2.9 KiB
YAML

name: Generate Website
on:
workflow_dispatch:
schedule:
- cron: '0 0 1 1 *'
push:
branches:
- master
env:
USER_TOKEN: ${{ secrets.TOKEN }}
USER_NAME: ${{ vars.USER }}
jobs:
generate:
name: Generate Website
runs-on: docker
container:
image: alpine
steps:
- name: Install packages
run: apk add --no-cache nodejs git git-lfs bash curl tar zstd
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout assets
uses: actions/checkout@v4
with:
token: ${{ secrets.TOKEN }}
repository: sapphirus.org/Suo
sparse-checkout: |
templates/assets
dist
path: suo
- name: Pull from LFS
run: |
# Double authentication header workaround for actions/checkout@v4
# https://github.com/actions/checkout/issues/1830#issuecomment-2314758792
AUTH=$(git -C suo config --local http.$SERVER/.extraheader)
git -C suo config --local --unset http.$SERVER/.extraheader
git -C suo config --local http.$SERVER/$REPOSITORY/info/lfs/objects/batch.extraheader "$AUTH"
git -C suo lfs pull
env:
SERVER: ${{ github.server_url }}
REPOSITORY: sapphirus.org/Suo
- name: Fetch suo binary
shell: bash
run: |
POST_URL="https://git.sapphirus.org/api/packages/private/generic/suo/latest/suo"
echo "::group:: Fetching suo"
mkdir ./bin/ &&
curl --silent \
--show-error \
--user $USER_NAME:$USER_TOKEN $POST_URL \
--output ./bin/suo &&
chmod +x ./bin/suo
echo "::endgroup::"
- name: Generate website
run: ./bin/suo && ./suo/dist/assets.sh ./output ./suo
- name: Package website
shell: bash
run: |
echo "::group:: Packaging website"
cd output
tar --mtime=1970-01-01 -acvf website.tar.zst *
SUM=$(sha256sum website.tar.zst); echo "${SUM% *}" > website.ver
echo "::endgroup::"
- name: Upload package
shell: bash
run: |
POST_URL="https://git.sapphirus.org/api/packages/private/generic/website/latest/"
SRC_DIR="./output/"
FILES=$(ls "$SRC_DIR"*.tar.zst "$SRC_DIR"*.ver)
for file in $FILES; do
echo "::group:: Removing $file"
curl --silent \
--show-error \
--user $USER_NAME:$USER_TOKEN \
-X DELETE $POST_URL${file##$SRC_DIR}
echo "::endgroup::"
done
for file in $FILES; do
echo "::group:: Publishing $file"
curl --silent \
--show-error \
--user $USER_NAME:$USER_TOKEN \
--upload-file $file $POST_URL${file##$SRC_DIR}
echo "::endgroup::"
done