Files
breeze/.github/workflows/pages.yml
T

187 lines
6.1 KiB
YAML

name: Cloudflare Pages
on:
push:
branches:
- master
# Refresh available downloads after a release; pushes deploy independently.
workflow_run:
workflows: [Release]
types: [completed]
branches: [master]
pull_request:
workflow_dispatch:
inputs:
released_web:
description: Use the published web app for a website-only update
type: boolean
default: false
permissions:
contents: read
concurrency:
# A failed Release produces a skipped refresh, which must not cancel a push.
group: pages-${{ github.ref }}-${{ github.event_name == 'workflow_run' && github.event.workflow_run.conclusion != 'success' && 'skipped' || 'deploy' }}
cancel-in-progress: true
jobs:
build:
name: Build Site
runs-on: ubuntu-latest
timeout-minutes: 60
if: github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success'
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
lfs: true
- name: Fetch Ziran packages
uses: ./.github/actions/ziran-packages
- name: Set up Node.js for the web build
uses: actions/setup-node@v4
with:
node-version: 22
- name: Resolve published downloads
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
gh api repos/waozixyz/breeze/releases/latest > "$RUNNER_TEMP/inbe-published-release.json"
python3 - "$RUNNER_TEMP/inbe-published-release.json" >> "$GITHUB_ENV" <<'PY'
import json
import re
import sys
from pathlib import Path
release = json.loads(Path(sys.argv[1]).read_text())
tag = release["tag_name"]
version = tag.removeprefix("v")
assert re.fullmatch(r"(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)", version), "Invalid published release version"
assets = {asset["name"] for asset in release["assets"]}
candidates = [f"inbe-{version}-arm64-v8a.apk", f"inbe-{version}.apk"]
android = next((name for name in candidates if name in assets), None)
assert android is not None, "Published release has no compatible Android APK"
print(f"SITE_RELEASE_VERSION={version}")
print(f"SITE_ANDROID_APK_ASSET={android}")
PY
- name: Install Packages
if: ${{ !inputs.released_web }}
timeout-minutes: 15
run: .github/scripts/install-apt-packages.sh .github/apt/web-packages.txt
- name: Set Up Emscripten
if: ${{ !inputs.released_web }}
uses: ./.github/actions/emscripten
- name: Download Released Web App
if: ${{ inputs.released_web }}
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
version="$SITE_RELEASE_VERSION"
test -n "$version"
mkdir -p build/released-web build/dist/web
gh release download "v$version" --pattern inbe-web.zip --dir build/released-web
unzip -q build/released-web/inbe-web.zip -d build/dist/web
test -s build/dist/web/index.wasm
- name: Web runner diagnostics
if: ${{ !inputs.released_web }}
run: |
set -euo pipefail
lscpu
free -m
for browser in chromium chromium-browser google-chrome google-chrome-stable; do
if command -v "$browser" >/dev/null 2>&1; then
"$browser" --version
fi
done
- name: Build Site
run: |
set -euo pipefail
if [ "$RELEASED_WEB" = "true" ]; then
make package-unpackaged-assets
sh site/build.sh
else
export PATH="$INBE_NODE_BIN:$PATH"
node --version
make build-laws
make site
fi
test -f build/site/index.html
test -f build/site/build/web/index.html
test -f build/site/build/web/index.js
test -f build/site/build/web/index.wasm || test -f build/site/build/web/index.wasm.gz || test -f build/site/build/web/index.wasm.parts.json
if [ "$GITHUB_EVENT_NAME" != "pull_request" ]; then
make site-release-assets-check
else
echo "Skipping release asset availability check for pull request build"
fi
env:
GH_TOKEN: ${{ github.token }}
RELEASED_WEB: ${{ inputs.released_web }}
- name: Upload Web diagnostics after a failed build
if: ${{ failure() && !inputs.released_web }}
uses: actions/upload-artifact@v4
with:
name: inbe-web-diagnostics
path: build/dist/web
if-no-files-found: warn
retention-days: 3
- name: Upload Site Artifact
uses: actions/upload-artifact@v4
with:
name: inbe-site
path: build/site
if-no-files-found: error
deploy-preview:
name: Deploy Preview
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'pull_request'
steps:
- name: Download Site Artifact
uses: actions/download-artifact@v4
with:
name: inbe-site
path: build/site
- name: Deploy Preview To Cloudflare Pages
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy build/site --project-name=inbe --branch=${{ github.head_ref || github.ref_name }} --commit-hash=${{ github.sha }}
deploy-production:
name: Deploy Production
runs-on: ubuntu-latest
needs: build
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master'
steps:
- name: Download Site Artifact
uses: actions/download-artifact@v4
with:
name: inbe-site
path: build/site
- name: Deploy Production To Cloudflare Pages
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy build/site --project-name=inbe --branch=master --commit-hash=${{ github.sha }}