-
-
Notifications
You must be signed in to change notification settings - Fork 302
160 lines (146 loc) · 5.21 KB
/
update.yml
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: Update
on:
# Runs everyday at noon
schedule:
- cron: "0 12 * * *"
# Allow manual triggering
workflow_dispatch:
inputs:
lock:
type: boolean
default: true
description: Update flake.lock
generate:
type: boolean
default: true
description: Update generated files
# Allow one concurrent update per branch
concurrency:
group: "update-${{ github.ref_name }}"
cancel-in-progress: true
# Allow pushing and creating PRs
permissions:
contents: write
pull-requests: write
jobs:
update:
name: Update the flake inputs and generate options
runs-on: ubuntu-latest
timeout-minutes: 40
if: github.event_name != 'schedule' || github.repository == 'nix-community/nixvim'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ssh-key: ${{ secrets.CI_UPDATE_SSH_KEY }}
- name: Install Nix
uses: cachix/install-nix-action@v30
with:
nix_path: nixpkgs=channel:nixos-unstable
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure git
run: |
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
- name: Update flake.lock
id: flake_lock
if: inputs.lock || github.event_name == 'schedule'
run: |
old=$(git show --no-patch --format=%h)
nix flake update --commit-lock-file
new=$(git show --no-patch --format=%h)
if [ "$old" != "$new" ]; then
echo "body<<EOF" >> "$GITHUB_OUTPUT"
git show --no-patch --format=%b >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
fi
- name: Check if nixpkgs input was changed
if: github.event_name == 'schedule'
env:
repo: ${{ github.repository }}
branch: update/${{ github.ref_name }}
run: |
getAttr() {
nix eval --raw --impure \
--expr '{ ref }: builtins.getFlake ref' \
--argstr ref "$1" "$2"
}
getNixpkgsRev() {
getAttr "$1" 'inputs.nixpkgs.rev'
}
old=$(
getNixpkgsRev "github:$repo/$branch" \
|| echo "" # Could fail, e.g. if the branch is deleted
)
new=$(getNixpkgsRev "$PWD")
if [[ "$old" = "$new" ]]; then
(
echo "nixpkgs rev has not changed ($new). Stopping..."
echo 'You can re-run the workflow manually to update anyway.'
) >&2
(
echo '## Update cancelled'
echo
echo 'The `nixpkgs` rev has not changed (`'"$new"'`).'
echo
echo 'You can re-run the workflow manually to update anyway.'
echo
) >> $GITHUB_STEP_SUMMARY
exit 1
fi
- name: Update generated files
id: generate
if: inputs.generate || github.event_name == 'schedule'
run: |
old=$(git show --no-patch --format=%h)
nix-build ./update-scripts -A generate
./result/bin/generate --commit
new=$(git show --no-patch --format=%h)
if [ "$old" != "$new" ]; then
body=$(git show --no-patch --format=%b)
echo "body<<EOF" >> "$GITHUB_OUTPUT"
if [ -n "$body" ]; then
# Multi-file changes are listed in the body
echo "$body" >> "$GITHUB_OUTPUT"
else
# Single-file changes are only in the summary,
# e.g. "generated: Updated none-ls.nix"
git show --no-patch --format=%s | \
sed -e 's/^generated:/-/' >> "$GITHUB_OUTPUT"
fi
echo "EOF" >> "$GITHUB_OUTPUT"
fi
- name: Create Pull Request
id: pr
uses: peter-evans/create-pull-request@v6
with:
add-paths: "!**"
branch: update/${{ github.ref_name }}
delete-branch: true
title: |
[${{ github.ref_name }}] Update flake.lock & generated files
body: |
## Flake lockfile
```
${{ steps.flake_lock.outputs.body || 'No changes' }}
```
## Generate
${{ steps.generate.outputs.body || 'No changes' }}
- name: Print summary
if: ${{ steps.pr.outputs.pull-request-number }}
run: |
num="${{ steps.pr.outputs.pull-request-number }}"
pr_url="${{ steps.pr.outputs.pull-request-url }}"
pr_branch="${{ steps.pr.outputs.pull-request-branch }}"
head="${{ steps.pr.outputs.pull-request-head-sha }}"
operation="${{ steps.pr.outputs.pull-request-operation }}"
# stdout
echo "${head:0:6} pushed to ${pr_branch}"
echo "${pr} was ${operation}."
# markdown summary
echo "## ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
echo >> $GITHUB_STEP_SUMMARY
echo "\`${head:0:6}\` pushed to \`${pr_branch}\`" >> $GITHUB_STEP_SUMMARY
echo >> $GITHUB_STEP_SUMMARY
echo "[#${num}](${pr_url}) was ${operation}." >> $GITHUB_STEP_SUMMARY
echo >> $GITHUB_STEP_SUMMARY