Skip to content
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

211 SIM-OPS-Generate PR from staging to main with changelog #335

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/workflows/release-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Changelog
on:
push:
branches:
- release-*

jobs:
release-notes-pr:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
- name: Extract branch
id: extract_branch
run: echo "branch=${GITHUB_REF#refs/heads/}" >> "$GITHUB_OUTPUT"
env:
GITHUB_REF: ${{ github.ref_name }}

- name: Extract tag from branch name
id: extract_tag
run: echo "tag=${BRANCH#release-}" >> "$GITHUB_OUTPUT"
env:
BRANCH: ${{ steps.extract_branch.outputs.branch }}

- name: Checkout repository
uses: actions/checkout@v4

- name: Get latest release
id: get_latest_release
run: |
latest_release=$(gh release view --json tagName --jq .tagName)
echo $latest_release
echo "tag=$latest_release" >> "$GITHUB_OUTPUT"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Generate release notes
id: generate_release_notes
# https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#generate-release-notes-content-for-a-release
run: |
response=$(curl -L \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if this curl command will fail from some rate-limiting rule? How to handle such errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hasn't failed for me in my tests. I think for now we can go forward by just retrying the action manually if it fails and addressing it in a fix PR. I don't think we should complicate it now :)

-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/yeagerai/genlayer-simulator/releases/generate-notes \
-d '{"tag_name":"${{ steps.extract_tag.outputs.tag }}","target_commitish":"${{ steps.extract_branch.outputs.branch }}","previous_tag_name":"${{ steps.get_latest_release.outputs.tag}}"}' )
echo $response

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First time I see that one, but I've researched a lot about tools to automate this and I didn't find anyone that would satisfy our needs. All of them had little to no flexibility to customize them.

For example, the one you are sharing here only works with "milestones"

Do you know how to use it for this use case?
We need to create release notes when there's a release branch created, and add those notes to a PR body

# Multi line output https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-of-a-multiline-string
{
echo 'notes<<EOF'
echo $response | jq -r -e .body
echo EOF
} >> "$GITHUB_OUTPUT"

- name: Create pull request
id: create_pull_request
run: |
gh pr create --title "Release ${{ steps.extract_tag.outputs.tag }}" --body "${{ steps.generate_release_notes.outputs.notes }}" --base main --head ${{ steps.extract_branch.outputs.branch }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Loading