|
| 1 | +name: Draft release pull request |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [closed] |
| 6 | + branches: |
| 7 | + - main |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: ${{ github.workflow }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +jobs: |
| 14 | + generate-changelog: |
| 15 | + name: Create a PR to update version and release notes |
| 16 | + if: github.event.pull_request.merged == true |
| 17 | + permissions: |
| 18 | + contents: write |
| 19 | + actions: write |
| 20 | + pull-requests: write |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + fetch-depth: 0 # Needed to get all tags for changelog generation |
| 26 | + - name: Set up Python 3.12 |
| 27 | + uses: actions/setup-python@v4 |
| 28 | + with: |
| 29 | + python-version: 3.12 |
| 30 | + cache: pip |
| 31 | + - name: Install build tool |
| 32 | + run: python -m pip install hatch |
| 33 | + - name: Determine Version Bump from PR Labels |
| 34 | + id: version |
| 35 | + run: | |
| 36 | + BUMP="patch" |
| 37 | + LABELS='${{ toJSON(github.event.pull_request.labels.*.name) }}' |
| 38 | + echo "Checking labels: $LABELS" |
| 39 | + if echo "$LABELS" | grep -q "semver:major"; then |
| 40 | + BUMP="major" |
| 41 | + elif echo "$LABELS" | grep -q "semver:minor"; then |
| 42 | + BUMP="minor" |
| 43 | + elif echo "$LABELS" | grep -q "semver:alpha"; then |
| 44 | + BUMP="alpha" |
| 45 | + elif echo "$LABELS" | grep -q "semver:beta"; then |
| 46 | + BUMP="beta" |
| 47 | + elif echo "$LABELS" | grep -q "semver:preview"; then |
| 48 | + BUMP="preview" |
| 49 | + elif echo "$LABELS" | grep -q "semver:dev"; then |
| 50 | + BUMP="dev" |
| 51 | + fi |
| 52 | + echo "Version bump determined: $BUMP" |
| 53 | + echo "level=${BUMP}" >> $GITHUB_OUTPUT |
| 54 | + - name: Bump version |
| 55 | + run: hatch version ${{ steps.version.outputs.level }} |
| 56 | + - name: Generate release notes |
| 57 | + if: steps.version.outputs.level == 'major' || steps.version.outputs.level == 'minor' || steps.version.outputs.level == 'patch' || steps.version.outputs.level == 'beta' |
| 58 | + id: changelog |
| 59 | + env: |
| 60 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 61 | + run: | |
| 62 | + # This will be empty if there are no releases yet |
| 63 | + PREVIOUS_VERSION=$(gh release view --json tagName --jq .tagName 2>/dev/null || echo "") |
| 64 | + NEXT_VERSION="v$(hatch version)" |
| 65 | + echo "## $NEXT_VERSION ($(date -I))" > changelog.md |
| 66 | +
|
| 67 | + # Build arguments for the API call |
| 68 | + ARGS=("--method" "POST" "-H" "Accept: application/vnd.github.v3+json" "/repos/SFDO-Tooling/CumulusCI/releases/generate-notes" "-f" "target_commitish=main" "-f" "tag_name=$NEXT_VERSION") |
| 69 | + if [ -n "$PREVIOUS_VERSION" ]; then |
| 70 | + echo "Generating notes between $PREVIOUS_VERSION and $NEXT_VERSION" |
| 71 | + ARGS+=("-f" "previous_tag_name=$PREVIOUS_VERSION") |
| 72 | + else |
| 73 | + echo "No previous release found. Generating notes for the first release." |
| 74 | + fi |
| 75 | +
|
| 76 | + gh api "${ARGS[@]}" --jq '.body' | |
| 77 | + sed -e 's_\(https.*\/\)\([0-9]*\)$_[#\2](\1\2)_' \ |
| 78 | + -e 's_by @\(.*\) in_by [@\1](https://github.com/\1) in_' >> changelog.md |
| 79 | + python utility/update-history.py |
| 80 | + - name: Lint history |
| 81 | + if: steps.version.outputs.level == 'major' || steps.version.outputs.level == 'minor' || steps.version.outputs.level == 'patch' || steps.version.outputs.level == 'beta' |
| 82 | + run: | |
| 83 | + npm install prettier |
| 84 | + npx prettier --write docs/history.md |
| 85 | + - name: Commit version and changelog |
| 86 | + run: | |
| 87 | + BRANCH_NAME="release-$(hatch version)" |
| 88 | + git config user.name github-actions[bot] |
| 89 | + git config user.email 41898282+github-actions[bot]@users.noreply.github.com |
| 90 | + git switch -c "$BRANCH_NAME" |
| 91 | + git add docs/history.md cumulusci/__about__.py |
| 92 | + git commit -m "Update changelog (automated)" |
| 93 | + # Delete the remote branch if it exists, ignoring errors if it doesn't. |
| 94 | + git push origin --delete "$BRANCH_NAME" || true |
| 95 | + # Push the new branch. |
| 96 | + git push origin "$BRANCH_NAME" |
| 97 | + - name: Create and Merge Release PR |
| 98 | + env: |
| 99 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 100 | + run: | |
| 101 | + PR_URL=$(gh pr create --title "Release v$(hatch version)" --fill --label 'auto-pr') |
| 102 | + if [ -n "$PR_URL" ]; then |
| 103 | + echo "Created PR: $PR_URL" |
| 104 | + gh pr merge "$PR_URL" --merge --delete-branch |
| 105 | + echo "PR merged and branch deleted." |
| 106 | + else |
| 107 | + echo "PR creation failed." |
| 108 | + exit 1 |
| 109 | + fi |
| 110 | + - name: Call Release Workflow |
| 111 | + uses: benc-uk/workflow-dispatch@v1 |
| 112 | + with: |
| 113 | + workflow: "Publish and release CumulusCI" |
| 114 | + token: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments