Skip to content

Update flake dependencies #169

Update flake dependencies

Update flake dependencies #169

# CI job to periodically (once a week) update flake.lock
name: Update flake dependencies
on:
schedule:
- cron: "0 16 * * 5"
workflow_dispatch: # for allowing manual triggers of the workflow
jobs:
update-dependencies:
runs-on: ubuntu-latest
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
with:
egress-policy: audit
- name: Generate GitHub App installation token
id: app-token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
with:
client-id: ${{ secrets.FLAKE_BOT_APP_ID }}
private-key: ${{ secrets.FLAKE_BOT_APP_PRIVATE_KEY }}
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
token: ${{ steps.app-token.outputs.token }}
- uses: DeterminateSystems/nix-installer-action@3138316df39ed29be04236d7ffc686fa525866aa # v23
- uses: DeterminateSystems/magic-nix-cache-action@84c0677f58dcedf3b91f8223ce36a9ea5b3c84b7 # v15
with:
use-flakehub: false
- name: Update flake.lock and create signed commit with flake.lock changes
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
FILE_TO_COMMIT: flake.lock
COMMIT_BRANCH: automation/update-flake-dependencies
COMMIT_MESSAGE: "chore(nix): Update Flake dependencies"
run: |
# fetch remote state
git fetch
# if branch exists on remote already
if git checkout "$COMMIT_BRANCH" > /dev/null 2>&1; then
# pull changes
git pull
else
# otherwise, create the branch and push it to remote
git checkout -b "$COMMIT_BRANCH"
git push -u origin "$COMMIT_BRANCH"
fi
# update flake.lock
nix flake update
# make sure something actually changed first, if not, no updates required
if [[ `git status --porcelain` ]]; then
# commit via the GitHub API so we get automatic commit signing
gh api --method PUT /repos/1Password/shell-plugins/contents/$FILE_TO_COMMIT \
--field message="$COMMIT_MESSAGE" \
--field content="$(base64 -w 0 $FILE_TO_COMMIT)" \
--field branch="$COMMIT_BRANCH" \
--field sha="$(git rev-parse $COMMIT_BRANCH:$FILE_TO_COMMIT)"
OPEN_PR_COUNT=$(gh pr list --head "$COMMIT_BRANCH" --state open --json number --jq 'length')
if [ "$OPEN_PR_COUNT" -eq 0 ]; then
gh pr create --title "[automation]: Update Flake dependencies" \
--body "This is an automated PR to update \`flake.lock\`" \
--label "flake.lock automation" \
--base main --head $COMMIT_BRANCH
fi
fi