diff --git a/README.md b/README.md index 9152b7c..1623c83 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ ## Usage Follow the [instruction](https://docs.github.com/en/actions/learn-github-actions/reusing-workflows#calling-a-reusable-workflow) from Github to use any workflows in this repository. +- [Automate creating the Release pull request](create_release_pull_request/README.md) + ## How to contribute - Refer to the [official guide](https://docs.github.com/en/actions/learn-github-actions/reusing-workflows#creating-a-reusable-workflow) to learn how to define a reusable workflow - Put the new workflow under `./github/workflows` directory diff --git a/create_release_pull_request/README.md b/create_release_pull_request/README.md new file mode 100644 index 0000000..7f71bea --- /dev/null +++ b/create_release_pull_request/README.md @@ -0,0 +1,6 @@ +# Automate creating the Release pull request + +## Usage + +- Create a `create_release_pull_request.yml` workflow, sample [here](sample/workflows/create_release_pull_request.yml). +- Provide a release changelog configuration file, sample [here](sample/workflows/config/changelog-release.json). diff --git a/create_release_pull_request/action.yml b/create_release_pull_request/action.yml new file mode 100644 index 0000000..8b0cc42 --- /dev/null +++ b/create_release_pull_request/action.yml @@ -0,0 +1,102 @@ +name: Automate creating the Release pull request +description: Automate creating the Release pull request +inputs: + release_version: + description: Release version + required: true + changelog_configuration: + description: The changelog configuration file path, e.g., ".github/workflows/config/changelog-release.json" + required: true + default: ".github/workflows/config/changelog_release.json" + github_token: + description: The GitHub PAT for this action to use + required: false + default: ${{ github.token }} + base_branch: + description: The base branch for the release pull request, e.g., "main" + required: false + default: main + assignee: + description: The assignee for the Release pull request, e.g., bot + required: false + label: + description: 'The label for the Release pull request, e.g., "type : release"' + required: false + default: "type : release" + release_body_url: + description: The URL to put in the release body. If not set, the GitHub Milestone (= release_version) URL will be used. + required: false + +runs: + using: composite + steps: + - name: Find the HEAD commit + id: find_head_commit + shell: bash + run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT + + - name: Find the latest ${{ inputs.base_branch }} commit + id: find_latest_base_commit + shell: bash + run: | + git fetch origin ${{ inputs.base_branch }} + echo "sha=$(git rev-parse origin/${{ inputs.base_branch }})" >> $GITHUB_OUTPUT + + - name: Generate changelog + id: generate_changelog + uses: mikepenz/release-changelog-builder-action@v4 + with: + token: ${{ inputs.github_token }} + configuration: ${{ inputs.changelog_configuration }} + outputFile: body_content.txt + fromTag: ${{ steps.find_latest_base_commit.outputs.sha }} + toTag: ${{ steps.find_head_commit.outputs.sha }} + + - name: Find milestone + id: find_milestone + env: + GH_TOKEN: ${{ inputs.github_token }} + shell: bash + run: | + gh extension install valeriobelli/gh-milestone + MILESTONE=${{ inputs.release_version }} + MILESTONE_URL=$(gh milestone list --query $MILESTONE --json url --jq ".[0].url") + echo "milestone=$MILESTONE" >> $GITHUB_OUTPUT + echo "milestone_url=$MILESTONE_URL" >> $GITHUB_OUTPUT + + - name: Prepend Release URL into the changelog + shell: bash + run: | + if [ -n "${{ inputs.release_body_url }}" ]; then + echo -e "${{ inputs.release_body_url }}\n\n$(cat body_content.txt)" > body_content.txt + else + echo -e "${{ steps.find_milestone.outputs.milestone_url }}\n\n$(cat body_content.txt)" > body_content.txt + fi + + - name: Create the Release pull request + env: + GH_TOKEN: ${{ inputs.github_token }} + shell: bash + run: | + RELEASE_BRANCH=release/${{ inputs.release_version }} + + # Create the release branch + git checkout -b $RELEASE_BRANCH + git push origin $RELEASE_BRANCH -f + + # Add milestone if available + if [ -n "${{ steps.find_milestone.outputs.milestone_url }}" ]; then + MILESTONE_PARAM="--milestone ${{ steps.find_milestone.outputs.milestone }}" + else + MILESTONE_PARAM="" + fi + + # Create the pull request + gh pr create \ + --base ${{ inputs.base_branch }} \ + --head $RELEASE_BRANCH \ + --assignee ${{ inputs.assignee }} \ + --title "Release - ${{ inputs.release_version }}" \ + --label "${{ inputs.label }}" \ + $MILESTONE_PARAM \ + --body-file body_content.txt \ diff --git a/create_release_pull_request/sample/workflows/config/changelog-release.json b/create_release_pull_request/sample/workflows/config/changelog-release.json new file mode 100644 index 0000000..6480db0 --- /dev/null +++ b/create_release_pull_request/sample/workflows/config/changelog-release.json @@ -0,0 +1,35 @@ +{ + "categories": [ + { + "title": "## โœจ Features", + "labels": [ + "type : feature" + ], + "empty_content": "N/A" + }, + { + "title": "## ๐Ÿ› Bug fixes", + "labels": [ + "type : bug" + ], + "empty_content": "N/A" + }, + { + "title": "## ๐Ÿงน Chores", + "labels": [ + "type : chore" + ], + "empty_content": "N/A" + }, + { + "title": "## Others", + "exclude_labels": [ + "type : feature", + "type : bug", + "type : chore", + "type : release" + ] + } + ], + "max_pull_requests": 200 +} diff --git a/create_release_pull_request/sample/workflows/create_release_pull_request.yml b/create_release_pull_request/sample/workflows/create_release_pull_request.yml new file mode 100644 index 0000000..4d17376 --- /dev/null +++ b/create_release_pull_request/sample/workflows/create_release_pull_request.yml @@ -0,0 +1,28 @@ +name: Create the Release pull request + +on: + workflow_dispatch: + +jobs: + create_release_pull_request: + name: Create the Release pull request + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: + - name: Check out + uses: actions/checkout@v4 + + - name: Read the current version + id: version + uses: christian-draeger/read-properties@1.1.1 + with: + path: "version.properties" + properties: "version" + + - uses: nimblehq/github-actions-workflows/create_release_pull_request@0.1.10 + with: + release_version: ${{ steps.version.outputs.version }} + changelog_configuration: ".github/workflows/config/changelog-release.json" + assignee: bot-nimble