From ee50a91823796c55f05da7e01dd6032a6d9ca4ec Mon Sep 17 00:00:00 2001 From: John K Watson Date: Fri, 10 May 2024 09:23:44 -0700 Subject: [PATCH] GHA for generating the post-release pull request --- .github/scripts/get-prior-version.sh | 22 +++++++ .../workflows/generate-post-release-pr.yml | 61 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100755 .github/scripts/get-prior-version.sh create mode 100644 .github/workflows/generate-post-release-pr.yml diff --git a/.github/scripts/get-prior-version.sh b/.github/scripts/get-prior-version.sh new file mode 100755 index 00000000000..ca4987f09ac --- /dev/null +++ b/.github/scripts/get-prior-version.sh @@ -0,0 +1,22 @@ +version=$(.github/scripts/get-version.sh) +if [[ $version =~ ^([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then + major="${BASH_REMATCH[1]}" + minor="${BASH_REMATCH[2]}" + patch="${BASH_REMATCH[3]}" +else + echo "unexpected version: $version" + exit 1 +fi +if [[ $patch == 0 ]]; then + if [[ $minor == 0 ]]; then + prior_major=$((major - 1)) + prior_minor=$(grep -Po "^## Version $prior_major.\K[0-9]+" CHANGELOG.md | head -1) + prior_version="$prior_major.$prior_minor" + else + prior_version="$major.$((minor - 1)).0" + fi +else + prior_version="$major.$minor.$((patch - 1))" +fi + +echo $prior_version diff --git a/.github/workflows/generate-post-release-pr.yml b/.github/workflows/generate-post-release-pr.yml new file mode 100644 index 00000000000..ef1a61c8184 --- /dev/null +++ b/.github/workflows/generate-post-release-pr.yml @@ -0,0 +1,61 @@ +name: Generate Post-Release PR +on: + workflow_dispatch: + +jobs: + prereqs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Verify prerequisites + run: | + if [[ $GITHUB_REF_NAME != main ]]; then + echo this workflow should only be run against main + exit 1 + fi + + create-pull-request-against-main: + runs-on: ubuntu-latest + needs: + - prereqs + steps: + - uses: actions/checkout@v4 + + - name: Set environment variables + run: | + version=$(.github/scripts/get-version.sh) + if [[ $version =~ ^([0-9]+)\.([0-9]+)\.0$ ]]; then + major="${BASH_REMATCH[1]}" + minor="${BASH_REMATCH[2]}" + next_version="$major.$((minor + 1)).0" + else + echo "unexpected version: $version" + exit 1 + fi + echo "NEXT_VERSION=$next_version" >> $GITHUB_ENV + echo "VERSION=$version" >> $GITHUB_ENV + prior_version=$(.github/scripts/get-prior-version.sh) + echo "PRIOR_VERSION=$prior_version" >> $GITHUB_ENV + + - name: Use CLA approved github bot + run: .github/scripts/use-cla-approved-github-bot.sh + + - name: Create pull request against main + env: + # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows + GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} + run: | + ./gradlew updateVersionInDocs -Prelease.version=$VERSION + ./gradlew japicmp -PapiBaseVersion=$PRIOR_VERSION -PapiNewVersion=$VERSION + ./gradlew --refresh-dependencies japicmp + + message="Post release for version $VERSION" + body="Post-release updates for version \`$VERSION\`." + branch="opentelemetrybot/post-release-for-${VERSION}" + + git checkout -b $branch + git commit -a -m "$message" + git push --set-upstream origin $branch + gh pr create --title "$message" \ + --body "$body" \ + --base main