diff --git a/.github/workflows/auto-tag.yml b/.github/workflows/auto-tag.yml new file mode 100644 index 00000000..dd43662d --- /dev/null +++ b/.github/workflows/auto-tag.yml @@ -0,0 +1,59 @@ +name: Auto Tag & Sync + +on: + pull_request: + types: [closed] + branches: [main] + +permissions: + contents: write + +jobs: + tag-and-sync: + if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/') + runs-on: ubuntu-latest + + steps: + - name: Checkout main + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.GH_TOKEN }} + + - name: Setup pnpm + uses: pnpm/action-setup@v4 + + - name: Read version from package.json + id: version + run: | + VERSION=$(node -p "require('./package.json').version") + echo "version=${VERSION}" >> "$GITHUB_OUTPUT" + echo "tag=v${VERSION}" >> "$GITHUB_OUTPUT" + + - name: Check tag doesn't already exist + id: check + env: + TAG_VERSION: ${{ steps.version.outputs.version }} + run: | + if git rev-parse "v${TAG_VERSION}" >/dev/null 2>&1; then + echo "exists=true" >> "$GITHUB_OUTPUT" + else + echo "exists=false" >> "$GITHUB_OUTPUT" + fi + + - name: Create and push tag + if: steps.check.outputs.exists == 'false' + env: + TAG_NAME: ${{ steps.version.outputs.tag }} + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git tag -a "${TAG_NAME}" -m "Release ${TAG_NAME}" + git push origin "${TAG_NAME}" + + - name: Merge main → develop + run: | + git fetch origin develop + git checkout develop + git merge main --no-edit + git push origin develop