| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,6 @@ | |||
| 1 | 1 | # This action requires the following secrets to be set on the repository: | |
| 2 | 2 | # GH_USER_NAME: GitHub user whose Jenkins and GitHub token are defined below | |
| 3 | 3 | # GH_USER_TOKEN: GitHub user token, to be used by ncu and to push changes | |
| 4 | - # JENKINS_TOKEN: Jenkins token, to be used to check CI status | ||
| 5 | 4 | ||
| 6 | 5 | name: Create Release Proposal | |
| 7 | 6 | ||
@@ -24,6 +23,7 @@ env: | |||
| 24 | 23 | ||
| 25 | 24 | permissions: | |
| 26 | 25 | contents: write | |
| 26 | + pull-requests: write | ||
| 27 | 27 | ||
| 28 | 28 | jobs: | |
| 29 | 29 | releasePrepare: | |
@@ -37,9 +37,7 @@ jobs: | |||
| 37 | 37 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| 38 | 38 | with: | |
| 39 | 39 | ref: ${{ env.STAGING_BRANCH }} | |
| 40 | - # Needs the whole git history for ncu to work | ||
| 41 | - # See https://github.com/nodejs/node-core-utils/pull/486 | ||
| 42 | - fetch-depth: 0 | ||
| 40 | + persist-credentials: false | ||
| 43 | 41 | ||
| 44 | 42 | # Install dependencies | |
| 45 | 43 | - name: Install Node.js | |
@@ -56,29 +54,32 @@ jobs: | |||
| 56 | 54 | ncu-config set upstream origin | |
| 57 | 55 | ncu-config set username "$USERNAME" | |
| 58 | 56 | ncu-config set token "$GH_TOKEN" | |
| 59 | - ncu-config set jenkins_token "$JENKINS_TOKEN" | ||
| 60 | 57 | ncu-config set repo "$(echo "$GITHUB_REPOSITORY" | cut -d/ -f2)" | |
| 61 | 58 | ncu-config set owner "${GITHUB_REPOSITORY_OWNER}" | |
| 62 | 59 | env: | |
| 63 | 60 | USERNAME: ${{ secrets.JENKINS_USER }} | |
| 64 | - GH_TOKEN: ${{ secrets.GH_USER_TOKEN }} | ||
| 65 | - JENKINS_TOKEN: ${{ secrets.JENKINS_TOKEN }} | ||
| 61 | + GH_TOKEN: ${{ github.token }} | ||
| 66 | 62 | ||
| 67 | 63 | - name: Set up ghauth config (Ubuntu) | |
| 68 | 64 | run: | | |
| 69 | - mkdir -p ~/.config/changelog-maker/ | ||
| 70 | - echo '{ | ||
| 71 | - "user": "'$(ncu-config get username)'", | ||
| 72 | - "token": "'$(ncu-config get token)'" | ||
| 73 | - }' > ~/.config/changelog-maker/config.json | ||
| 65 | + mkdir -p "${XDG_CONFIG_HOME:-~/.config}/changelog-maker" | ||
| 66 | + echo '{}' | jq '{user: env.USERNAME, token: env.TOKEN}' > "${XDG_CONFIG_HOME:-~/.config}/changelog-maker/config.json" | ||
| 67 | + env: | ||
| 68 | + USERNAME: ${{ secrets.JENKINS_USER }} | ||
| 69 | + TOKEN: ${{ github.token }} | ||
| 74 | 70 | ||
| 75 | 71 | - name: Setup git author | |
| 76 | 72 | run: | | |
| 77 | 73 | git config --local user.email "github-bot@iojs.org" | |
| 78 | 74 | git config --local user.name "Node.js GitHub Bot" | |
| 79 | 75 | ||
| 80 | 76 | - name: Start git node release prepare | |
| 77 | + # The curl command is to make sure we run the version of the script corresponding to the current workflow. | ||
| 81 | 78 | run: | | |
| 79 | + git update-index --assume-unchanged tools/actions/create-release.sh | ||
| 80 | + curl -fsSLo tools/actions/create-release.sh https://github.com/${GITHUB_REPOSITORY}/raw/${GITHUB_SHA}/tools/actions/create-release.sh | ||
| 82 | 81 | ./tools/actions/create-release.sh "${RELEASE_DATE}" "${RELEASE_LINE}" | |
| 83 | 82 | env: | |
| 84 | - GH_TOKEN: ${{ secrets.GH_USER_TOKEN }} | ||
| 83 | + GH_TOKEN: ${{ github.token }} | ||
| 84 | + # We want the bot to push the push the release commit so CI runs on it. | ||
| 85 | + BOT_TOKEN: ${{ secrets.GH_USER_TOKEN }} | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,9 @@ | |||
| 2 | 2 | ||
| 3 | 3 | set -xe | |
| 4 | 4 | ||
| 5 | + GITHUB_REPOSITORY=${GITHUB_REPOSITORY:-nodejs/node} | ||
| 6 | + BOT_TOKEN=${BOT_TOKEN:-} | ||
| 7 | + | ||
| 5 | 8 | RELEASE_DATE=$1 | |
| 6 | 9 | RELEASE_LINE=$2 | |
| 7 | 10 | ||
@@ -10,24 +13,114 @@ if [ -z "$RELEASE_DATE" ] || [ -z "$RELEASE_LINE" ]; then | |||
| 10 | 13 | exit 1 | |
| 11 | 14 | fi | |
| 12 | 15 | ||
| 16 | + if [ -z "$GITHUB_REPOSITORY" ] || [ -z "$BOT_TOKEN" ]; then | ||
| 17 | + echo "Invalid value in env for GITHUB_REPOSITORY and BOT_TOKEN" | ||
| 18 | + exit 1 | ||
| 19 | + fi | ||
| 20 | + | ||
| 21 | + if ! command -v node || ! command -v gh || ! command -v git || ! command -v awk; then | ||
| 22 | + echo "Missing required dependencies" | ||
| 23 | + exit 1 | ||
| 24 | + fi | ||
| 25 | + | ||
| 13 | 26 | 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 | ||
| 27 | + | ||
| 28 | + HEAD_BRANCH="$(git rev-parse --abbrev-ref HEAD)" | ||
| 29 | + HEAD_SHA="$(git rev-parse HEAD^)" | ||
| 18 | 30 | ||
| 19 | 31 | TITLE=$(awk "/^## ${RELEASE_DATE}/ { print substr(\$0, 4) }" "doc/changelogs/CHANGELOG_V${RELEASE_LINE}.md") | |
| 20 | 32 | ||
| 21 | 33 | # Use a temporary file for the PR body | |
| 22 | 34 | TEMP_BODY="$(awk "/## ${RELEASE_DATE}/,/^<a id=/{ if (!/^<a id=/) print }" "doc/changelogs/CHANGELOG_V${RELEASE_LINE}.md")" | |
| 23 | 35 | ||
| 24 | - PR_URL="$(gh pr create --title "$TITLE" --body "$TEMP_BODY" --base "v$RELEASE_LINE.x")" | ||
| 36 | + # Create the proposal branch | ||
| 37 | + gh api \ | ||
| 38 | + --method POST \ | ||
| 39 | + -H "Accept: application/vnd.github+json" \ | ||
| 40 | + -H "X-GitHub-Api-Version: 2022-11-28" \ | ||
| 41 | + "/repos/${GITHUB_REPOSITORY}/git/refs" \ | ||
| 42 | + -f "ref=refs/heads/$HEAD_BRANCH" -f "sha=$HEAD_SHA" | ||
| 43 | + | ||
| 44 | + # Create the proposal PR | ||
| 45 | + PR_URL="$(gh api \ | ||
| 46 | + --method POST \ | ||
| 47 | + --jq .html_url \ | ||
| 48 | + -H "Accept: application/vnd.github+json" \ | ||
| 49 | + -H "X-GitHub-Api-Version: 2022-11-28" \ | ||
| 50 | + "/repos/${GITHUB_REPOSITORY}/pulls" \ | ||
| 51 | + -f "title=$TITLE" -f "body=$TEMP_BODY" -f "head=$HEAD_BRANCH" -f "base=v$RELEASE_LINE.x")" | ||
| 25 | 52 | ||
| 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|")" | ||
| 53 | + # Push the release commit to the proposal branch using `BOT_TOKEN` from the env | ||
| 54 | + node --input-type=module - \ | ||
| 55 | + "$GITHUB_REPOSITORY" \ | ||
| 56 | + "$HEAD_BRANCH" \ | ||
| 57 | + "$HEAD_SHA" \ | ||
| 58 | + "$(git log -1 HEAD --format=%s || true)" \ | ||
| 59 | + "$(git log -1 HEAD --format=%b | awk -v PR_URL="$PR_URL" '{sub(/^PR-URL: TODO$/, "PR-URL: " PR_URL)} 1' || true)" \ | ||
| 60 | + "$(git show HEAD --diff-filter=d --name-only --format= || true)" \ | ||
| 61 | + "$(git show HEAD --diff-filter=D --name-only --format= || true)" \ | ||
| 62 | + <<'EOF' | ||
| 63 | + const [,, | ||
| 64 | + repo, | ||
| 65 | + branch, | ||
| 66 | + parentCommitSha, | ||
| 67 | + commit_title, | ||
| 68 | + commit_body, | ||
| 69 | + modifiedOrAddedFiles, | ||
| 70 | + deletedFiles, | ||
| 71 | + ] = process.argv; | ||
| 28 | 72 | ||
| 29 | - # Replace "TODO" with the PR URL in the last commit | ||
| 30 | - git commit --amend --no-edit -m "$AMENDED_COMMIT_MSG" || true | ||
| 73 | + import { readFileSync } from 'node:fs'; | ||
| 74 | + import util from 'node:util'; | ||
| 31 | 75 | ||
| 32 | - # Force-push the amended commit | ||
| 33 | - git push --force | ||
| 76 | + const query = ` | ||
| 77 | + mutation ($repo: String! $branch: String!, $parentCommitSha: GitObjectID!, $changes: FileChanges!, $commit_title: String!, $commit_body: String) { | ||
| 78 | + createCommitOnBranch(input: { | ||
| 79 | + branch: { | ||
| 80 | + repositoryNameWithOwner: $repo, | ||
| 81 | + branchName: $branch | ||
| 82 | + }, | ||
| 83 | + message: { | ||
| 84 | + headline: $commit_title, | ||
| 85 | + body: $commit_body | ||
| 86 | + }, | ||
| 87 | + expectedHeadOid: $parentCommitSha, | ||
| 88 | + fileChanges: $changes | ||
| 89 | + }) { | ||
| 90 | + commit { | ||
| 91 | + url | ||
| 92 | + } | ||
| 93 | + } | ||
| 94 | + } | ||
| 95 | + `; | ||
| 96 | + const response = await fetch('https://api.github.com/graphql', { | ||
| 97 | + method: 'POST', | ||
| 98 | + headers: { | ||
| 99 | + 'Authorization': `bearer ${process.env.BOT_TOKEN}`, | ||
| 100 | + }, | ||
| 101 | + body: JSON.stringify({ | ||
| 102 | + query, | ||
| 103 | + variables: { | ||
| 104 | + repo, | ||
| 105 | + branch, | ||
| 106 | + parentCommitSha, | ||
| 107 | + commit_title, | ||
| 108 | + commit_body, | ||
| 109 | + changes: { | ||
| 110 | + additions: modifiedOrAddedFiles.split('\n').filter(Boolean) | ||
| 111 | + .map(path => ({ path, contents: readFileSync(path).toString('base64') })), | ||
| 112 | + deletions: deletedFiles.split('\n').filter(Boolean), | ||
| 113 | + } | ||
| 114 | + }, | ||
| 115 | + }) | ||
| 116 | + }); | ||
| 117 | + if (!response.ok) { | ||
| 118 | + console.log({statusCode: response.status, statusText: response.statusText}); | ||
| 119 | + process.exitCode ||= 1; | ||
| 120 | + } | ||
| 121 | + const data = await response.json(); | ||
| 122 | + if (data.errors?.length) { | ||
| 123 | + throw new Error('Endpoint returned an error', { cause: data }); | ||
| 124 | + } | ||
| 125 | + console.log(util.inspect(data, { depth: Infinity })); | ||
| 126 | + EOF | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments