forked from openai/codex-security
-
Notifications
You must be signed in to change notification settings - Fork 0
195 lines (174 loc) · 6.62 KB
/
Copy pathnode-release-cut.yml
File metadata and controls
195 lines (174 loc) · 6.62 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
name: node-release-cut
on:
push:
branches: [main]
paths:
- sdk/typescript/package.json
workflow_dispatch:
permissions:
contents: read
concurrency:
group: node-release-cut
queue: max
jobs:
cut:
if: github.repository == 'openai/codex-security'
name: cut release tag
runs-on: ubuntu-latest
permissions:
actions: write
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Set up Node.js
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: "24.15.0"
package-manager-cache: false
- name: Resolve the stable package version
id: release
shell: bash
env:
BEFORE_SHA: ${{ github.event.before }}
run: |
set -euo pipefail
if [[ "$GITHUB_REF" != "refs/heads/main" ]]; then
echo "Release tags can only be cut from main." >&2
exit 1
fi
git fetch origin main
if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then
echo "Release tags can only be cut from commits on main." >&2
exit 1
fi
version="$(node sdk/typescript/scripts/release-automation.mjs version sdk/typescript/package.json)"
if [[ "$GITHUB_EVENT_NAME" == "push" && "$BEFORE_SHA" =~ ^[0-9a-f]{40}$ ]]; then
if previous_manifest="$(git show "$BEFORE_SHA:sdk/typescript/package.json" 2>/dev/null)"; then
previous_version="$(
printf '%s\n' "$previous_manifest" |
node --input-type=module --eval '
import { readFileSync } from "node:fs";
const manifest = JSON.parse(readFileSync(0, "utf8"));
if (typeof manifest.version !== "string") {
throw new Error("The previous package version is missing.");
}
process.stdout.write(manifest.version);
'
)"
if [[ "$version" == "$previous_version" ]]; then
echo "Package version is unchanged; no release is needed."
echo "changed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
node sdk/typescript/scripts/release-automation.mjs \
require-increase "$version" "$previous_version" >/dev/null
fi
fi
if ! published_versions="$(
npm view @openai/codex-security versions \
--json \
--registry=https://registry.npmjs.org/
)"; then
published_versions="$(
printf '%s\n' "$published_versions" |
node sdk/typescript/scripts/release-automation.mjs \
initial-published-versions "$version"
)"
fi
printf '%s\n' "$published_versions" |
node sdk/typescript/scripts/release-automation.mjs \
require-published-increase "$version" >/dev/null
{
printf 'changed=true\n'
printf 'version=%s\n' "$version"
printf 'tag=npm-v%s\n' "$version"
} >> "$GITHUB_OUTPUT"
- name: Create the exact merged release tag
if: steps.release.outputs.changed == 'true'
shell: bash
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ steps.release.outputs.tag }}
run: |
set -euo pipefail
query_status=0
tag_response="$(
gh api --include \
"repos/$GITHUB_REPOSITORY/git/ref/tags/$RELEASE_TAG" 2>/dev/null
)" || query_status=$?
IFS=' ' read -r _ response_status _ <<< "$tag_response" || true
response_body="$(
awk 'body { print } /^\r?$/ { body = 1 }' <<< "$tag_response"
)"
if [[ "$query_status" == 0 && "$response_status" =~ ^2[0-9]{2}$ ]]; then
if ! existing_ref="$(
jq -er '[.object.type, .object.sha] | @tsv' <<< "$response_body"
)"; then
echo "Unable to query release tag $RELEASE_TAG." >&2
exit 1
fi
elif [[ "$query_status" != 0 && "$response_status" == 404 &&
"$(
jq -r '.status // empty' <<< "$response_body" \
2>/dev/null || true
)" == 404 ]]; then
existing_ref=""
else
echo "Unable to query release tag $RELEASE_TAG." >&2
exit 1
fi
if [[ -n "$existing_ref" ]]; then
IFS=$'\t' read -r tag_type tag_object <<< "$existing_ref"
if [[ ! "$tag_object" =~ ^[0-9a-f]{40}$ ]]; then
echo "Release tag $RELEASE_TAG does not identify a valid commit." >&2
exit 1
fi
case "$tag_type" in
commit)
existing_sha="$tag_object"
;;
tag)
if ! existing_sha="$(
gh api \
"repos/$GITHUB_REPOSITORY/git/tags/$tag_object" \
--jq 'if .object.type == "commit" then .object.sha else empty end'
)"; then
echo "Release tag $RELEASE_TAG does not identify a valid commit." >&2
exit 1
fi
;;
*)
echo "Release tag $RELEASE_TAG does not identify a valid commit." >&2
exit 1
;;
esac
if [[ ! "$existing_sha" =~ ^[0-9a-f]{40}$ ]]; then
echo "Release tag $RELEASE_TAG does not identify a valid commit." >&2
exit 1
fi
if [[ "$existing_sha" != "$GITHUB_SHA" ]]; then
echo "Release tag $RELEASE_TAG already points to a different commit." >&2
exit 1
fi
echo "Release tag $RELEASE_TAG already points to $GITHUB_SHA."
exit 0
fi
gh api --method POST "repos/$GITHUB_REPOSITORY/git/refs" \
-f "ref=refs/tags/$RELEASE_TAG" \
-f "sha=$GITHUB_SHA" \
--silent
- name: Dispatch the protected npm release
if: steps.release.outputs.changed == 'true'
shell: bash
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ steps.release.outputs.tag }}
run: |
set -euo pipefail
gh workflow run node-release.yml \
--repo "$GITHUB_REPOSITORY" \
--ref "$RELEASE_TAG"