Files
moeka-project/.github/workflows/update-nix-assets-hash.yaml
T

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@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1
- 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