forked from vercel/workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
110 lines (97 loc) · 3.76 KB
/
Copy pathrelease.yml
File metadata and controls
110 lines (97 loc) · 3.76 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
name: Release
on:
push:
branches:
- main
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 10.14.0
- name: Setup Node.js 22.x
uses: actions/setup-node@v4
with:
node-version: 22.x
cache: "pnpm"
- name: Install Dependencies
run: pnpm install --frozen-lockfile
- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
version: pnpm ci:version
publish: pnpm ci:publish
createGithubReleases: false
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_PULL_REQUESTS }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN_ELEVATED }}
- name: Add latest dist-tag to published packages
if: steps.changesets.outputs.published == 'true'
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN_ELEVATED }}
run: |
# Configure npm auth for dist-tag operations
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
# Parse published packages and add latest tag to each
echo '${{ steps.changesets.outputs.publishedPackages }}' | jq -c '.[]' | while read -r pkg; do
NAME=$(echo "$pkg" | jq -r '.name')
VERSION=$(echo "$pkg" | jq -r '.version')
echo "Adding 'latest' dist-tag to ${NAME}@${VERSION}..."
npm dist-tag add "${NAME}@${VERSION}" latest || echo "Failed to add dist-tag for ${NAME}, continuing..."
done
- name: Create GitHub Release
if: steps.changesets.outputs.published == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_PULL_REQUESTS }}
PUBLISHED_PACKAGES: ${{ steps.changesets.outputs.publishedPackages }}
run: |
# Generate release notes (PUBLISHED_PACKAGES filters to only include packages from this release)
RELEASE_JSON=$(node scripts/generate-release-notes.mjs)
TAG=$(echo "$RELEASE_JSON" | jq -r '.tag')
TITLE=$(echo "$RELEASE_JSON" | jq -r '.title')
BODY=$(echo "$RELEASE_JSON" | jq -r '.body')
# Check if a release with this tag already exists
if gh release view "$TAG" &>/dev/null; then
echo "Release $TAG already exists, updating..."
gh release edit "$TAG" \
--title "$TITLE" \
--notes "$BODY" \
--latest \
--prerelease=false
else
echo "Creating new release $TAG..."
gh release create "$TAG" \
--target "${{ github.sha }}" \
--title "$TITLE" \
--notes "$BODY" \
--latest \
--prerelease=false
fi
- name: Post release notes to Slack
if: steps.changesets.outputs.published == 'true'
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_RELEASE_CHANNEL_ID: ${{ secrets.SLACK_RELEASE_CHANNEL_ID }}
PUBLISHED_PACKAGES: ${{ steps.changesets.outputs.publishedPackages }}
run: |
if [ -z "$SLACK_BOT_TOKEN" ] || [ -z "$SLACK_RELEASE_CHANNEL_ID" ]; then
echo "Missing Slack secrets: SLACK_BOT_TOKEN and/or SLACK_RELEASE_CHANNEL_ID"
exit 1
fi
# Post to Slack via chat.postMessage (payload is chunked to Slack limits)
node scripts/generate-release-slack-payload.mjs --post