-
Notifications
You must be signed in to change notification settings - Fork 35
90 lines (76 loc) · 2.65 KB
/
publish-alpha.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: Publish Alpha
permissions:
contents: write
pull-requests: write
on:
workflow_dispatch:
push:
branches:
- main
jobs:
release:
if: contains(github.head_ref || github.ref_name, 'changeset-release') || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 9.7.0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: pnpm install
- name: Build
run: pnpm build
- name: Prepare CLI package for publishing
run: cd packages/cli && rm -rf node_modules && pnpm install --shamefully-hoist --ignore-scripts && cd ../..
- name: Setup npm auth
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
- name: Create and publish alpha release
id: publish
run: |
# Try to publish and capture output
OUTPUT=$(pnpm changeset publish 2>&1)
# Show the output immediately
echo "$OUTPUT"
if [ $? -eq 0 ]; then
echo "✓ Successfully published packages"
else
# Check if it's because no changes were found
if echo "$OUTPUT" | grep -q "No changes to publish"; then
echo "ℹ No changes to publish - this is OK"
exit 0
else
echo "✗ Error occurred during publish"
exit 1
fi
fi
# Store output for next steps
echo "OUTPUT<<EOF" >> $GITHUB_OUTPUT
echo "$OUTPUT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Force latest tag for all published packages
run: |
echo "${{ steps.publish.outputs.OUTPUT }}" | grep -E "New tag:" | while read -r line ; do
if [[ $line =~ New[[:space:]]+tag:[[:space:]]{2}([^@]+)@([^[:space:]]+) ]]; then
PKG_NAME="${BASH_REMATCH[1]}"
PKG_VERSION="${BASH_REMATCH[2]}"
echo "Setting latest tag for $PKG_NAME@$PKG_VERSION"
npm dist-tag add "${PKG_NAME}@${PKG_VERSION}" latest
fi
done
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}