@@ -10,24 +10,76 @@ if [ -z "$RELEASE_DATE" ] || [ -z "$RELEASE_LINE" ]; then
10
10
exit 1
11
11
fi
12
12
13
+ buildMutationQuery () {
14
+ cat - << 'EOF '
15
+ mutation ($repo: String! $branch: String!, $parent: GitObjectID!, $commit_title: String!, $commit_body: String) {
16
+ createCommitOnBranch(input: {
17
+ branch: {
18
+ repositoryNameWithOwner: $repo,
19
+ branchName: $branch
20
+ },
21
+ message: {
22
+ headline: $commit_title,
23
+ body: $commit_body
24
+ },
25
+ expectedHeadOid: $parent,
26
+ fileChanges: {
27
+ additions: [
28
+ EOF
29
+ git show HEAD --diff-filter=d --name-only --format= | while read -r FILE; do
30
+ echo " { path: $(
31
+ node -p ' JSON.stringify(process.argv[1])' " $FILE "
32
+ ) , contents: $(
33
+ node -p ' JSON.stringify(fs.readFileSync(process.argv[1]).toString("base64"))' " $FILE "
34
+ ) },"
35
+ done
36
+ echo ' ], deletions: ['
37
+ git show HEAD --diff-filter=D --name-only --format= | while read -r FILE; do
38
+ echo " $( node -p ' JSON.stringify(process.argv[1])' " $FILE " ) ,"
39
+ done
40
+ cat - << 'EOF '
41
+ ]
42
+ }}) {
43
+ commit {
44
+ url
45
+ }
46
+ }
47
+ }
48
+ EOF
49
+ }
50
+
51
+
13
52
git node release --prepare --skipBranchDiff --yes --releaseDate " $RELEASE_DATE "
14
- # We use it to not specify the branch name as it changes based on
15
- # the commit list (semver-minor/semver-patch)
16
- git config push.default current
17
- git push
53
+
54
+ HEAD=" $( git rev-parse --abbrev-ref HEAD) "
18
55
19
56
TITLE=$( awk " /^## ${RELEASE_DATE} / { print substr(\$ 0, 4) }" " doc/changelogs/CHANGELOG_V${RELEASE_LINE} .md" )
20
57
21
58
# Use a temporary file for the PR body
22
59
TEMP_BODY=" $( awk " /## ${RELEASE_DATE} /,/^<a id=/{ if (!/^<a id=/) print }" " doc/changelogs/CHANGELOG_V${RELEASE_LINE} .md" ) "
23
60
24
- PR_URL=" $( gh pr create --title " $TITLE " --body " $TEMP_BODY " --base " v$RELEASE_LINE .x" ) "
25
-
26
- # Amend commit message so it contains the correct PR-URL trailer.
27
- AMENDED_COMMIT_MSG=" $( git log -1 --pretty=%B | sed " s|PR-URL: TODO|PR-URL: $PR_URL |" ) "
61
+ # Create the proposal branch
62
+ gh api \
63
+ --method POST \
64
+ -H " Accept: application/vnd.github+json" \
65
+ -H " X-GitHub-Api-Version: 2022-11-28" \
66
+ " /repos/${GITHUB_REPOSITORY} /git/refs" \
67
+ -f " ref=refs/heads/$HEAD " -f " sha=$( git rev-parse HEAD^) "
28
68
29
- # Replace "TODO" with the PR URL in the last commit
30
- git commit --amend --no-edit -m " $AMENDED_COMMIT_MSG " || true
69
+ # Create the proposal PR
70
+ PR_URL=" $( gh api \
71
+ --method POST \
72
+ --jq .html_url
73
+ -H " Accept: application/vnd.github+json" \
74
+ -H " X-GitHub-Api-Version: 2022-11-28" \
75
+ " /repos/${GITHUB_REPOSITORY} /pulls" \
76
+ -f " title=$TITLE " -f " body=$TEMP_BODY " -f " head=$HEAD " -f " base=v$RELEASE_LINE .x" ) "
31
77
32
- # Force-push the amended commit
33
- git push --force
78
+ # Push the release commit to the proposal branch
79
+ gh api graphql \
80
+ -F repo=" $GITHUB_REPOSITORY " \
81
+ -F branch=" $HEAD " \
82
+ -F parent=" $( git rev-parse HEAD^) " \
83
+ -F commit_title=" $( git log -1 HEAD --format=%s) " \
84
+ -F commit_body=" $( git log -1 HEAD --format=%b | sed " s|PR-URL: TODO|PR-URL: $PR_URL |" ) " \
85
+ -f query=" $( buildMutationQuery) "
0 commit comments