|
| 1 | +name: Automate creating the Release pull request |
| 2 | +description: Automate creating the Release pull request |
| 3 | +inputs: |
| 4 | + release_version: |
| 5 | + description: Release version |
| 6 | + required: true |
| 7 | + changelog_configuration: |
| 8 | + description: The changelog configuration file path, e.g., ".github/workflows/config/changelog-release.json" |
| 9 | + required: true |
| 10 | + default: ".github/workflows/config/changelog_release.json" |
| 11 | + github_token: |
| 12 | + description: The GitHub PAT for this action to use |
| 13 | + required: false |
| 14 | + default: ${{ github.token }} |
| 15 | + base_branch: |
| 16 | + description: The base branch for the release pull request, e.g., "main" |
| 17 | + required: false |
| 18 | + default: main |
| 19 | + assignee: |
| 20 | + description: The assignee for the Release pull request, e.g., bot |
| 21 | + required: false |
| 22 | + label: |
| 23 | + description: 'The label for the Release pull request, e.g., "type : release"' |
| 24 | + required: false |
| 25 | + default: "type : release" |
| 26 | + release_body_url: |
| 27 | + description: The URL to put in the release body. If not set, the GitHub Milestone (= release_version) URL will be used. |
| 28 | + required: false |
| 29 | + |
| 30 | +runs: |
| 31 | + using: composite |
| 32 | + steps: |
| 33 | + - name: Find the HEAD commit |
| 34 | + id: find_head_commit |
| 35 | + shell: bash |
| 36 | + run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT |
| 37 | + |
| 38 | + - name: Find the latest ${{ inputs.base_branch }} commit |
| 39 | + id: find_latest_base_commit |
| 40 | + shell: bash |
| 41 | + run: | |
| 42 | + git fetch origin ${{ inputs.base_branch }} |
| 43 | + echo "sha=$(git rev-parse origin/${{ inputs.base_branch }})" >> $GITHUB_OUTPUT |
| 44 | +
|
| 45 | + - name: Generate changelog |
| 46 | + id: generate_changelog |
| 47 | + uses: mikepenz/release-changelog-builder-action@348e88fab4c37338b1e803ceb2d4a7a5db6c0833 # mikepenz/release-changelog-builder-action@v6.2.2 |
| 48 | + with: |
| 49 | + token: ${{ inputs.github_token }} |
| 50 | + configuration: ${{ inputs.changelog_configuration }} |
| 51 | + outputFile: body_content.txt |
| 52 | + fromTag: ${{ steps.find_latest_base_commit.outputs.sha }} |
| 53 | + toTag: ${{ steps.find_head_commit.outputs.sha }} |
| 54 | + |
| 55 | + - name: Find milestone |
| 56 | + id: find_milestone |
| 57 | + env: |
| 58 | + GH_TOKEN: ${{ inputs.github_token }} |
| 59 | + shell: bash |
| 60 | + run: | |
| 61 | + gh extension install valeriobelli/gh-milestone |
| 62 | + MILESTONE=${{ inputs.release_version }} |
| 63 | + MILESTONE_URL=$(gh milestone list --query $MILESTONE --json url --jq ".[0].url") |
| 64 | + echo "milestone=$MILESTONE" >> $GITHUB_OUTPUT |
| 65 | + echo "milestone_url=$MILESTONE_URL" >> $GITHUB_OUTPUT |
| 66 | +
|
| 67 | + - name: Prepend Release URL into the changelog |
| 68 | + shell: bash |
| 69 | + run: | |
| 70 | + if [ -n "${{ inputs.release_body_url }}" ]; then |
| 71 | + echo -e "${{ inputs.release_body_url }}\n\n$(cat body_content.txt)" > body_content.txt |
| 72 | + else |
| 73 | + echo -e "${{ steps.find_milestone.outputs.milestone_url }}\n\n$(cat body_content.txt)" > body_content.txt |
| 74 | + fi |
| 75 | +
|
| 76 | + - name: Create the Release pull request |
| 77 | + env: |
| 78 | + GH_TOKEN: ${{ inputs.github_token }} |
| 79 | + shell: bash |
| 80 | + run: | |
| 81 | + RELEASE_BRANCH=release/${{ inputs.release_version }} |
| 82 | +
|
| 83 | + # Create the release branch |
| 84 | + git checkout -b $RELEASE_BRANCH |
| 85 | + git push origin $RELEASE_BRANCH -f |
| 86 | +
|
| 87 | + # Add milestone if available |
| 88 | + if [ -n "${{ steps.find_milestone.outputs.milestone_url }}" ]; then |
| 89 | + MILESTONE_PARAM="--milestone ${{ steps.find_milestone.outputs.milestone }}" |
| 90 | + else |
| 91 | + MILESTONE_PARAM="" |
| 92 | + fi |
| 93 | +
|
| 94 | + # Create the pull request |
| 95 | + gh pr create \ |
| 96 | + --base ${{ inputs.base_branch }} \ |
| 97 | + --head $RELEASE_BRANCH \ |
| 98 | + --assignee ${{ inputs.assignee }} \ |
| 99 | + --title "Release - ${{ inputs.release_version }}" \ |
| 100 | + --label "${{ inputs.label }}" \ |
| 101 | + $MILESTONE_PARAM \ |
| 102 | + --body-file body_content.txt \ |
0 commit comments