-
Notifications
You must be signed in to change notification settings - Fork 0
102 lines (85 loc) · 2.8 KB
/
update-flake-lock.yaml
File metadata and controls
102 lines (85 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: update-flake-lock
on:
workflow_dispatch: # allows manual triggering
# schedule:
# - cron: "0 0 * * 0" # runs weekly on Sunday at 00:00
jobs:
lockfile:
env:
BRANCH: chore/update-flake-lock
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
submodules: recursive
- uses: cachix/install-nix-action@v31
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- uses: cachix/cachix-action@v17
with:
name: kidibox
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
- name: Create or update branch
run: |
git checkout -b $BRANCH
git push -u origin $BRANCH --force
- name: Update flake.lock
id: update-flake
run: |
echo "result<<EOF" >> $GITHUB_OUTPUT
nix flake update 2>&1 | tee -a $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Check for changes
id: check-changes
run: |
CHANGED=$(git status --porcelain)
if [ -z "$CHANGED" ]; then
echo "No changes detected."
echo "changes=false" >> $GITHUB_ENV
else
echo "Changes detected."
echo "changes=true" >> $GITHUB_ENV
fi
- name: Commit changes
if: env.changes == 'true'
run: |
#!/usr/bin/env bash
set -euo pipefail
mapfile -t CHANGED < <(git diff --name-only | xargs)
declare -a FILES
for value in "${CHANGED[@]}"; do
FILES+=(-F "files[][path]=$value" -F "files[][contents]=$(base64 -w0 "$value")")
done
gh api graphql \
-F githubRepository="$GITHUB_REPOSITORY" \
-F branchName="$BRANCH" \
-F expectedHeadOid="$(git rev-parse HEAD)" \
-F commitMessage="chore: update flake.lock" \
-F "query=@.github/api/createCommitOnBranch.gql" \
"${FILES[@]}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create pull request if not exists
if: env.changes == 'true'
run: |
#!/usr/bin/env bash
set -euo pipefail
PR_ID=$(gh pr list --head "$BRANCH" --json number -q '.[0].number')
if [ -z "$PR_ID" ]; then
git reset --hard "$GITHUB_REF"
git pull
gh pr create \
--title "chore: update flake.lock" \
--body "${PR_BODY}" \
--base "${GITHUB_REF}" \
--head "${BRANCH}"
else
gh pr update "$PR_ID" --body "${PR_BODY}"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_BODY: |
```
${{ steps.update-flake.outputs.result }}
```