generated from nimblehq/git-template
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Add "Create Release PR" composite action #7
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c5e2980
Add "Create Release PR" composite action
luongvo 592c081
Expose token & changelogConfigurationJson params
luongvo 04ad8e6
Fix assignee user param usage & allow force pushing the release branch
luongvo f95ef04
Expose label param
luongvo 6c87df5
Set some params as optinal
luongvo b5432b3
Add sample workflow and config files + README
luongvo 58a73ba
Rename: pr > pull_request
luongvo 5cd6cc6
Add optional "release_body_url" + fix the fromTag commit finding
luongvo 2eaa93f
Update sample workflow config
luongvo d2f913f
Add milestone if available, otherwise > skip
luongvo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 \ |
35 changes: 35 additions & 0 deletions
35
create_release_pull_request/sample/workflows/config/changelog-release.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
28 changes: 28 additions & 0 deletions
28
create_release_pull_request/sample/workflows/create_release_pull_request.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/[email protected] | ||
with: | ||
path: "version.properties" | ||
properties: "version" | ||
|
||
- uses: nimblehq/github-actions-workflows/[email protected] | ||
with: | ||
release_version: ${{ steps.version.outputs.version }} | ||
changelog_configuration: ".github/workflows/config/changelog-release.json" | ||
assignee: bot-nimble |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: if
milestone_url
is found, that means the milestone from the release version is available from the repo.