From c5e298098271a895e7ab835e9995d13f9b954679 Mon Sep 17 00:00:00 2001 From: "Luong Vo (Lucas)" Date: Thu, 23 Nov 2023 23:41:04 +0700 Subject: [PATCH 01/10] Add "Create Release PR" composite action --- create_release_pr/action.yml | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 create_release_pr/action.yml diff --git a/create_release_pr/action.yml b/create_release_pr/action.yml new file mode 100644 index 0000000..ffa6302 --- /dev/null +++ b/create_release_pr/action.yml @@ -0,0 +1,55 @@ +name: Automate creating the Release pull request +description: Automate creating the Release pull request +inputs: + version: + description: Current release version + required: true + base_branch: + description: The base branch for the release pull request + required: true + assignee: + description: The assignee username, e.g. bot-nimble + required: true + +runs: + using: composite + steps: + - name: Find HEAD commit + id: head + run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT + + - name: Build changelog + id: changelog + uses: mikepenz/release-changelog-builder-action@v4 + with: + configuration: ".github/workflows/changelog-config.json" + # Listing PRs from the last tag to the HEAD commit + toTag: ${{ steps.head.outputs.sha }} + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Create the Release pull request + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + HEAD_BRANCH=release/${{ inputs.version }} + + # Fetch milestone info + gh extension install valeriobelli/gh-milestone + MILESTONE=${{ inputs.version }} + MILESTONE_URL=$(gh milestone list --query $MILESTONE --json url --jq ".[0].url") + + # Create the release branch + git checkout -b $HEAD_BRANCH + git push origin $HEAD_BRANCH + + # Create the pull request + gh pr create \ + --base ${{ inputs.base_branch }} \ + --head $HEAD_BRANCH \ + --assignee ${{ inputs.version }} \ + --title "Release - ${{ inputs.version }}" \ + --label 'type : release' \ + --milestone $MILESTONE \ + --body "$MILESTONE_URL + + ${{ steps.changelog.outputs.changelog }}" \ From 592c0813ab2747aeaebc339ad16c265295b41ec1 Mon Sep 17 00:00:00 2001 From: "Luong Vo (Lucas)" Date: Fri, 24 Nov 2023 10:10:18 +0700 Subject: [PATCH 02/10] Expose token & changelogConfigurationJson params --- create_release_pr/action.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/create_release_pr/action.yml b/create_release_pr/action.yml index ffa6302..b797a08 100644 --- a/create_release_pr/action.yml +++ b/create_release_pr/action.yml @@ -1,12 +1,18 @@ name: Automate creating the Release pull request description: Automate creating the Release pull request inputs: + token: + description: The GitHub PAT for this action to use + required: true version: description: Current release version required: true base_branch: description: The base branch for the release pull request required: true + changelogConfiguration: + description: The changelog configuration file path, e.g., ".github/workflows/config/changelog-release.json" + required: true assignee: description: The assignee username, e.g. bot-nimble required: true @@ -16,20 +22,22 @@ runs: steps: - name: Find HEAD commit id: head + shell: bash run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT - name: Build changelog id: changelog uses: mikepenz/release-changelog-builder-action@v4 with: - configuration: ".github/workflows/changelog-config.json" + configuration: ${{ inputs.changelogConfiguration }} # Listing PRs from the last tag to the HEAD commit toTag: ${{ steps.head.outputs.sha }} - token: ${{ secrets.GITHUB_TOKEN }} + token: ${{ inputs.token }} - name: Create the Release pull request env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ inputs.token }} + shell: bash run: | HEAD_BRANCH=release/${{ inputs.version }} From 04ad8e607e9dad9c6e9ea04a76aad4ce5c740a48 Mon Sep 17 00:00:00 2001 From: "Luong Vo (Lucas)" Date: Fri, 24 Nov 2023 10:23:51 +0700 Subject: [PATCH 03/10] Fix assignee user param usage & allow force pushing the release branch --- create_release_pr/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/create_release_pr/action.yml b/create_release_pr/action.yml index b797a08..e98674d 100644 --- a/create_release_pr/action.yml +++ b/create_release_pr/action.yml @@ -48,13 +48,13 @@ runs: # Create the release branch git checkout -b $HEAD_BRANCH - git push origin $HEAD_BRANCH + git push origin $HEAD_BRANCH -f # Create the pull request gh pr create \ --base ${{ inputs.base_branch }} \ --head $HEAD_BRANCH \ - --assignee ${{ inputs.version }} \ + --assignee ${{ inputs.assignee }} \ --title "Release - ${{ inputs.version }}" \ --label 'type : release' \ --milestone $MILESTONE \ From f95ef0451e6ce711d0c7070c8cfa37a69417d861 Mon Sep 17 00:00:00 2001 From: "Luong Vo (Lucas)" Date: Fri, 24 Nov 2023 10:35:49 +0700 Subject: [PATCH 04/10] Expose label param --- create_release_pr/action.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/create_release_pr/action.yml b/create_release_pr/action.yml index e98674d..76b7647 100644 --- a/create_release_pr/action.yml +++ b/create_release_pr/action.yml @@ -8,13 +8,16 @@ inputs: description: Current release version required: true base_branch: - description: The base branch for the release pull request + description: The base branch for the release pull request, e.g., "main" required: true changelogConfiguration: description: The changelog configuration file path, e.g., ".github/workflows/config/changelog-release.json" required: true assignee: - description: The assignee username, e.g. bot-nimble + description: The assignee username for the Release pull request, e.g. bot-nimble + required: true + label: + description: The label for the Release pull request, e.g. "type : release" required: true runs: @@ -56,7 +59,7 @@ runs: --head $HEAD_BRANCH \ --assignee ${{ inputs.assignee }} \ --title "Release - ${{ inputs.version }}" \ - --label 'type : release' \ + --label ${{ inputs.label }} \ --milestone $MILESTONE \ --body "$MILESTONE_URL From 6c87df5a050f60a47fe9819a7e94e7513f0a501f Mon Sep 17 00:00:00 2001 From: "Luong Vo (Lucas)" Date: Fri, 24 Nov 2023 10:57:40 +0700 Subject: [PATCH 05/10] Set some params as optinal --- create_release_pr/action.yml | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/create_release_pr/action.yml b/create_release_pr/action.yml index 76b7647..04aa4e7 100644 --- a/create_release_pr/action.yml +++ b/create_release_pr/action.yml @@ -1,24 +1,28 @@ name: Automate creating the Release pull request description: Automate creating the Release pull request inputs: - token: - description: The GitHub PAT for this action to use - required: true version: description: Current release version required: true + 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: true + required: false + default: main changelogConfiguration: description: The changelog configuration file path, e.g., ".github/workflows/config/changelog-release.json" required: true assignee: - description: The assignee username for the Release pull request, e.g. bot-nimble - required: true + description: The assignee for the Release pull request, e.g., bot-nimble + required: false + default: 'bot-nimble' label: - description: The label for the Release pull request, e.g. "type : release" - required: true + description: 'The label for the Release pull request, e.g., "type : release"' + required: false + default: 'type : release' runs: using: composite @@ -42,7 +46,7 @@ runs: GH_TOKEN: ${{ inputs.token }} shell: bash run: | - HEAD_BRANCH=release/${{ inputs.version }} + RELEASE_BRANCH=release/${{ inputs.version }} # Fetch milestone info gh extension install valeriobelli/gh-milestone @@ -50,16 +54,16 @@ runs: MILESTONE_URL=$(gh milestone list --query $MILESTONE --json url --jq ".[0].url") # Create the release branch - git checkout -b $HEAD_BRANCH - git push origin $HEAD_BRANCH -f + git checkout -b $RELEASE_BRANCH + git push origin $RELEASE_BRANCH -f # Create the pull request gh pr create \ --base ${{ inputs.base_branch }} \ - --head $HEAD_BRANCH \ + --head $RELEASE_BRANCH \ --assignee ${{ inputs.assignee }} \ --title "Release - ${{ inputs.version }}" \ - --label ${{ inputs.label }} \ + --label "${{ inputs.label }}" \ --milestone $MILESTONE \ --body "$MILESTONE_URL From b5432b374de1fbc4b294f47d256343b84dacf838 Mon Sep 17 00:00:00 2001 From: "Luong Vo (Lucas)" Date: Mon, 27 May 2024 22:32:40 +0700 Subject: [PATCH 06/10] Add sample workflow and config files + README --- README.md | 2 ++ create_release_pr/README.md | 6 ++++ .../sample/workflows/changelog-release.json | 35 +++++++++++++++++++ .../sample/workflows/create_release_pr.yml | 28 +++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 create_release_pr/README.md create mode 100644 create_release_pr/sample/workflows/changelog-release.json create mode 100644 create_release_pr/sample/workflows/create_release_pr.yml diff --git a/README.md b/README.md index 9152b7c..0a82498 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_pr/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_pr/README.md b/create_release_pr/README.md new file mode 100644 index 0000000..d8cb676 --- /dev/null +++ b/create_release_pr/README.md @@ -0,0 +1,6 @@ +# Automate creating the Release pull request + +## Usage + +- Create a `create_release_pr.yml` workflow, sample [here](sample/workflows/create_release_pr.yml). +- Provide a release changelog configuration file, sample [here](sample/workflows/changelog-release.json). diff --git a/create_release_pr/sample/workflows/changelog-release.json b/create_release_pr/sample/workflows/changelog-release.json new file mode 100644 index 0000000..6480db0 --- /dev/null +++ b/create_release_pr/sample/workflows/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_pr/sample/workflows/create_release_pr.yml b/create_release_pr/sample/workflows/create_release_pr.yml new file mode 100644 index 0000000..b41b081 --- /dev/null +++ b/create_release_pr/sample/workflows/create_release_pr.yml @@ -0,0 +1,28 @@ +name: Create the Release pull request + +on: + workflow_dispatch: + +jobs: + create_release_pr: + 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_pr@0.1.10 + with: + version: ${{ steps.version.outputs.version }} + changelogConfiguration: ".github/workflows/config/changelog-release.json" + assignee: bot-nimble From 58a73bac345f5d2e55ed6739ae4f2c8899a477f9 Mon Sep 17 00:00:00 2001 From: "Luong Vo (Lucas)" Date: Mon, 27 May 2024 23:05:48 +0700 Subject: [PATCH 07/10] Rename: pr > pull_request --- README.md | 2 +- create_release_pr/README.md | 6 ------ create_release_pull_request/README.md | 6 ++++++ .../action.yml | 0 .../sample/workflows/config}/changelog-release.json | 0 .../sample/workflows/create_release_pull_request.yml | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) delete mode 100644 create_release_pr/README.md create mode 100644 create_release_pull_request/README.md rename {create_release_pr => create_release_pull_request}/action.yml (100%) rename {create_release_pr/sample/workflows => create_release_pull_request/sample/workflows/config}/changelog-release.json (100%) rename create_release_pr/sample/workflows/create_release_pr.yml => create_release_pull_request/sample/workflows/create_release_pull_request.yml (93%) diff --git a/README.md b/README.md index 0a82498..1623c83 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ ## 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_pr/README.md) +- [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 diff --git a/create_release_pr/README.md b/create_release_pr/README.md deleted file mode 100644 index d8cb676..0000000 --- a/create_release_pr/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# Automate creating the Release pull request - -## Usage - -- Create a `create_release_pr.yml` workflow, sample [here](sample/workflows/create_release_pr.yml). -- Provide a release changelog configuration file, sample [here](sample/workflows/changelog-release.json). 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_pr/action.yml b/create_release_pull_request/action.yml similarity index 100% rename from create_release_pr/action.yml rename to create_release_pull_request/action.yml diff --git a/create_release_pr/sample/workflows/changelog-release.json b/create_release_pull_request/sample/workflows/config/changelog-release.json similarity index 100% rename from create_release_pr/sample/workflows/changelog-release.json rename to create_release_pull_request/sample/workflows/config/changelog-release.json diff --git a/create_release_pr/sample/workflows/create_release_pr.yml b/create_release_pull_request/sample/workflows/create_release_pull_request.yml similarity index 93% rename from create_release_pr/sample/workflows/create_release_pr.yml rename to create_release_pull_request/sample/workflows/create_release_pull_request.yml index b41b081..58244df 100644 --- a/create_release_pr/sample/workflows/create_release_pr.yml +++ b/create_release_pull_request/sample/workflows/create_release_pull_request.yml @@ -4,7 +4,7 @@ on: workflow_dispatch: jobs: - create_release_pr: + create_release_pull_request: name: Create the Release pull request runs-on: ubuntu-latest permissions: @@ -21,7 +21,7 @@ jobs: path: "version.properties" properties: "version" - - uses: nimblehq/github-actions-workflows/create_release_pr@0.1.10 + - uses: nimblehq/github-actions-workflows/create_release_pull_request@0.1.10 with: version: ${{ steps.version.outputs.version }} changelogConfiguration: ".github/workflows/config/changelog-release.json" From 5cd6cc6c63389658f4a68d29b1c7c5169864e128 Mon Sep 17 00:00:00 2001 From: "Luong Vo (Lucas)" Date: Mon, 27 May 2024 23:23:17 +0700 Subject: [PATCH 08/10] Add optional "release_body_url" + fix the fromTag commit finding --- create_release_pull_request/action.yml | 81 +++++++++++++++++--------- 1 file changed, 53 insertions(+), 28 deletions(-) diff --git a/create_release_pull_request/action.yml b/create_release_pull_request/action.yml index 04aa4e7..49978b2 100644 --- a/create_release_pull_request/action.yml +++ b/create_release_pull_request/action.yml @@ -1,10 +1,14 @@ name: Automate creating the Release pull request description: Automate creating the Release pull request inputs: - version: - description: Current release version + release_version: + description: Release version required: true - token: + 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 }} @@ -12,46 +16,69 @@ inputs: description: The base branch for the release pull request, e.g., "main" required: false default: main - changelogConfiguration: - description: The changelog configuration file path, e.g., ".github/workflows/config/changelog-release.json" - required: true assignee: - description: The assignee for the Release pull request, e.g., bot-nimble + description: The assignee for the Release pull request, e.g., bot required: false - default: 'bot-nimble' label: description: 'The label for the Release pull request, e.g., "type : release"' required: false - default: 'type : release' + 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 HEAD commit - id: head + - name: Find the HEAD commit + id: find_head_commit shell: bash run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT - - name: Build changelog - id: changelog + - 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: - configuration: ${{ inputs.changelogConfiguration }} - # Listing PRs from the last tag to the HEAD commit - toTag: ${{ steps.head.outputs.sha }} - token: ${{ inputs.token }} + 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: Create the Release pull request + - name: Find milestone + id: find_milestone env: - GH_TOKEN: ${{ inputs.token }} + GH_TOKEN: ${{ inputs.github_token }} shell: bash run: | - RELEASE_BRANCH=release/${{ inputs.version }} - - # Fetch milestone info gh extension install valeriobelli/gh-milestone - MILESTONE=${{ inputs.version }} + 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 @@ -62,9 +89,7 @@ runs: --base ${{ inputs.base_branch }} \ --head $RELEASE_BRANCH \ --assignee ${{ inputs.assignee }} \ - --title "Release - ${{ inputs.version }}" \ + --title "Release - ${{ inputs.release_version }}" \ --label "${{ inputs.label }}" \ - --milestone $MILESTONE \ - --body "$MILESTONE_URL - - ${{ steps.changelog.outputs.changelog }}" \ + --milestone "${{ steps.find_milestone.outputs.milestone }}" \ + --body-file body_content.txt \ From 2eaa93fb1389ce323a51a652451e30da69af3ff4 Mon Sep 17 00:00:00 2001 From: "Luong Vo (Lucas)" Date: Tue, 28 May 2024 00:35:33 +0700 Subject: [PATCH 09/10] Update sample workflow config --- .../sample/workflows/create_release_pull_request.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index 58244df..4d17376 100644 --- a/create_release_pull_request/sample/workflows/create_release_pull_request.yml +++ b/create_release_pull_request/sample/workflows/create_release_pull_request.yml @@ -23,6 +23,6 @@ jobs: - uses: nimblehq/github-actions-workflows/create_release_pull_request@0.1.10 with: - version: ${{ steps.version.outputs.version }} - changelogConfiguration: ".github/workflows/config/changelog-release.json" + release_version: ${{ steps.version.outputs.version }} + changelog_configuration: ".github/workflows/config/changelog-release.json" assignee: bot-nimble From d2f913f1faba9dd814eb0cab86147d2bab6e0e34 Mon Sep 17 00:00:00 2001 From: "Luong Vo (Lucas)" Date: Tue, 28 May 2024 10:34:21 +0700 Subject: [PATCH 10/10] Add milestone if available, otherwise > skip --- create_release_pull_request/action.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/create_release_pull_request/action.yml b/create_release_pull_request/action.yml index 49978b2..8b0cc42 100644 --- a/create_release_pull_request/action.yml +++ b/create_release_pull_request/action.yml @@ -84,6 +84,13 @@ runs: 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 }} \ @@ -91,5 +98,5 @@ runs: --assignee ${{ inputs.assignee }} \ --title "Release - ${{ inputs.release_version }}" \ --label "${{ inputs.label }}" \ - --milestone "${{ steps.find_milestone.outputs.milestone }}" \ + $MILESTONE_PARAM \ --body-file body_content.txt \