fix: typo #5
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
name: Create release branch PR | |
on: | |
push: | |
branches: | |
- main | |
# pull_request: | |
# types: [closed] | |
# branches: | |
# - main | |
jobs: | |
create-release-pr: | |
# if: github.event.pull_request.merged == true | |
runs-on: ubuntu-latest | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: fetch latest release tag | |
id: latest_release_tag | |
run: | | |
pre_tag=$(curl -H 'Accept: application/vnd.github.v3+json' -H 'Authorization: token ${{ secrets.GITHUB_TOKEN }}' https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name) | |
if [ "$pre_tag" = "null" ]; then | |
pre_tag="0" | |
fi | |
echo "pre_tag=$pre_tag" >> $GITHUB_OUTPUT | |
- name: fetch list of merged PRs since latest release | |
id: merged_prs | |
run: | | |
latest_tag=${{ steps.latest_release_tag.outputs.latest_tag }} | |
merged_prs=$(gh pr list --state merged --base main --json title,number,headRefName,mergedAt --jq ".[] | select(.mergedAt > \"$latest_tag\") | {title: .title, number: .number, headRefName: .headRefName}") | |
echo "$merged_prs" | |
echo "::set-output name=merged_prs::$merged_prs" | |
- name: Create PR to release branch | |
run: | | |
PR_EXISTS=$(gh pr list --head main --base release --state open --json number --jq '.[].number') | |
pr_body="The following PRs were merged since the last release:\n" | |
for pr in $(echo "${{ steps.merged_prs.outputs.merged_prs }}" | jq -r '.[] | @base64'); do | |
_jq() { | |
echo ${pr} | base64 --decode | jq -r ${1} | |
} | |
pr_title=$(_jq '.title') | |
pr_number=$(_jq '.number') | |
pr_body+="\n- $pr_title (#$pr_number)" | |
done | |
if [ -z "$PR_EXISTS" ]; then | |
gh pr create --title "Merge main into release" --body "$pr_body" --base release --head main | |
else | |
existing_pr_body=$(gh pr view $PR_EXISTS --json body --jq '.body') | |
new_pr_body="${existing_pr_body}\n${pr_body}" | |
gh pr edit $PR_EXISTS --body "$new_pr_body" | |
gh pr comment $PR_EXISTS --body "Additional PRs merged:\n${pr_body}" | |
fi |