-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathcreate-release-proposal.sh
More file actions
executable file
Β·134 lines (118 loc) Β· 3.64 KB
/
create-release-proposal.sh
File metadata and controls
executable file
Β·134 lines (118 loc) Β· 3.64 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
#!/bin/sh
GITHUB_REPOSITORY=${GITHUB_REPOSITORY:-nodejs/node}
BOT_TOKEN=${BOT_TOKEN:-}
RELEASE_DATE=$1
RELEASE_LINE=$2
RELEASER=$3
if [ -z "$RELEASE_DATE" ] || [ -z "$RELEASE_LINE" ]; then
echo "Usage: $0 <RELEASE_DATE> <RELEASE_LINE>"
exit 1
fi
if [ -z "$GITHUB_REPOSITORY" ] || [ -z "$BOT_TOKEN" ]; then
echo "Invalid value in env for GITHUB_REPOSITORY and BOT_TOKEN"
exit 1
fi
HAS_MISSING_DEPS=
for dep in node gh git git-node awk; do
command -v "$dep" > /dev/null || {
echo "Required dependency $dep is missing" >&2
HAS_MISSING_DEPS=1
}
done
[ -z "$HAS_MISSING_DEPS" ] || exit 1
set -xe
git node release --prepare --skipBranchDiff --yes --releaseDate "$RELEASE_DATE"
HEAD_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
HEAD_SHA="$(git rev-parse HEAD^)"
TITLE="$(git log -1 --format=%s)"
TEMP_BODY="$(awk -v MAX_BODY_LENGTH="65536" \
"/^## ${RELEASE_DATE}/,/^<a id=/{ if (/^<a id=/) {exit;} if ((output_length += length(\$0)) > MAX_BODY_LENGTH) {exit 1;} print }" \
"doc/changelogs/CHANGELOG_V${RELEASE_LINE}.md" || echo "β¦")"
# Create the proposal branch
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${GITHUB_REPOSITORY}/git/refs" \
-f "ref=refs/heads/$HEAD_BRANCH" -f "sha=$HEAD_SHA"
# Create the proposal PR
PR_URL="$(gh api \
--method POST \
--jq .html_url \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${GITHUB_REPOSITORY}/pulls" \
-f "title=$TITLE" -f "body=$TEMP_BODY" -f "head=$HEAD_BRANCH" -f "base=v$RELEASE_LINE.x" -f draft=true)"
# Push the release commit to the proposal branch using `BOT_TOKEN` from the env
node --input-type=module - \
"$GITHUB_REPOSITORY" \
"$HEAD_BRANCH" \
"$HEAD_SHA" \
"$TITLE" \
"$(git log -1 HEAD --format=%b | awk -v PR_URL="$PR_URL" '{sub(/^PR-URL: TODO$/, "PR-URL: " PR_URL)} 1' || true)" \
"$(git show HEAD --diff-filter=d --name-only --format= || true)" \
"$(git show HEAD --diff-filter=D --name-only --format= || true)" \
<<'EOF'
const [,,
repo,
branch,
parentCommitSha,
commit_title,
commit_body,
modifiedOrAddedFiles,
deletedFiles,
] = process.argv;
import { readFileSync } from 'node:fs';
import util from 'node:util';
const query = `
mutation ($repo: String! $branch: String!, $parentCommitSha: GitObjectID!, $changes: FileChanges!, $commit_title: String!, $commit_body: String) {
createCommitOnBranch(input: {
branch: {
repositoryNameWithOwner: $repo,
branchName: $branch
},
message: {
headline: $commit_title,
body: $commit_body
},
expectedHeadOid: $parentCommitSha,
fileChanges: $changes
}) {
commit {
url
}
}
}
`;
const response = await fetch('https://api.github.com/graphql', {
method: 'POST',
headers: {
'Authorization': `bearer ${process.env.BOT_TOKEN}`,
},
body: JSON.stringify({
query,
variables: {
repo,
branch,
parentCommitSha,
commit_title,
commit_body,
changes: {
additions: modifiedOrAddedFiles.split('\n').filter(Boolean)
.map(path => ({ path, contents: readFileSync(path).toString('base64') })),
deletions: deletedFiles.split('\n').filter(Boolean),
}
},
})
});
if (!response.ok) {
console.log({statusCode: response.status, statusText: response.statusText});
process.exitCode ||= 1;
}
const data = await response.json();
if (data.errors?.length) {
throw new Error('Endpoint returned an error', { cause: data });
}
console.log(util.inspect(data, { depth: Infinity }));
EOF
gh pr edit "$PR_URL" --add-label release --add-label "v$RELEASE_LINE.x" --add-assignee "$RELEASER"