-
-
Notifications
You must be signed in to change notification settings - Fork 2
186 lines (173 loc) · 6 KB
/
js.yml
File metadata and controls
186 lines (173 loc) · 6 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
name: js
on:
push:
branches: main
paths:
- 'js/**'
- '.github/workflows/js.yml'
pull_request:
paths:
- 'js/**'
- '.github/workflows/js.yml'
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
defaults:
run:
working-directory: js
jobs:
findChangedJsFiles:
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
isJsFilesChanged: ${{ steps.setIsJsFilesChangedOutput.outputs.isJsFilesChanged }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Get changed files using defaults
id: changed-files
uses: tj-actions/changed-files@v47
- name: Set output isJsFilesChanged
id: setIsJsFilesChangedOutput
run: |
isJsFilesChanged='false'
echo "Changed files: ${{ steps.changed-files.outputs.all_changed_files }}"
for changedFile in ${{ steps.changed-files.outputs.all_changed_files }}; do
if [[ $changedFile == js/*.js ]] || [[ $changedFile == js/*.json ]] || [[ $changedFile == js/*.pegjs ]] || [[ $changedFile == js/* ]] || [[ $changedFile == .github/workflows/js.yml ]]; then
echo "isJsFilesChanged='true'"
isJsFilesChanged='true'
break
fi
done
echo "isJsFilesChanged=${isJsFilesChanged}" >> $GITHUB_OUTPUT
echo "isJsFilesChanged: ${isJsFilesChanged}"
format:
needs: [findChangedJsFiles]
if: ${{ needs.findChangedJsFiles.outputs.isJsFilesChanged == 'true' }}
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v6
with:
submodules: true
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Check formatting with Prettier
run: npx prettier --check .
lint:
needs: [findChangedJsFiles, format]
if: ${{ needs.findChangedJsFiles.outputs.isJsFilesChanged == 'true' }}
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v6
with:
submodules: true
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install Dependencies
run: bun install
- name: Lint
run: bun run lint
test:
needs: [findChangedJsFiles, format, lint]
if: ${{ needs.findChangedJsFiles.outputs.isJsFilesChanged == 'true' }}
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v6
with:
submodules: true
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install Dependencies
run: bun install
- name: Build
run: bun run build
- name: Test
run: bun test
publishToNpm:
needs: [test, findChangedJsFiles]
if: ${{ needs.findChangedJsFiles.outputs.isJsFilesChanged == 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v6
with:
submodules: true
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install Dependencies
run: bun install
- name: Build
run: bun run build
- name: Check if version already published
id: version-check
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
PACKAGE_NAME=$(node -p "require('./package.json').name")
echo "Package: $PACKAGE_NAME@$PACKAGE_VERSION"
# Check if version exists on NPM
if npm view $PACKAGE_NAME@$PACKAGE_VERSION version 2>/dev/null; then
echo "Version $PACKAGE_VERSION already exists on NPM"
echo "should_publish=false" >> $GITHUB_OUTPUT
else
echo "Version $PACKAGE_VERSION does not exist on NPM"
echo "should_publish=true" >> $GITHUB_OUTPUT
fi
- name: Publish to NPM
if: steps.version-check.outputs.should_publish == 'true'
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
npm publish --access public
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
publishRelease:
runs-on: ubuntu-latest
timeout-minutes: 10
needs: [publishToNpm]
if: ${{ needs.findChangedJsFiles.outputs.isJsFilesChanged == 'true' && needs.publishToNpm.result == 'success' && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
steps:
- uses: actions/checkout@v6
with:
submodules: true
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Check if GitHub release already exists
id: release-check
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
TAG_NAME="js_$PACKAGE_VERSION"
echo "Checking if release $TAG_NAME already exists"
# Check if release exists
if gh release view "$TAG_NAME" >/dev/null 2>&1; then
echo "Release $TAG_NAME already exists"
echo "should_create_release=false" >> $GITHUB_OUTPUT
else
echo "Release $TAG_NAME does not exist"
echo "should_create_release=true" >> $GITHUB_OUTPUT
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create GitHub release
if: steps.release-check.outputs.should_create_release == 'true'
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
PACKAGE_NAME=$(node -p "require('./package.json').name")
# Create release with consistent tag format: js_version
gh release create "js_${PACKAGE_VERSION}" \
--title "[JS] $PACKAGE_VERSION" \
--notes "https://www.npmjs.com/package/$PACKAGE_NAME"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}