Skip to content

Version or Publish

Version or Publish #18

name: Version or Publish
on:
workflow_run:
workflows: ["Builds, tests & co"]
types: [completed]
concurrency: ${{ github.workflow }}
permissions: read-all
jobs:
release:
if: ${{ github.repository_owner == 'js2me' && github.event.workflow_run.conclusion == 'success' }}
permissions:
contents: write # to create release
id-token: write # to generate provenance
issues: write # to post issue comments
pull-requests: write # to create pull request
runs-on: ubuntu-latest
steps:
- name: Checkout tree
uses: actions/checkout@v4
- name: Set-up Node.js
uses: actions/setup-node@v4
with:
check-latest: true
node-version-file: .nvmrc
- run: corepack enable
- run: pnpm i
- name: Get latest tag before changeset
id: before-tag
continue-on-error: false
run: |
git fetch --tags
tag=$(git for-each-ref --sort=-creatordate --format '%(refname:short)' refs/tags | head -n 1)
if [ -z "$tag" ]; then
echo "last_tag=" >> $GITHUB_OUTPUT
else
echo "last_tag=$tag" >> $GITHUB_OUTPUT
fi
- name: Create Release Pull Request
uses: changesets/action@v1
continue-on-error: false
with:
version: pnpm changeset version
publish: pnpm pub-ci
env:
GITHUB_TOKEN: ${{ github.token }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Get latest tag after changeset
id: after-tag
continue-on-error: false
run: |
git fetch --tags
tag=$(git for-each-ref --sort=-creatordate --format '%(refname:short)' refs/tags | head -n 1)
if [ -z "$tag" ]; then
echo "new_tag=$last_tag" >> $GITHUB_OUTPUT
else
echo "new_tag=$tag" >> $GITHUB_OUTPUT
fi
- name: Convert version to anchor format
id: version_anchor
run: |
clean_version="${VERSION#v}"
anchor_version="${clean_version//./}"
echo "anchor_version=$anchor_version" >> $GITHUB_OUTPUT
env:
VERSION: ${{ steps.after-tag.outputs.new_tag }}
- name: Create GitHub Release
if: steps.before-tag.outputs.last_tag != steps.after-tag.outputs.new_tag
continue-on-error: false
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
tag_name: ${{ steps.after-tag.outputs.new_tag }}
release_name: ${{ steps.after-tag.outputs.new_tag }}
body: |
## [Changelog for release notes](https://github.com/js2me/mobx-tanstack-query/blob/master/CHANGELOG.md#${{ steps.version_anchor.outputs.anchor_version }})
Changes: https://github.com/${{ github.repository }}/compare/${{ steps.before-tag.outputs.last_tag }}...${{ steps.after-tag.outputs.new_tag }}
draft: false
prerelease: false