From 5aa3d35a842f43f83fabde439a700b571275d8cf Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Fri, 1 Nov 2024 14:52:17 -0300 Subject: [PATCH 1/5] build: add create release proposal action --- .github/workflows/create-release-proposal.yml | 81 +++++++++++++++++++ tools/actions/create-release.sh | 44 ++++++++++ 2 files changed, 125 insertions(+) create mode 100644 .github/workflows/create-release-proposal.yml create mode 100755 tools/actions/create-release.sh diff --git a/.github/workflows/create-release-proposal.yml b/.github/workflows/create-release-proposal.yml new file mode 100644 index 00000000000000..1c7e9f285903e5 --- /dev/null +++ b/.github/workflows/create-release-proposal.yml @@ -0,0 +1,81 @@ +# This action requires the following secrets to be set on the repository: +# GH_USER_NAME: GitHub user whose Jenkins and GitHub token are defined below +# GH_USER_TOKEN: GitHub user token, to be used by ncu and to push changes +# JENKINS_TOKEN: Jenkins token, to be used to check CI status + +name: Create Release Proposal + +on: + workflow_dispatch: + inputs: + release-line: + required: true + type: number + default: 23 + description: 'The release line (without dots or prefix). e.g: 22' + release-date: + required: true + type: string + default: YYYY-MM-DD + description: The release date in YYYY-MM-DD format + +concurrency: ${{ github.workflow }} + +env: + NODE_VERSION: lts/* + +permissions: + contents: write + +jobs: + releasePrepare: + env: + STAGING_BRANCH: v${{ inputs.release-line }}.x-staging + RELEASE_BRANCH: v${{ inputs.release-line }}.x + RELEASE_DATE: ${{ inputs.release-date }} + RELEASE_LINE: ${{ inputs.release-line }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + with: + ref: ${{ env.STAGING_BRANCH }} + # Needs the whole git history for ncu to work + # See https://github.com/nodejs/node-core-utils/pull/486 + fetch-depth: 0 + + # Install dependencies + - name: Install Node.js + uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3 + with: + node-version: ${{ env.NODE_VERSION }} + + - name: Install @node-core/utils + run: npm install -g @node-core/utils + + - name: Configure @node-core/utils + run: | + ncu-config set branch "${RELEASE_BRANCH}" + ncu-config set upstream origin + ncu-config set username "$USERNAME" + ncu-config set token "$GH_TOKEN" + ncu-config set jenkins_token "$JENKINS_TOKEN" + ncu-config set repo "$(echo "$GITHUB_REPOSITORY" | cut -d/ -f2)" + ncu-config set owner "${GITHUB_REPOSITORY_OWNER}" + env: + USERNAME: ${{ secrets.JENKINS_USER }} + GH_TOKEN: ${{ secrets.GH_USER_TOKEN }} + JENKINS_TOKEN: ${{ secrets.JENKINS_TOKEN }} + + - name: Set up ghauth config (Ubuntu) + run: | + mkdir -p ~/.config/changelog-maker/ + echo '{ + "user": "'$(ncu-config get username)'", + "token": "'$(ncu-config get token)'" + }' > ~/.config/changelog-maker/config.json + + - name: Start git node release prepare + run: | + ./tools/actions/create-release.sh "${RELEASE_DATE}" "${RELEASE_LINE}" + env: + GH_TOKEN: ${{ secrets.GH_USER_TOKEN }} diff --git a/tools/actions/create-release.sh b/tools/actions/create-release.sh new file mode 100755 index 00000000000000..b3a0cd96d014f1 --- /dev/null +++ b/tools/actions/create-release.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +set -xe + +RELEASE_DATE=$1 +RELEASE_LINE=$2 + +if [ -z "$RELEASE_DATE" ] || [ -z "$RELEASE_LINE" ]; then + echo "Usage: $0 " + exit 1 +fi + +git config --local user.email "github-bot@iojs.org" +git config --local user.name "Node.js GitHub Bot" + +git node release --prepare --skipBranchDiff --yes --releaseDate "$RELEASE_DATE" +# We use it to not specify the branch name as it changes based on +# the commit list (semver-minor/semver-patch) +git config push.default current +git push + +TITLE=$(awk "/^## ${RELEASE_DATE}/ { print substr(\$0, 4) }" "doc/changelogs/CHANGELOG_V${RELEASE_LINE}.md") + +# Use a temporary file for the PR body +TEMP_BODY=$(mktemp) +awk "/## ${RELEASE_DATE}/,/^ "$TEMP_BODY" + +gh pr create --title "$TITLE" --body-file "$TEMP_BODY" --base "v$RELEASE_LINE.x" + +# Dynamically get the repository (owner/repo) and branch +REPO=$(git remote get-url origin | sed -E 's|^.*github.com[/:]([^/]+/[^.]+)(\.git)?$|\1|') +BRANCH=$(git branch --show-current) + +# Get the PR URL for the current branch in the repository +PR_URL=$(gh pr list --repo "$REPO" --head "$BRANCH" --json url -q ".[0].url") + +# Replace "TODO" with the PR URL in the last commit +git commit --amend --no-edit -m "$(git log -1 --pretty=%B | sed "s|PR-URL: TODO|PR-URL: $PR_URL|")" + +# Force-push the amended commit +git push --force + +rm "$TEMP_BODY" + From 644adfc699d2edca31f8d86a0998d01da1f84009 Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Fri, 22 Nov 2024 17:01:01 -0300 Subject: [PATCH 2/5] fixup! build: add create release proposal action --- tools/actions/create-release.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/actions/create-release.sh b/tools/actions/create-release.sh index b3a0cd96d014f1..f698098bbe09d7 100755 --- a/tools/actions/create-release.sh +++ b/tools/actions/create-release.sh @@ -34,8 +34,11 @@ BRANCH=$(git branch --show-current) # Get the PR URL for the current branch in the repository PR_URL=$(gh pr list --repo "$REPO" --head "$BRANCH" --json url -q ".[0].url") +# Get the last commit message +LAST_COMMIT_MSG=$(git log -1 --pretty=%B) + # Replace "TODO" with the PR URL in the last commit -git commit --amend --no-edit -m "$(git log -1 --pretty=%B | sed "s|PR-URL: TODO|PR-URL: $PR_URL|")" +git commit --amend --no-edit -m "$(echo "$LAST_COMMIT_MSG" | sed "s|PR-URL: TODO|PR-URL: $PR_URL|")" || true # Force-push the amended commit git push --force From 51f580326c482d216edb077fd0af9b470fdc69f8 Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Fri, 22 Nov 2024 19:49:30 -0300 Subject: [PATCH 3/5] fixup! fixup! build: add create release proposal action --- tools/actions/create-release.sh | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/tools/actions/create-release.sh b/tools/actions/create-release.sh index f698098bbe09d7..e98d7b14e2251f 100755 --- a/tools/actions/create-release.sh +++ b/tools/actions/create-release.sh @@ -22,17 +22,9 @@ git push TITLE=$(awk "/^## ${RELEASE_DATE}/ { print substr(\$0, 4) }" "doc/changelogs/CHANGELOG_V${RELEASE_LINE}.md") # Use a temporary file for the PR body -TEMP_BODY=$(mktemp) -awk "/## ${RELEASE_DATE}/,/^ "$TEMP_BODY" +TEMP_BODY="$(awk "/## ${RELEASE_DATE}/,/^ Date: Fri, 22 Nov 2024 20:59:00 -0300 Subject: [PATCH 4/5] fixup! fixup! fixup! build: add create release proposal action --- .github/workflows/create-release-proposal.yml | 5 +++++ tools/actions/create-release.sh | 9 +++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/create-release-proposal.yml b/.github/workflows/create-release-proposal.yml index 1c7e9f285903e5..4da734cc5583fd 100644 --- a/.github/workflows/create-release-proposal.yml +++ b/.github/workflows/create-release-proposal.yml @@ -74,6 +74,11 @@ jobs: "token": "'$(ncu-config get token)'" }' > ~/.config/changelog-maker/config.json + - name: Setup GitHub user + run: | + git config --local user.email "github-bot@iojs.org" + git config --local user.name "Node.js GitHub Bot" + - name: Start git node release prepare run: | ./tools/actions/create-release.sh "${RELEASE_DATE}" "${RELEASE_LINE}" diff --git a/tools/actions/create-release.sh b/tools/actions/create-release.sh index e98d7b14e2251f..3a69b3f5602ffc 100755 --- a/tools/actions/create-release.sh +++ b/tools/actions/create-release.sh @@ -10,9 +10,6 @@ if [ -z "$RELEASE_DATE" ] || [ -z "$RELEASE_LINE" ]; then exit 1 fi -git config --local user.email "github-bot@iojs.org" -git config --local user.name "Node.js GitHub Bot" - git node release --prepare --skipBranchDiff --yes --releaseDate "$RELEASE_DATE" # We use it to not specify the branch name as it changes based on # the commit list (semver-minor/semver-patch) @@ -26,11 +23,11 @@ TEMP_BODY="$(awk "/## ${RELEASE_DATE}/,/^ Date: Fri, 22 Nov 2024 21:07:07 -0300 Subject: [PATCH 5/5] Update .github/workflows/create-release-proposal.yml Co-authored-by: Antoine du Hamel --- .github/workflows/create-release-proposal.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/create-release-proposal.yml b/.github/workflows/create-release-proposal.yml index 4da734cc5583fd..5f0f80eed24c95 100644 --- a/.github/workflows/create-release-proposal.yml +++ b/.github/workflows/create-release-proposal.yml @@ -74,7 +74,7 @@ jobs: "token": "'$(ncu-config get token)'" }' > ~/.config/changelog-maker/config.json - - name: Setup GitHub user + - name: Setup git author run: | git config --local user.email "github-bot@iojs.org" git config --local user.name "Node.js GitHub Bot"