Repository navigation
147 lines (129 loc) · 4.79 KB
/
Copy pathpublish.yml
File metadata and controls
147 lines (129 loc) · 4.79 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: Publish Package
on:
push:
branches:
- main
- 'v[0-9]*'
permissions: {}
env:
VITE_TEST_WATCHER_DEBUG: 'false'
jobs:
# Keep detection outside the Release environment. Environment approval is job-level,
# so the publish job is only created after a release commit is detected.
detect:
if: github.repository == 'vitest-dev/vitest'
name: Detect release commit
runs-on: ubuntu-slim
outputs:
release: ${{ steps.detect.outputs.release }}
version: ${{ steps.detect.outputs.version }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Detect release
id: detect
run: |
SUBJECT="$(git log -1 --format=%s)"
VERSION="$(jq -r .version package.json)"
EXPECTED="chore: release v$VERSION"
# use prefix match since commit has PR number trailer.
if [[ "$SUBJECT" == "$EXPECTED"* ]]; then
echo "release=true" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Detected release v$VERSION"
else
echo "release=false" >> "$GITHUB_OUTPUT"
echo "No release commit found at HEAD"
fi
publish:
if: needs.detect.outputs.release == 'true'
needs: detect
name: Publish Vitest
runs-on: ubuntu-latest
permissions:
contents: write # trusted publishing and changelog requirement
id-token: write # trusted publishing requirement
environment: Release
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Check release tag
env:
VERSION: ${{ needs.detect.outputs.version }}
run: |
TAG="v$VERSION"
if git rev-parse --verify --quiet "refs/tags/$TAG"; then
echo "Tag $TAG already exists"
exit 1
fi
- name: Install pnpm
uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v4.4.0
- name: Set node version to 24
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
registry-url: https://registry.npmjs.org/
# disable cache to avoid cache poisoning
package-manager-cache: false
- name: Install
run: pnpm install --frozen-lockfile --prefer-offline
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1'
- name: Build
run: pnpm build
- name: Stage publish to npm (dry run)
env:
VERSION: ${{ needs.detect.outputs.version }}
PUBLISH_BRANCH: ${{ github.ref_name }}
PUBLISH_DRY_RUN: 'true'
run: pnpm run publish-ci "$VERSION"
- name: Stage publish to npm
env:
VERSION: ${{ needs.detect.outputs.version }}
PUBLISH_BRANCH: ${{ github.ref_name }}
run: pnpm run publish-ci "$VERSION"
- id: generate-token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
with:
client-id: ${{ secrets.RELEASE_GITHUB_APP_ID }}
private-key: ${{ secrets.RELEASE_GITHUB_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: ${{ github.event.repository.name }}
permission-contents: write
- name: Push release tag
env:
VERSION: ${{ needs.detect.outputs.version }}
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
run: |
TAG="v$VERSION"
git config user.name "vitest-release-bot[bot]"
git config user.email "292707936+vitest-release-bot[bot]@users.noreply.github.com"
git tag "$TAG" "$GITHUB_SHA"
git push "https://x-access-token:$GH_TOKEN@github.com/$GITHUB_REPOSITORY.git" "$TAG"
- name: Generate Changelog
env:
VERSION: ${{ needs.detect.outputs.version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG="v$VERSION"
npx changelogithub --to "$TAG" --name "$TAG"
promote-docs:
if: needs.detect.outputs.release == 'true' && github.ref_name == 'main' && !contains(needs.detect.outputs.version, '-')
needs:
- detect
- publish
name: Promote stable documentation
permissions:
contents: read
uses: ./.github/workflows/promote-docs.yml
with:
target: ${{ github.sha }}
# the values come from the release-bot environment of the called job,
# but it can read only the secrets that the caller passes by name
secrets:
RELEASE_GITHUB_APP_ID: ${{ secrets.RELEASE_GITHUB_APP_ID }}
RELEASE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.RELEASE_GITHUB_APP_PRIVATE_KEY }}