diff --git a/.github/workflows/create-rc-release-pr.yaml b/.github/workflows/create-rc-release-pr.yaml new file mode 100644 index 00000000000..11d1ad39c7f --- /dev/null +++ b/.github/workflows/create-rc-release-pr.yaml @@ -0,0 +1,122 @@ +name: Create RC Release PR + +on: + workflow_dispatch: + inputs: + version: + description: The rc release version to create (MAJOR.MINOR.PATCHrcN e.g. 2.42.4rc0). + required: true + +defaults: + run: + shell: bash + +jobs: + org-check: + name: Check GitHub Organization + if: ${{ github.repository_owner == 'pantsbuild' }} + runs-on: ubuntu-latest + steps: + - name: Noop + run: "true" + + github-pr: + name: Create an rc release pull request + needs: org-check + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + + steps: + - name: Determine release version + id: validate-version + run: | + version="${{ inputs.version }}" + + if [[ -z "$version" ]]; then + echo "::error::An input 'version' must be specified" + exit 1 + + elif (( ${#version} > 11 )); then + echo "::error::The input 'version' must be smaller than 12 characters (i.e. allows '2.99.99rc99')" + exit 1 + + elif [[ ! "${version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+rc[0-9]+$ ]]; then + echo "::error::The input version '${version}' must be of the form MAJOR.MINOR.PATCHrcN (8.9.10rc99)" + exit 1 + fi + + major_minor=$(echo "$version" | grep -oE '^[0-9]+\.[0-9]+') + base_branch="${major_minor}.x" + + echo "::notice::Release version is: ${version}, with major-minor: ${major_minor}" + echo "release-version=${version}" >> $GITHUB_OUTPUT + echo "major-minor-version=${major_minor}" >> $GITHUB_OUTPUT + + echo "::notice::Base branch is: ${base_branch}" + echo "base-branch=${base_branch}" >> "$GITHUB_OUTPUT" + + - uses: actions/checkout@v6 + with: + ref: ${{ steps.validate-version.outputs.base-branch }} + fetch-depth: 0 # Required for contributors file + + - name: Update CONTRIBUTORS.md and VERSION files + env: + RELEASE_VERSION: ${{ steps.validate-version.outputs.release-version }} + run: | + if [[ -z "$RELEASE_VERSION" ]]; then + echo "::error::The 'RELEASE_VERSION' was empty" + exit 1 + fi + + echo "$RELEASE_VERSION" > src/python/pants/VERSION + + # Create an alphabetical list of all contributors, using the .mailmap where available (stripping bots) + # The `sed` at the end is to match the existing Python code which prefixes a "+ " to each name + { + printf "Created as part of the release process.\n\n" + + git log --use-mailmap --format=format:%aN HEAD \ + | sort -u \ + | grep -vxF \ + -e "dependabot[bot]" \ + -e "github-actions[bot]" \ + -e "Worker Pants (Pantsbuild GitHub Automation Bot)" \ + | sed 's/^/+ /' + } > CONTRIBUTORS.md + + - name: Commit changes and create pull request + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BASE_BRANCH: ${{ steps.validate-version.outputs.base-branch }} + RELEASE_VERSION: ${{ steps.validate-version.outputs.release-version }} + run: | + if [[ -z $(git status --porcelain) ]]; then + echo "::error::No changes detected - skipping PR creation" + exit 1 + fi + + # Assign our general account to the local user + git config --local user.email "pantsbuild+github-automation@gmail.com" + git config --local user.name "Worker Pants (Pantsbuild GitHub Automation Bot)" + + # Create and checkout a new release automation branch + BRANCH_NAME="automation/release/$RELEASE_VERSION" + git checkout -b "$BRANCH_NAME" + + # Commit and push to the release branch + TITLE="Prepare $RELEASE_VERSION" + git add src/python/pants/VERSION CONTRIBUTORS.md + git commit -m "$TITLE" + git push -u origin "$BRANCH_NAME" + + # Create PR from the release automation branch to stable release branch + gh pr create \ + --title "$TITLE" \ + --body "" \ + --base "$BASE_BRANCH" \ + --head "$BRANCH_NAME" \ + --label "automation:release-prep,category:internal" \ + --assignee "${{ github.actor }}"