-
Notifications
You must be signed in to change notification settings - Fork 62
151 lines (126 loc) · 5.13 KB
/
Copy pathupdate-flake.yaml
File metadata and controls
151 lines (126 loc) · 5.13 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
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
name: Update Flake and Validate Build
on:
schedule:
- cron: "30 00 * * 1"
workflow_dispatch: # Allow manual triggering
# Set default permissions as read only
permissions: read-all
jobs:
update-flake:
runs-on: ubuntu-latest
permissions:
# Only need contents write to update the flake lock file
contents: write
outputs:
update_available: ${{ steps.check_updates.outputs.update_available }}
steps:
- name: Repository Checkout
uses: actions/checkout@v5
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v20
- name: Check for Updates
id: check_updates
run: |
# Create a temporary copy of flake.lock
cp flake.lock flake.lock.backup
# Try to update flake.lock
nix flake update
# Check if there are differences
if ! cmp -s flake.lock flake.lock.backup; then
echo "update_available=true" >> "$GITHUB_OUTPUT"
# Restore original flake.lock
mv flake.lock.backup flake.lock
else
echo "update_available=false" >> "$GITHUB_OUTPUT"
fi
- name: Update flake.lock
if: steps.check_updates.outputs.update_available == 'true'
uses: DeterminateSystems/update-flake-lock@v27
with:
nix-options: --debug --log-format raw
token: ${{ secrets.FLAKE_TOKEN }}
pr-title: "deps: update flake.lock"
pr-labels: |
dependencies
automated
build-and-check:
needs: update-flake
permissions:
# Needed for checking out code
contents: read
# Needed for creating issues
issues: write
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
fail-fast: false # Continue with other jobs even if one fails
runs-on: ${{ matrix.os }}
steps:
- name: Repository Checkout
uses: actions/checkout@v5
with:
ref: update_flake_lock_action
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v20
- name: Build and Test Configuration
id: build
continue-on-error: true # Continue to next steps even if build fails
run: |
set +e # Don't exit immediately on error
# Run the build and capture output
OUTPUT=$(nix build .# 2>&1)
BUILD_EXIT_CODE=$?
echo "build_output<<EOF" >> $GITHUB_ENV
echo "$OUTPUT" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
# Check if build succeeded
if [ $BUILD_EXIT_CODE -eq 0 ]; then
echo "build_status=success" >> $GITHUB_ENV
else
echo "build_status=failure" >> $GITHUB_ENV
# Ensure the error is visible in the logs
echo "::error::Build failed with exit code $BUILD_EXIT_CODE"
echo "$OUTPUT"
fi
- name: Create Issue on Build Failure
if: env.build_status == 'failure'
uses: actions/github-script@v8
with:
script: |
const os = '${{ matrix.os }}';
const buildOutput = process.env.build_output;
const isUpdate = '${{ needs.update-flake.outputs.update_available }}' === 'true';
// Extract warnings and errors from build output
const warnings = buildOutput.match(/evaluation warning:[^\n]+/g) || [];
const errors = buildOutput.match(/error:[^\n]+/g) || [];
// Create a summary section
const summary = [
warnings.length > 0 ? `${warnings.length} evaluation warnings` : '',
errors.length > 0 ? `${errors.length} errors` : ''
].filter(Boolean).join(' and ');
// Get repository information from context
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
await github.rest.issues.create({
owner,
repo,
title: `🔨 Build Failed on ${os}: ${summary}${isUpdate ? ' (Dependency Update)' : ''}`,
body: `Build failed during automated validation on ${os}${isUpdate ? ' while testing dependency updates.' : '.'}\n
${isUpdate ? 'This failure occurred on the dependency update branch `deps/update-flake-lock`.' : 'This failure occurred on the main branch.'}\n
### Summary
${summary}\n
${warnings.length > 0 ? `### Warnings\n\`\`\`\n${warnings.join('\n')}\n\`\`\`\n` : ''}
${errors.length > 0 ? `### Errors\n\`\`\`\n${errors.join('\n')}\n\`\`\`\n` : ''}
<details>
<summary>Build Output</summary>
\`\`\`
${buildOutput}
\`\`\`
</details>
Please review the build output and fix any issues.`,
labels: [
'build-failure',
'bug',
...(warnings.length > 0 ? ['has-warnings'] : []),
...(errors.length > 0 ? ['has-errors'] : [])
]
});