Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

During release process, create pull request to increment major version on instead of a direct commit #4380

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/prepare_release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Prepare Release
name: Prepare Release
on:
workflow_dispatch:

Expand Down Expand Up @@ -37,24 +37,28 @@ jobs:
echo "Release branch does not exist. Continuing with preparation..."
echo "release-branch-name=${release_branch_name}" >> $GITHUB_OUTPUT
fi

- name: Get default branch
id: get-default-branch
run: |
DEFAULT_BRANCH=$(curl --silent --show-error --header "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}" | jq .default_branch --raw-output)
echo "Default branch is $DEFAULT_BRANCH"
echo "default-branch=${DEFAULT_BRANCH}" >> $GITHUB_OUTPUT
echo "default-branch=${DEFAULT_BRANCH}" >> $GITHUB_OUTPUT

- name: Increment Major version on default branch
run: |
git checkout ${{ steps.get-default-branch.outputs.default-branch }}
NEW_BRANCH="prs/temp-increment-major-$(date +%Y%m%d%H%M%S)"
git checkout -b $NEW_BRANCH
new_version_major=$((${{ steps.fetch-versions.outputs.major }} + 1))
sed -i.bak "s/set(CPACK_PACKAGE_VERSION_MAJOR \"[0-9]*\")/set(CPACK_PACKAGE_VERSION_MAJOR \"$new_version_major\")/g" CMakeLists.txt
rm CMakeLists.txt.bak
git add CMakeLists.txt
git commit -m "Update CPACK_PACKAGE_VERSION_MAJOR to $new_version_major"
git push origin ${{ steps.get-default-branch.outputs.default-branch }}
# Reset CPACK_PACKAGE_VERSION_MAJOR to its original value for the release branch
git push origin $NEW_BRANCH
# Create pull request
export GH_TOKEN=${{ secrets.GITHUB_TOKEN }}
gh pr create --base ${{ steps.get-default-branch.outputs.default-branch }} --head $NEW_BRANCH --title "Update CPACK_PACKAGE_VERSION_MAJOR to $new_version_major" --body "Auto-generated PR to update CPACK_PACKAGE_VERSION_MAJOR"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to put the GitHub token in an enviroment variable? I don't know if it is or isn't just asking the question.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case it should be safe as it never leaves the workflow.
Its validity is limited to the duration and the scope of the current workflow. (It's not a PAT)
Also its not passed to an external script but required for gh pr create

git reset --hard HEAD~1

- name: Prepare release branch and set pre-release to 0
Expand All @@ -65,7 +69,3 @@ jobs:
git add CMakeLists.txt
git commit -m "Update CPACK_PACKAGE_VERSION_PRE_RELEASE to 0"
git push origin ${{ steps.check-release-branch.outputs.release-branch-name }}
shell: bash
env:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Loading