forked from safe-global/safe-wallet-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 0
120 lines (113 loc) · 4.77 KB
/
Copy pathstore-codegen-drift.yml
File metadata and controls
120 lines (113 loc) · 4.77 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
name: Store Codegen Drift
on:
schedule:
- cron: '0 6 * * *'
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
check-drift:
permissions:
contents: read
issues: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v6.0.0
- uses: ./.github/actions/yarn
with:
after-install: 'false'
- run: yarn workspace @safe-global/store build:dev
- name: Check for drift
id: drift
run: git diff --exit-code -- packages/store/scripts/api-schema/schema.json packages/store/src/gateway/AUTO_GENERATED/
- name: Capture changed files
if: failure() && steps.drift.outcome == 'failure'
run: git diff --name-only -- packages/store/scripts/api-schema/schema.json packages/store/src/gateway/AUTO_GENERATED/ > "${RUNNER_TEMP}/drift-files.txt"
- name: Report drift
if: failure() && steps.drift.outcome == 'failure'
run: |
{
echo "## Store codegen drift detected"
echo
echo 'The generated Store API client is out of sync with the staging CGW schema.'
echo
echo '**Fix:**'
echo '```bash'
echo 'yarn workspace @safe-global/store build:dev'
echo '```'
echo
echo '**Changed files:**'
echo '```text'
cat "${RUNNER_TEMP}/drift-files.txt"
echo '```'
} >> "${GITHUB_STEP_SUMMARY}"
- name: Open or update drift issue
if: failure() && steps.drift.outcome == 'failure' && vars.ENABLE_DRIFT_ISSUES == 'true'
continue-on-error: true
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const fs = require('fs')
const path = require('path')
const marker = '<!-- store-codegen-drift -->'
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
const driftPath = path.join(process.env.RUNNER_TEMP, 'drift-files.txt')
const raw = fs.existsSync(driftPath) ? fs.readFileSync(driftPath, 'utf8') : ''
const files = raw.trim() || '(no files listed)'
const body = [
marker,
'The scheduled `Store Codegen Drift` workflow detected that `packages/store/src/gateway/AUTO_GENERATED/` is out of sync with the staging CGW schema.',
'',
`**Failing run:** ${runUrl}`,
'',
'**Fix:**',
'```bash',
'yarn workspace @safe-global/store build:dev',
'# commit the resulting changes',
'```',
'',
'**Changed files:**',
'```',
files,
'```',
'',
'This issue will auto-close the next time the workflow succeeds.',
].join('\n')
const q = `repo:${context.repo.owner}/${context.repo.repo} is:issue is:open in:body "${marker}" author:app/github-actions`
const { data } = await github.rest.search.issuesAndPullRequests({ q })
if (data.items.length > 0) {
await github.rest.issues.createComment({
...context.repo,
issue_number: data.items[0].number,
body: `New drift detected in run ${runUrl}.\n\nChanged files:\n\`\`\`\n${files}\n\`\`\``,
})
} else {
await github.rest.issues.create({
...context.repo,
title: 'CI: store codegen drift detected',
body,
})
}
- name: Close drift issue on success
if: success()
continue-on-error: true
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const marker = '<!-- store-codegen-drift -->'
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
const q = `repo:${context.repo.owner}/${context.repo.repo} is:issue is:open in:body "${marker}" author:app/github-actions`
const { data } = await github.rest.search.issuesAndPullRequests({ q })
for (const issue of data.items) {
await github.rest.issues.createComment({
...context.repo,
issue_number: issue.number,
body: `Drift resolved in run ${runUrl}. Auto-closing.`,
})
await github.rest.issues.update({
...context.repo,
issue_number: issue.number,
state: 'closed',
})
}