-
Notifications
You must be signed in to change notification settings - Fork 2
153 lines (126 loc) · 3.9 KB
/
main.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
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
148
149
150
151
152
153
name: Build, Test for Main
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, labeled]
jobs:
build:
name: Build
strategy:
matrix:
os:
- ubuntu-latest
- macOS-latest
runs-on: ${{ matrix.os }}
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: pnpm/action-setup@v4
with:
package_json_file: package.json
run_install: false
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: "pnpm"
- name: Install dependencies
run: pnpm install
- name: Build
run: pnpm build
- name: Test
run: pnpm test
- name: Types
run: pnpm types
publish:
name: Publish to NPM or Create Version PR
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Generate a token
uses: actions/create-github-app-token@v1
id: generate-token
with:
# uses https://github.com/organizations/tinacms/settings/apps/release-bot-allow-prs-and-push
app-id: ${{ secrets.BOT_APP_ID }}
private-key: ${{ secrets.BOT_APP_SECRET }}
- uses: actions/checkout@v4
with:
token: ${{ steps.generate-token.outputs.token || secrets.GITHUB_TOKEN }}
fetch-depth: 0
- uses: pnpm/action-setup@v4
with:
package_json_file: package.json
run_install: false
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: "pnpm"
registry-url: https://registry.npmjs.org
- name: Install dependencies
run: pnpm install
- name: Build
run: pnpm build
- name: Types
run: pnpm types
- name: Create Release Pull Request
id: changesets
uses: changesets/action@v1
with:
version: pnpm run version
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token || secrets.GITHUB_TOKEN }}
- name: Set snapshot version
if: steps.changesets.outputs.hasChangesets == 'true'
run: |
timestamp=$(date +'%Y%m%d%H%M%S')
jq --arg version "0.0.0-$timestamp" '.version = $version' package.json > package.tmp.json
mv package.tmp.json package.json
- uses: JS-DevTools/npm-publish@v3
name: Publish to NPM
with:
access: public
tag: ${{ steps.changesets.outputs.hasChangesets == 'true' && 'beta' || 'latest' }}
token: ${{ secrets.NPM_AUTH_TOKEN }}
publish-pr:
name: Publish PR preview
needs: build
if: >
github.event_name == 'pull_request' &&
contains(github.event.pull_request.labels.*.name, 'tagged')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
package_json_file: package.json
run_install: false
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: "pnpm"
registry-url: https://registry.npmjs.org
- name: Install dependencies
run: pnpm install
- name: Build
run: pnpm build
- name: Types
run: pnpm types
- name: Set snapshot version
run: |
timestamp=$(date +'%Y%m%d%H%M%S')
jq --arg version "0.0.0-$timestamp" '.version = $version' package.json > package.tmp.json
mv package.tmp.json package.json
- uses: JS-DevTools/npm-publish@v3
name: Publish to NPM
with:
access: public
tag: ${{ github.head_ref || github.ref_name }}
token: ${{ secrets.NPM_AUTH_TOKEN }}