Files
moeka-project/.github/workflows/update-nix-assets-hash.yaml
T
f459d00954 chore(ci): use personal access token for hash update (#1925)
## Description

Unfortunately the method of manually calling CI on the PR branch used by
#1907 doesn't count as status check of that PR (#1924), probably because
the called workflow inherits the context of the calling workflow, which
is not triggered by the PR. I read the docs and the most straightforward
solution is using a PAT, which does trigger the pull_request event.
Alternatively you can open PR with a custom github app, which is more
complicated but allows the app to bypass ruleset and commit directly to
main. Or just disable mandatory status checks.

## Linked Issues



## Additional Context

<!-- e.g. is there anything you'd like reviewers to focus on? -->

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Rin <shinohara-rin@users.noreply.github.com>
2026-06-04 18:12:51 +08:00

76 lines
2.4 KiB
YAML

name: Update Nix assets Hash
on:
workflow_dispatch:
push:
branches:
- main
paths:
- 'apps/stage-web/package.json'
- 'apps/stage-web/vite.config.ts'
permissions:
contents: write
pull-requests: write
jobs:
update:
if: github.event_name == 'workflow_dispatch' || !github.event.repository.fork
runs-on: ubuntu-latest
steps:
# Why?
#
# failed to
# $ nix build .#airi-pnpm-deps
# > airi-pnpm-deps> Running phase: fixupPhase
# > error: writing to file: No space left on device
- name: Free Disk Space
uses: jlumbroso/free-disk-space@main
- uses: actions/checkout@v6
with:
ref: main # Use main regardless of workflow_dispatch branch
# Authenticate git with PAT so that pushing to head retriggers CI
token: ${{ secrets.HASH_UPDATE_TOKEN }}
- uses: cachix/install-nix-action@v31
with:
extra_nix_config: experimental-features = nix-command flakes
- name: Update Hash
run: nix/update-assets-hash.sh
- name: Check for changes
id: changes
run: |
if git diff --quiet; then
echo "has_changes=false" >> "$GITHUB_OUTPUT"
else
echo "has_changes=true" >> "$GITHUB_OUTPUT"
fi
- name: Create PR
if: steps.changes.outputs.has_changes == 'true'
env:
# Create PR with PAT to trigger CI
GH_TOKEN: ${{ secrets.HASH_UPDATE_TOKEN }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add nix/assets-hash.txt
git commit -m 'chore(nix): update assets hash'
git push -f origin HEAD:chore/update-nix-assets-hash
# Create PR if it doesn't already exist
existing_pr=$(gh pr list --head chore/update-nix-assets-hash --json number -q '.[0].number' 2>/dev/null || true)
if [ -z "$existing_pr" ]; then
gh pr create \
--base main \
--head chore/update-nix-assets-hash \
--title 'chore(nix): update assets hash' \
--body 'Auto-generated by CI to keep Nix asset hash up-to-date.'
fi
# Enable auto-merge so PR merges once checks pass
gh pr merge --squash --auto --delete-branch chore/update-nix-assets-hash