156 lines
5.2 KiB
YAML
156 lines
5.2 KiB
YAML
name: "Build Web Bundle"
|
|
|
|
on:
|
|
workflow_dispatch: {}
|
|
push:
|
|
branches:
|
|
- master
|
|
|
|
env:
|
|
CARGO_TERM_COLOR: always
|
|
INDEX_HTML_HEAD_REPLACEMENT: <script defer data-domain="dev.graphite.art" data-api="https://graphite.art/visit/event" src="https://graphite.art/visit/script.hash.js"></script>
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: [self-hosted, target/wasm]
|
|
permissions:
|
|
contents: write
|
|
deployments: write
|
|
actions: write
|
|
env:
|
|
RUSTC_WRAPPER: /usr/bin/sccache
|
|
CARGO_INCREMENTAL: 0
|
|
SCCACHE_DIR: /var/lib/github-actions/.cache
|
|
|
|
steps:
|
|
- name: 📥 Clone repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: 🗑 Clear wasm-bindgen cache
|
|
run: rm -r ~/.cache/.wasm-pack || true
|
|
|
|
- name: 🟢 Install Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version-file: .nvmrc
|
|
|
|
- name: 🚧 Install build dependencies
|
|
run: |
|
|
cd frontend
|
|
npm run setup
|
|
|
|
- name: 🦀 Install Rust
|
|
uses: actions-rust-lang/setup-rust-toolchain@v1
|
|
with:
|
|
toolchain: stable
|
|
override: true
|
|
rustflags: ""
|
|
target: wasm32-unknown-unknown
|
|
|
|
- name: ✂ Replace template in <head> of index.html
|
|
run: |
|
|
sed -i "s|<!-- INDEX_HTML_HEAD_REPLACEMENT -->|$INDEX_HTML_HEAD_REPLACEMENT|" frontend/index.html
|
|
|
|
- name: 🌐 Build Graphite web code
|
|
env:
|
|
NODE_ENV: production
|
|
run: mold -run cargo run build web
|
|
|
|
- name: 📤 Publish to Cloudflare Pages
|
|
id: cloudflare
|
|
env:
|
|
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
|
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
|
run: |
|
|
MAX_ATTEMPTS=5
|
|
DELAY=30
|
|
for ATTEMPT in $(seq 1 $MAX_ATTEMPTS); do
|
|
echo "Attempt $ATTEMPT of $MAX_ATTEMPTS..."
|
|
if OUTPUT=$(npx wrangler@3 pages deploy "frontend/dist" --project-name="graphite-dev" --commit-dirty=true 2>&1); then
|
|
URL=$(echo "$OUTPUT" | grep -oP 'https://[^\s]+\.pages\.dev' | tail -1)
|
|
echo "url=$URL" >> "$GITHUB_OUTPUT"
|
|
echo "Published successfully: $URL"
|
|
exit 0
|
|
fi
|
|
echo "Attempt $ATTEMPT failed:"
|
|
echo "$OUTPUT"
|
|
if [ "$ATTEMPT" -lt "$MAX_ATTEMPTS" ]; then
|
|
echo "Retrying in ${DELAY}s..."
|
|
sleep $DELAY
|
|
DELAY=$((DELAY * 3))
|
|
fi
|
|
done
|
|
echo "All $MAX_ATTEMPTS Cloudflare Pages publish attempts failed."
|
|
exit 1
|
|
|
|
- name: 💬 Comment build link URL to commit hash page on GitHub
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
CF_URL: ${{ steps.cloudflare.outputs.url }}
|
|
run: |
|
|
if [ -z "$CF_URL" ]; then
|
|
echo "No Cloudflare URL available, skipping comment."
|
|
exit 1
|
|
fi
|
|
gh api \
|
|
-X POST \
|
|
-H "Accept: application/vnd.github+json" \
|
|
/repos/${{ github.repository }}/commits/$(git rev-parse HEAD)/comments \
|
|
-f body="| 📦 **Build Complete for** $(git rev-parse HEAD) |
|
|
|-|
|
|
| $CF_URL |"
|
|
|
|
- name: ✂ Strip analytics script from built output for clean artifact
|
|
run: |
|
|
sed -i "s|$INDEX_HTML_HEAD_REPLACEMENT||" frontend/dist/index.html
|
|
|
|
- name: 📦 Upload web bundle artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: graphite-web-bundle
|
|
path: frontend/dist
|
|
|
|
- name: 📃 Generate code documentation info for website
|
|
run: |
|
|
cd tools/editor-message-tree
|
|
cargo run
|
|
cd ../..
|
|
mkdir -p artifacts-generated
|
|
mv website/generated/hierarchical_message_system_tree.txt artifacts-generated/hierarchical_message_system_tree.txt
|
|
|
|
- name: 💿 Obtain cache of auto-generated code docs artifacts, to check if they've changed
|
|
id: cache-website-code-docs
|
|
uses: actions/cache/restore@v4
|
|
with:
|
|
path: artifacts
|
|
key: website-code-docs
|
|
|
|
- name: 🔍 Check if auto-generated code docs artifacts changed
|
|
id: website-code-docs-changed
|
|
run: |
|
|
if ! diff --brief --recursive artifacts-generated artifacts; then
|
|
echo "Auto-generated code docs artifacts have changed."
|
|
rm -rf artifacts
|
|
mv artifacts-generated artifacts
|
|
echo "changed=true" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "Auto-generated code docs artifacts have not changed."
|
|
rm -rf artifacts
|
|
rm -rf artifacts-generated
|
|
fi
|
|
|
|
- name: 💾 Save cache of auto-generated code docs artifacts
|
|
if: steps.website-code-docs-changed.outputs.changed == 'true'
|
|
uses: actions/cache/save@v4
|
|
with:
|
|
path: artifacts
|
|
key: ${{ steps.cache-website-code-docs.outputs.cache-primary-key }}
|
|
|
|
- name: ♻️ Trigger website rebuild if the auto-generated code docs artifacts have changed
|
|
if: steps.website-code-docs-changed.outputs.changed == 'true'
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
rm -rf artifacts
|
|
gh workflow run website.yml --ref master
|