159 lines
6.0 KiB
YAML
159 lines
6.0 KiB
YAML
# USAGE:
|
|
# After reviewing the code, core team members may comment on a PR with the exact text:
|
|
# - `!build-debug` to build with debug symbols and optimizations disabled
|
|
# - `!build` to build without debug symbols and optimizations enabled
|
|
# The comment may not contain any other text, not even whitespace or newlines.
|
|
name: "!build PR Command"
|
|
|
|
on:
|
|
issue_comment:
|
|
types:
|
|
- created
|
|
env:
|
|
CARGO_TERM_COLOR: always
|
|
|
|
jobs:
|
|
build:
|
|
# Command should be limited to core team members (those in the organization) for security.
|
|
# From the GitHub Actions docs:
|
|
# author_association = 'MEMBER': Author is a member of the organization that owns the repository.
|
|
if: >
|
|
github.event.issue.pull_request &&
|
|
github.event.comment.author_association == 'MEMBER' &&
|
|
(github.event.comment.body == '!build-debug' || github.event.comment.body == '!build')
|
|
runs-on: self-hosted
|
|
permissions:
|
|
contents: read
|
|
deployments: write
|
|
pull-requests: write
|
|
env:
|
|
RUSTC_WRAPPER: /usr/bin/sccache
|
|
CARGO_INCREMENTAL: 0
|
|
SCCACHE_DIR: /var/lib/github-actions/.cache
|
|
|
|
steps:
|
|
- name: 🔎 Find branch for this PR
|
|
id: commit_info
|
|
run: |
|
|
RESPONSE=$(curl -L -H 'Accept: application/vnd.github+json' -H 'X-GitHub-Api-Version: 2022-11-28' https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.issue.number }})
|
|
REPO=$(echo $RESPONSE | jq -r '.head.repo.full_name')
|
|
REF=$(echo $RESPONSE | jq -r '.head.ref')
|
|
SHA=$(echo $RESPONSE | jq -r '.head.sha')
|
|
echo "repo=$REPO" >> $GITHUB_OUTPUT
|
|
echo "ref=$REF" >> $GITHUB_OUTPUT
|
|
echo "sha=$SHA" >> $GITHUB_OUTPUT
|
|
|
|
- name: 📥 Clone repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
repository: ${{ steps.commit_info.outputs.repo }}
|
|
ref: ${{ steps.commit_info.outputs.ref }}
|
|
|
|
- name: 🗑 Clear wasm-bindgen cache
|
|
continue-on-error: true
|
|
run: rm -r ~/.cache/.wasm-pack
|
|
|
|
- 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
|
|
env:
|
|
INDEX_HTML_HEAD_REPLACEMENT: ""
|
|
run: |
|
|
# Remove the INDEX_HTML_HEAD_REPLACEMENT environment variable for build links (not master deploys)
|
|
sed -i "s|<!-- INDEX_HTML_HEAD_REPLACEMENT -->|$INDEX_HTML_HEAD_REPLACEMENT|" frontend/index.html
|
|
|
|
- name: ⌨ Set build command based on comment
|
|
id: build_command
|
|
run: |
|
|
if [[ "${{ github.event.comment.body }}" == "!build-debug" ]]; then
|
|
echo "command=build web debug" >> $GITHUB_OUTPUT
|
|
elif [[ "${{ github.event.comment.body }}" == "!build" ]]; then
|
|
echo "command=build web" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "Failed to detect if the build command written in the comment should have been '!build-debug', or '!build'" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: 💬 Comment Actions run link
|
|
id: comment_actions_run_link
|
|
uses: actions/github-script@v6
|
|
with:
|
|
script: |
|
|
github.rest.issues.updateComment({
|
|
comment_id: ${{ github.event.comment.id }},
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
body: '!build ([Run ID ' + context.runId + '](https://github.com/GraphiteEditor/Graphite/actions/runs/' + context.runId + '))'
|
|
});
|
|
|
|
- name: 🌐 Build Graphite web code
|
|
env:
|
|
NODE_ENV: production
|
|
if: ${{ success() || failure()}}
|
|
run: mold -run cargo run ${{ steps.build_command.outputs.command }}
|
|
|
|
- name: ❗ Warn on build failure
|
|
if: ${{ failure() }}
|
|
uses: actions/github-script@v6
|
|
with:
|
|
script: |
|
|
github.rest.issues.createComment({
|
|
issue_number: context.issue.number,
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
body: 'The build process has failed. Please check the [build logs](https://github.com/GraphiteEditor/Graphite/actions/runs/' + context.runId + ') for details.'
|
|
});
|
|
|
|
- name: 📤 Publish to Cloudflare Pages
|
|
id: cloudflare
|
|
env:
|
|
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
|
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
|
run: |
|
|
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"
|
|
else
|
|
echo "$OUTPUT"
|
|
exit 1
|
|
fi
|
|
|
|
- name: ❗ Warn on publish failure
|
|
if: ${{ failure() }}
|
|
uses: actions/github-script@v6
|
|
with:
|
|
script: |
|
|
github.rest.issues.createComment({
|
|
issue_number: context.issue.number,
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
body: 'The deployment to Cloudflare Pages has failed. Please check the [build logs](https://github.com/GraphiteEditor/Graphite/actions/runs/' + context.runId + ') for details.'
|
|
});
|
|
|
|
- name: 💬 Comment build link
|
|
uses: actions/github-script@v6
|
|
with:
|
|
script: |
|
|
github.rest.issues.createComment({
|
|
issue_number: context.issue.number,
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
body: '| 📦 **Build Complete for** ${{ steps.commit_info.outputs.sha }} |\n|-|\n| ${{ steps.cloudflare.outputs.url }} |'
|
|
})
|