-
Notifications
You must be signed in to change notification settings - Fork 1
122 lines (101 loc) · 3.38 KB
/
Copy pathci-cd.yml
File metadata and controls
122 lines (101 loc) · 3.38 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
name: CI/CD
on:
push:
branches:
- main
- '*prerelease*'
permissions:
contents: read
id-token: write
pages: write
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- run: npm ci
- run: npm run build
- run: npm test
publish:
needs: build-and-test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || contains(github.ref, 'prerelease')
environment: production
permissions:
contents: write
id-token: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: actions/setup-node@v4
with:
node-version: '24'
- run: npm ci
- run: npm run build
- name: Check if version has changed
id: version-check
run: |
CURRENT=$(node -p "require('./package.json').version")
PACKAGE_NAME=$(node -p "require('./package.json').name")
PUBLISHED=$(npm view "$PACKAGE_NAME" version 2>/dev/null || echo "")
echo "current=$CURRENT" >> "$GITHUB_OUTPUT"
echo "previous=$PUBLISHED" >> "$GITHUB_OUTPUT"
if [ "$CURRENT" != "$PREVIOUS" ]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
fi
- name: Publish to npm
if: steps.version-check.outputs.changed == 'true'
run: npm publish --provenance --access public
- name: Write step summary (no publish)
if: steps.version-check.outputs.changed == 'false'
run: |
echo "## ℹ️ No npm package published" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "The version in \`package.json\` (\`${{ steps.version-check.outputs.current }}\`) was not incremented since the previous commit. No package was published to npm." >> "$GITHUB_STEP_SUMMARY"
echo "If you intended to publish a new version, please bump the version number." >> "$GITHUB_STEP_SUMMARY"
- name: Post commit comment (no publish)
if: steps.version-check.outputs.changed == 'false'
uses: actions/github-script@v7
with:
script: |
await github.rest.repos.createCommitComment({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: context.sha,
body: 'ℹ️ **No npm package published** — the version in `package.json` was not incremented. If you intended to publish a new version, please bump the version number.'
});
deploy-storybook:
needs: build-and-test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: storybook
cancel-in-progress: false
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- run: npm ci
- run: npm run build-storybook
- uses: actions/upload-pages-artifact@v3
with:
path: ./storybook-static
- uses: actions/deploy-pages@v4
id: deployment