From f2e8d94a2eebc28612967c43dc06a5881052c8f6 Mon Sep 17 00:00:00 2001 From: Rupesh J Date: Fri, 18 Jul 2025 13:53:54 +0530 Subject: [PATCH] Auto merge PR. Create semver:dev label by default. --- .github/workflows/pr-labeler.yml | 25 +++++++++++++++++++++++++ .github/workflows/pre-release.yml | 27 +++++++++++++++++++++++---- 2 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/pr-labeler.yml diff --git a/.github/workflows/pr-labeler.yml b/.github/workflows/pr-labeler.yml new file mode 100644 index 0000000000..b60cf657d4 --- /dev/null +++ b/.github/workflows/pr-labeler.yml @@ -0,0 +1,25 @@ +name: Add Default PR Label + +on: + pull_request: + types: [opened] + +jobs: + add-label: + name: Add default semver label + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - name: Add semver:dev label if no other semver label exists + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_NUMBER: ${{ github.event.pull_request.number }} + run: | + LABELS=$(gh pr view "$PR_NUMBER" --json labels --jq '.labels.[].name' 2>/dev/null || echo "") + if ! echo "$LABELS" | grep -q "semver:"; then + echo "No semver label found. Adding semver:dev." + gh pr edit "$PR_NUMBER" --add-label "semver:dev" + else + echo "A semver label is already present. Skipping." + fi diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml index b46ef30897..01cdfd31ae 100644 --- a/.github/workflows/pre-release.yml +++ b/.github/workflows/pre-release.yml @@ -6,10 +6,17 @@ on: branches: - main +concurrency: + group: ${{ github.workflow }} + cancel-in-progress: true + jobs: generate-changelog: name: Create a PR to update version and release notes if: github.event.pull_request.merged == true + permissions: + contents: write + pull-requests: write runs-on: ubuntu-latest steps: - uses: actions/checkout@main @@ -77,15 +84,27 @@ jobs: - name: Commit changes if: steps.version.outputs.level == 'major' || steps.version.outputs.level == 'minor' || steps.version.outputs.level == 'patch' || steps.version.outputs.level == 'beta' run: | + BRANCH_NAME="release-$(hatch version)" git config user.name github-actions[bot] git config user.email 41898282+github-actions[bot]@users.noreply.github.com - git switch -c "release-$(hatch version)" + git switch -c "$BRANCH_NAME" git add docs/history.md cumulusci/__about__.py git commit -m "Update changelog (automated)" - git push origin "release-$(hatch version)" - - name: Commit changes and open PR + # Delete the remote branch if it exists, ignoring errors if it doesn't. + git push origin --delete "$BRANCH_NAME" || true + # Push the new branch. + git push origin "$BRANCH_NAME" + - name: Create and Auto-Merge Release PR if: steps.version.outputs.level == 'major' || steps.version.outputs.level == 'minor' || steps.version.outputs.level == 'patch' || steps.version.outputs.level == 'beta' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - gh pr create --title "Release v$(hatch version)" --fill --label 'auto-pr' + PR_URL=$(gh pr create --title "Release v$(hatch version)" --fill --label 'auto-pr') + if [ -n "$PR_URL" ]; then + echo "Created PR: $PR_URL" + gh pr merge "$PR_URL" --auto --merge --delete-branch + echo "Enabled auto-merge for the release PR." + else + echo "PR creation failed." + exit 1 + fi