-
Notifications
You must be signed in to change notification settings - Fork 4
73 lines (58 loc) · 1.79 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
name: CI Workflow
on:
release:
types: [published]
push:
branches:
- main
- fix/ci-errors
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Install pnpm
run: npm install -g pnpm
- name: Install dependencies
run: pnpm install
- name: Build project
run: pnpm build
- name: Verify dist folder exists
run: |
if [ ! -d "dist" ]; then
echo "Error: dist folder not found!"
exit 1
fi
publish:
runs-on: ubuntu-latest
needs: build # This ensures publish runs only after build succeeds
steps:
- name: Set up Node.js for npm publishing
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/
- name: Install dependencies
run: npm ci
- name: Pre-upload validation
id: pack
run: |
npm pack --dry-run >> output 2>&1
echo PRE_UPLOAD_HASH=$(cat output | grep shasum | cut -f4 -d" ") >> $GITHUB_OUTPUT
- name: Publish package
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Post-upload validation
id: unpack
run: |
PACKAGE_NAME=$(cat package.json | jq .name | cut -f2 -d"\"")@$(cat package.json | jq .version | cut -f2 -d"\"")
echo POST_UPLOAD_HASH=$(npm view $PACKAGE_NAME | grep shasum | cut -f4 -d" ") >> $GITHUB_OUTPUT
- name: Pre and post upload validation
if: steps.pack.outputs.PRE_UPLOAD_HASH != steps.unpack.outputs.POST_UPLOAD_HASH
run: exit 1