Prepare translated versions of the home, Get started, Guides and FAQ pages in zh-Hans, zh-Hant, ja, ko, de and fr. English stays at the root and each language lives under its own directory. No translated page exists yet, so English pages only gain an og:locale tag. - LANGUAGES in website.py owns each language's directory, lang/hreflang tag, menu name and og:locale; locales/<language>.json holds the shared UI text (non-English locales start as English placeholders). - sync renders the header, footer and sharing regions in the page's language: localized navigation with an EN badge on English-only targets, a native-details language menu (same page, else the language's reviewed home, else omitted), hreflang alternates with x-default, og:locale alternates and the brand link to the language's home. - Translations record source-sha256 and status (draft or reviewed). Drafts are noindex and stay out of the sitemap, menus, hreflang and navigation. - sync copies every Copy-targeted code block from English by ID, and fills the website:translation-notice region when the English text has changed. The hash leaves out shared regions and those code blocks. - The verifier checks records, copied code, ID/Copy/data-msg parity while fresh, whitespace between CJK characters in ja/zh, and the page's lang. An out-of-date translation, inline-code differences, links to English pages with a reviewed translation and English placeholder UI strings are warnings, shown as GitHub annotations and in the job summary. - New commands: `translate <language> <route>` creates a draft and `translations` reports status, freshness and OS names to confirm. - styles.css adds per-language CJK font stacks, CJK heading, emphasis and line-breaking rules, German hyphenation, and the menu, badge and notice. - The publisher runs sync after the checks so notices are current. - website/translation.md documents the workflow, rules, register, glossary (with Korean), OS names to confirm and the review checklist. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
186 lines
6.7 KiB
YAML
186 lines
6.7 KiB
YAML
name: Publish REA website
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
target:
|
|
description: Publish both hosts, or Pages while configuring Cloudflare
|
|
type: choice
|
|
required: true
|
|
default: both
|
|
options:
|
|
- both
|
|
- pages
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
concurrency:
|
|
group: website-pages
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
prepare:
|
|
if: github.ref == 'refs/heads/main'
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 10
|
|
permissions:
|
|
contents: read
|
|
pages: read
|
|
steps:
|
|
- name: Validate the publication target
|
|
env:
|
|
PUBLISH_TARGET: ${{ inputs.target }}
|
|
run: |
|
|
case "$PUBLISH_TARGET" in
|
|
both|pages) ;;
|
|
*) echo "::error::Unknown publication target: $PUBLISH_TARGET"; exit 1 ;;
|
|
esac
|
|
- name: Require Cloudflare publishing credentials
|
|
if: inputs.target == 'both'
|
|
env:
|
|
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
|
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
|
run: |
|
|
if [[ -z "$CLOUDFLARE_API_TOKEN" || -z "$CLOUDFLARE_ACCOUNT_ID" ]]; then
|
|
echo "::error::Set CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID in repository Actions secrets before publishing."
|
|
exit 1
|
|
fi
|
|
- name: Check out the repository
|
|
uses: actions/checkout@v4
|
|
- name: Set up Python for website assets
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: "3.12"
|
|
cache: pip
|
|
cache-dependency-path: website/requirements.txt
|
|
- name: Install sharing-image dependencies
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install --no-install-recommends -y libcairo2 fonts-dejavu-core
|
|
python3 -m pip install -r website/requirements.txt
|
|
- name: Set up Node.js for website script tests
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version-file: .nvmrc
|
|
- name: Check shared HTML, links, assets and contributor workflows
|
|
run: python3 scripts/website.py check
|
|
# An out-of-date translation only warns in checks; publish it with its notice.
|
|
- name: Refresh translation notices
|
|
run: python3 scripts/website.py sync
|
|
- name: Record the published commit
|
|
run: |
|
|
python3 - <<'PY'
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
|
|
Path("website/public/deployment.json").write_text(
|
|
json.dumps({"commit": os.environ["GITHUB_SHA"]}) + "\n",
|
|
encoding="utf-8",
|
|
)
|
|
PY
|
|
- name: Configure Pages
|
|
uses: actions/configure-pages@v5
|
|
- name: Upload the website
|
|
uses: actions/upload-pages-artifact@v4
|
|
with:
|
|
path: website/public
|
|
|
|
deploy:
|
|
needs: prepare
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 15
|
|
permissions:
|
|
contents: read
|
|
actions: read
|
|
pages: write
|
|
id-token: write
|
|
environment:
|
|
name: github-pages
|
|
url: ${{ steps.deployment.outputs.page_url }}
|
|
steps:
|
|
- name: Check out publishing configuration
|
|
if: inputs.target == 'both'
|
|
uses: actions/checkout@v4
|
|
- name: Set up Node.js for Wrangler
|
|
if: inputs.target == 'both'
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version-file: .nvmrc
|
|
- name: Download the verified website
|
|
if: inputs.target == 'both'
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: github-pages
|
|
path: ${{ runner.temp }}/website-archive
|
|
- name: Extract the shared publishing artifact
|
|
if: inputs.target == 'both'
|
|
run: |
|
|
mkdir -p "$RUNNER_TEMP/rea-website-public"
|
|
tar -xf "$RUNNER_TEMP/website-archive/artifact.tar" -C "$RUNNER_TEMP/rea-website-public"
|
|
- name: Publish the website to Cloudflare
|
|
if: inputs.target == 'both'
|
|
uses: cloudflare/wrangler-action@v4
|
|
with:
|
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
|
wranglerVersion: "4.149.0"
|
|
packageManager: npm
|
|
command: deploy --cwd website --env production --assets "${{ runner.temp }}/rea-website-public"
|
|
- name: Publish to GitHub Pages
|
|
id: deployment
|
|
uses: actions/deploy-pages@v4
|
|
- name: Verify the selected published revisions
|
|
env:
|
|
PAGES_URL: ${{ steps.deployment.outputs.page_url }}
|
|
PUBLISH_TARGET: ${{ inputs.target }}
|
|
run: |
|
|
python3 -u - <<'PY'
|
|
import json
|
|
import os
|
|
import sys
|
|
import time
|
|
from urllib.error import URLError
|
|
from urllib.parse import urljoin
|
|
from urllib.request import Request, urlopen
|
|
|
|
expected = os.environ["GITHUB_SHA"]
|
|
pages_url = os.environ["PAGES_URL"]
|
|
if not pages_url:
|
|
sys.exit("GitHub Pages returned no published URL.")
|
|
target = os.environ["PUBLISH_TARGET"]
|
|
if target not in ("both", "pages"):
|
|
sys.exit("Unknown publication target: " + target)
|
|
hosts = {"GitHub Pages": pages_url}
|
|
if target == "both":
|
|
hosts["Cloudflare"] = "https://rea.tools/"
|
|
pending = dict(hosts)
|
|
for attempt in range(24):
|
|
for name, base in list(pending.items()):
|
|
url = urljoin(base, "deployment.json") + "?commit=" + expected
|
|
try:
|
|
request = Request(url, headers={
|
|
"Cache-Control": "no-cache",
|
|
"User-Agent": "REA-Website-Verifier/1.0 (+https://github.com/morluto/rea)",
|
|
})
|
|
with urlopen(request, timeout=10) as response:
|
|
actual = json.load(response).get("commit")
|
|
if actual == expected:
|
|
print(f"{name} serves {expected}: {base}")
|
|
del pending[name]
|
|
else:
|
|
print(f"Waiting for {name}: observed revision {actual}")
|
|
except (URLError, TimeoutError, ValueError) as error:
|
|
print(f"Waiting for {name}: {error}")
|
|
if not pending:
|
|
break
|
|
if attempt < 23:
|
|
time.sleep(5)
|
|
if pending:
|
|
sys.exit("Could not verify published revision on: " + ", ".join(pending))
|
|
with open(os.environ["GITHUB_STEP_SUMMARY"], "a", encoding="utf-8") as summary:
|
|
links = " and ".join(f"[{name}]({url})" for name, url in hosts.items())
|
|
summary.write(f"Published commit `{expected}` to {links}.\n")
|
|
PY
|