-
Notifications
You must be signed in to change notification settings - Fork 2
135 lines (114 loc) Β· 4.29 KB
/
Copy pathreset-database.yml
File metadata and controls
135 lines (114 loc) Β· 4.29 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
# yaml-language-server: $schema=https://www.schemastore.org/github-workflow.json
---
name: Reset Database
on:
workflow_dispatch: {}
concurrency:
group: reset-database
cancel-in-progress: false
permissions: {}
jobs:
reset-db:
name: ποΈ Reset DB
runs-on: ubuntu-24.04
timeout-minutes: 30
permissions:
contents: read
steps:
# Authentication: uses a deploy key (SSH) for direct push to main.
# The deploy key must be added as a bypass actor in the branch
# protection ruleset. See https://github.com/microsoft/sbi/issues/6
- name: β
Require default branch for manual runs
env:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
if [ "${GITHUB_REF}" != "refs/heads/${DEFAULT_BRANCH}" ]; then
echo "::error::Run workflow_dispatch from ${DEFAULT_BRANCH} only."
exit 1
fi
- name: β€΅οΈ Checkout (with LFS)
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ssh-key: ${{ secrets.NIGHTLY_WRITE_BOT_KEY }}
lfs: true
fetch-depth: 0
- name: π§ Setup Go
uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6.5.0
with:
go-version-file: go.mod
cache: true
- name: π§ Setup Task
uses: go-task/setup-task@01a4adf9db2d14c1de7a560f09170b6e0df736aa # v2.1.0
- name: π Download dependencies
run: go mod download
- name: ποΈ Build
run: task build
- name: ποΈ Clear database entries
run: |
./bin/linux-amd64/sbi reset-db \
--database azure_linux_images.db \
-v
- name: π Commit & push reset outputs
if: success()
run: |
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
# Source the shared allowlist from the trusted triggering commit
# so earlier tooling cannot taint the file list.
git restore --source='${{ github.sha }}' -- .github/reset-db-allowed-files.sh
source .github/reset-db-allowed-files.sh
is_allowed_file() {
local candidate="$1"
local allowed_file
for allowed_file in "${RESET_DB_ALLOWED_FILES[@]}"; do
if [ "$candidate" = "$allowed_file" ]; then
return 0
fi
done
return 1
}
# Validate expected artifacts exist
MISSING=()
for f in "${RESET_DB_ALLOWED_FILES[@]}"; do
[ -f "$f" ] || MISSING+=("$f")
done
if [ ${#MISSING[@]} -gt 0 ]; then
echo "::error::Missing expected reset artifacts:"
printf ' - %s\n' "${MISSING[@]}"
exit 1
fi
# Validate the full working tree so unexpected files cannot be
# hidden by selectively staging only the allowlisted outputs.
UNEXPECTED=()
while IFS= read -r -d '' file; do
if ! is_allowed_file "$file"; then
UNEXPECTED+=("$file")
fi
done < <(git diff --name-only -z)
while IFS= read -r -d '' file; do
if ! is_allowed_file "$file"; then
UNEXPECTED+=("$file")
fi
done < <(git ls-files --others --exclude-standard -z)
if [ ${#UNEXPECTED[@]} -gt 0 ]; then
echo "::error::Reset-db produced unexpected file changes:"
printf ' - %s\n' "${UNEXPECTED[@]}"
exit 1
fi
git add -f "${RESET_DB_ALLOWED_FILES[@]}"
if [ -z "$(git diff --cached --name-only)" ]; then
echo 'No changes to commit.'
exit 0
fi
# Final staged-file validation
while IFS= read -r -d '' file; do
if ! is_allowed_file "$file"; then
echo "::error::Unexpected file staged: $file"
exit 1
fi
done < <(git diff --cached --name-only -z)
CHANGED_FILES=$(git diff --cached --name-only | tr '\n' ' ')
echo "Changed files: $CHANGED_FILES"
git commit -m "chore: reset database entries [skip ci]"
git pull --rebase origin main
git push