Skip to content

chore: fix workflow bugs #99

chore: fix workflow bugs

chore: fix workflow bugs #99

Workflow file for this run

name: Publish latest release
##
# This workflow creates a latest release with the same target_commitish
# as the highest rc matching the release PR version
#
# It should also update the release PR description
# It should also attach the highest rc asset to the latest release
#
on:
pull_request:
branches:
- main
types:
- closed
jobs:
publish-latest:
if: ${{ github.event.pull_request.merged == true && startsWith(github.head_ref, 'release/')}}
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
env:
GH_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@v4
- id: create-latest-release
name: Create latest release
env:
SOURCE_BRANCH: ${{ github.head_ref }}
run: |
# find the target commitish of the latest release matching our tag
TAG=$(echo $SOURCE_BRANCH | sed 's/release\/\(.*\)/\1/')
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/{owner}/{repo}/releases > releases.json
TARGET_COMMITISH=$(cat releases.json | jq '.[] | select(.tag_name | match("$TAG")) | .target_commitish' | head -1)
# publish the latest release
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/{owner}/{repo}/releases \
-f tag_name="$TAG" \
-f target_commitish="$TARGET_COMMITISH" \
-f name="$TAG" \
-F generate_release_notes=true > release.json
# TODO attach the rc asset to latest release
# save output for upload
# echo "FILENAME=xverse-web-extension.$TAG.zip" >> $GITHUB_OUTPUT
# echo "UPLOAD_URL=$(cat release.json | jq -r .upload_url)" >> $GITHUB_OUTPUT
- id: update-description
name: Update PR description with release notes
env:
PR_ID: ${{ github.event.pull_request.number }}
run: |
# update PR description
cat release.json | jq -r .body > body.md
echo -e "\n\nPublished latest release: $(cat release.json | jq -r .html_url)" >> body.md
gh api \
--method PATCH \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/{owner}/{repo}/pulls/$PR_ID \
-F 'body=@body.md'