-
Notifications
You must be signed in to change notification settings - Fork 22
71 lines (70 loc) · 2.22 KB
/
flake_vendorhash.yaml
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
name: "Flake.nix vendorHash updater"
on:
push:
branches:
- main
paths:
- go.mod
- go.sum
pull_request:
paths:
- go.mod
- go.sum
jobs:
updateVendorHash:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v2
with: # OCMBot
app_id: ${{ secrets.OCMBOT_APP_ID }}
private_key: ${{ secrets.OCMBOT_PRIV_KEY }}
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ steps.generate_token.outputs.token }}
- name: Enable gh-CLI
uses: actions4gh/[email protected]
id: setup-gh
with:
token: ${{ steps.generate_token.outputs.token }}
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v12
- name: Update ocm vendor hash
run: nix run .#nixpkgs.nix-update -- --flake --version=skip ocm
- name: Check diff and create action summary
id: diff
run: |
diff=$(git diff)
if [[ -z "$diff" ]]; then
echo "Everything is tidy."
exit 0
else
echo "exists=true" >> "$GITHUB_OUTPUT"
fi
cat << EOF >> "${GITHUB_STEP_SUMMARY}"
Updates the vendorHash in \`flake.nix\`
\`\`\`bash
nix run .#nixpkgs.nix-update -- --flake --version=skip ocm
\`\`\`
produced:
\`\`\`diff
${diff}
\`\`\`
EOF
- name: Create Commit
if: ${{ steps.diff.outputs.exists }}
# https://docs.github.com/de/rest/repos/contents?apiVersion=2022-11-28#create-or-update-file-contents
run: |
FILE=flake.nix
BRANCH=${{ github.head_ref }}
echo "{\"message\":\"auto update vendor hash\",\"content\":\"$(base64 -w0 ${FILE})\",\"sha\":\"$(git rev-parse :${FILE})\"" > input.json
if [[ -n "$BRANCH" ]]; then
echo ",\"branch\":\"${{ github.head_ref }}\"" >> input.json
fi
echo "}" >> input.json
gh api -X PUT https://api.github.com/repos/${{ github.repository }}/contents/${FILE} --input input.json