Skip to content

Commit e79176a

Browse files
authored
ci: align publishing to router with main/-pre/-maint (#10283)
1 parent b6fd86b commit e79176a

File tree

3 files changed

+331
-41
lines changed

3 files changed

+331
-41
lines changed

.github/workflows/autofix.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: autofix.ci # needed to securely identify the workflow
33
on:
44
pull_request:
55
push:
6-
branches: [main, alpha, beta, rc, v4]
6+
branches: [main, 'v[0-9]', '*-pre', '*-maint']
77

88
concurrency:
99
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}

.github/workflows/release.yml

Lines changed: 58 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ name: Release
22

33
on:
44
push:
5-
branches: [main, alpha, beta, rc, v4]
6-
repository_dispatch:
7-
types: [release]
5+
branches: [main, 'v[0-9]', '*-pre', '*-maint']
86

97
concurrency:
10-
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
11-
cancel-in-progress: true
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: false
1210

1311
env:
1412
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
@@ -21,52 +19,72 @@ permissions:
2119
jobs:
2220
release:
2321
name: Release
24-
if: github.repository_owner == 'TanStack'
22+
if: "!contains(github.event.head_commit.message, 'ci: changeset release')"
2523
runs-on: ubuntu-latest
2624
steps:
2725
- name: Checkout
2826
uses: actions/checkout@v6.0.2
2927
with:
3028
fetch-depth: 0
29+
- name: Check for changesets
30+
id: changesets
31+
run: |
32+
CHANGESET_FILES=$(ls .changeset/*.md 2>/dev/null | grep -v README.md || true)
33+
if [ -z "$CHANGESET_FILES" ]; then
34+
echo "has_changesets=false" >> "$GITHUB_OUTPUT"
35+
else
36+
echo "has_changesets=true" >> "$GITHUB_OUTPUT"
37+
fi
3138
- name: Start Nx Agents
39+
if: steps.changesets.outputs.has_changesets == 'true'
3240
run: npx nx-cloud start-ci-run --distribute-on=".nx/workflows/dynamic-changesets.yaml"
3341
- name: Setup Tools
3442
uses: TanStack/config/.github/setup@main
3543
- name: Run Tests
44+
if: steps.changesets.outputs.has_changesets == 'true'
3645
run: pnpm run test:ci
3746
- name: Stop Nx Agents
38-
if: ${{ always() }}
47+
if: ${{ always() && steps.changesets.outputs.has_changesets == 'true' }}
3948
run: npx nx-cloud stop-all-agents
40-
# - name: Check for Changesets marked as major
41-
# id: major
42-
# run: |
43-
# echo "found=false" >> $GITHUB_OUTPUT
44-
# regex="(major)"
45-
# shopt -s nullglob
46-
# for file in .changeset/*.md; do
47-
# if [[ $(cat $file) =~ $regex ]]; then
48-
# echo "found=true" >> $GITHUB_OUTPUT
49-
# fi
50-
# done
51-
- name: Run Changesets (version or publish)
52-
id: changesets
53-
uses: changesets/action@v1.7.0
54-
with:
55-
version: pnpm run changeset:version
56-
publish: pnpm run changeset:publish
57-
commit: 'ci: Version Packages'
58-
title: 'ci: Version Packages'
59-
# - name: Auto-merge Changesets PR
60-
# if: steps.changesets.outputs.hasChangesets == 'true' && steps.major.outputs.found == 'false'
61-
# run: |
62-
# gh pr merge --squash "$PR_NUMBER"
63-
# gh api --method POST /repos/$REPO/dispatches -f 'event_type=release'
64-
# env:
65-
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66-
# REPO: ${{ github.repository }}
67-
# PR_NUMBER: ${{ steps.changesets.outputs.pullRequestNumber }}
68-
- name: Comment on PRs about release
69-
if: steps.changesets.outputs.published == 'true'
70-
uses: TanStack/config/.github/comment-on-release@main
71-
with:
72-
published-packages: ${{ steps.changesets.outputs.publishedPackages }}
49+
- name: Enter Pre-Release Mode
50+
if: "contains(github.ref_name, '-pre') && !hashFiles('.changeset/pre.json')"
51+
run: pnpm changeset pre enter pre
52+
- name: Version Packages
53+
run: pnpm run changeset:version
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
- name: Commit and Push Version Changes
57+
id: commit
58+
run: |
59+
git config user.name "github-actions[bot]"
60+
git config user.email "github-actions[bot]@users.noreply.github.com"
61+
git add .
62+
if git commit -m "ci: changeset release"; then
63+
git push
64+
echo "committed=true" >> "$GITHUB_OUTPUT"
65+
fi
66+
env:
67+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68+
- name: Determine dist-tag
69+
if: steps.commit.outputs.committed == 'true'
70+
id: dist-tag
71+
run: |
72+
BRANCH="${GITHUB_REF_NAME}"
73+
if [[ "$BRANCH" == *-pre ]]; then
74+
echo "prerelease=true" >> "$GITHUB_OUTPUT"
75+
elif [[ "$BRANCH" == *-maint ]]; then
76+
echo "tag=maint" >> "$GITHUB_OUTPUT"
77+
elif [[ "$BRANCH" =~ ^v[0-9]+$ ]]; then
78+
echo "tag=$BRANCH" >> "$GITHUB_OUTPUT"
79+
else
80+
echo "latest=true" >> "$GITHUB_OUTPUT"
81+
fi
82+
- name: Publish Packages
83+
if: steps.commit.outputs.committed == 'true'
84+
run: pnpm run changeset:publish ${{ steps.dist-tag.outputs.tag && format('--tag {0}', steps.dist-tag.outputs.tag) }}
85+
- name: Create GitHub Release
86+
if: steps.commit.outputs.committed == 'true'
87+
run: node scripts/create-github-release.mjs ${{ steps.dist-tag.outputs.prerelease == 'true' && '--prerelease' }} ${{ steps.dist-tag.outputs.latest == 'true' && '--latest' }}
88+
env:
89+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
90+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)