diff --git a/.github/workflows/release-pr.yml b/.github/workflows/release-pr.yml new file mode 100644 index 000000000..6c78044b8 --- /dev/null +++ b/.github/workflows/release-pr.yml @@ -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 \ + -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 + + # Multi line output https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-of-a-multiline-string + { + echo 'notes<> "$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 }}