Skip to content

Merge pull request #18 from reoring/feat/workflow-agent #8

Merge pull request #18 from reoring/feat/workflow-agent

Merge pull request #18 from reoring/feat/workflow-agent #8

Workflow file for this run

name: auto-release
on:
push:
branches:
- main
- master
paths:
- package.json
permissions:
contents: write
actions: write
concurrency:
group: auto-release-${{ github.ref }}
cancel-in-progress: false
jobs:
tag:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Resolve tag from package.json
id: meta
shell: bash
run: |
VERSION=$(node -e "const fs=require('node:fs'); const p=JSON.parse(fs.readFileSync('package.json','utf8')); process.stdout.write(String(p.version||''));")
if [[ -z "$VERSION" ]]; then
echo "package.json version is empty" >&2
exit 1
fi
TAG="v${VERSION}"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
- name: Create and push tag (if missing)
id: tagger
shell: bash
env:
TAG: ${{ steps.meta.outputs.tag }}
run: |
CREATED=0
if git ls-remote --tags origin "refs/tags/${TAG}" | grep -q "refs/tags/${TAG}$"; then
echo "Tag already exists: ${TAG}"
else
GIT_AUTHOR_NAME="github-actions[bot]" \
GIT_AUTHOR_EMAIL="41898282+github-actions[bot]@users.noreply.github.com" \
GIT_COMMITTER_NAME="github-actions[bot]" \
GIT_COMMITTER_EMAIL="41898282+github-actions[bot]@users.noreply.github.com" \
git tag -a "${TAG}" -m "Release ${TAG}"
git push origin "${TAG}"
CREATED=1
fi
echo "created=${CREATED}" >> "$GITHUB_OUTPUT"
- name: Dispatch release workflow
if: steps.tagger.outputs.created == '1'
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ steps.meta.outputs.tag }}
run: |
gh workflow run release --field tag="$TAG"