-
Notifications
You must be signed in to change notification settings - Fork 23
298 lines (247 loc) · 9.84 KB
/
Copy pathpublish.yml
File metadata and controls
298 lines (247 loc) · 9.84 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
name: Publish packages
on:
push:
tags:
- 'v*'
jobs:
linters:
name: Linting checks
runs-on: ubuntu-24.04
steps:
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20.x
- name: Get node version
id: node
run: |
echo "::set-output name=version::$(node -v)"
- name: Get node_modules cache
uses: actions/cache@v4
id: node_modules
with:
path: |
**/node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/package.lock') }}-${{ steps.node.outputs.version }}
- name: Install dependencies
run: npm install
- name: Run linters
run: npm run lint
# tests:
# name: Test checks
# runs-on: ubuntu-22.04
# steps:
# - name: Check out code
# uses: actions/checkout@v3
# with:
# fetch-depth: 2
# - name: Use Node.js 20.x
# uses: actions/setup-node@v3
# with:
# node-version: 20.x
# - name: Get node version
# id: node
# run: |
# echo "::set-output name=version::$(node -v)"
# - name: Get node_modules cache
# uses: actions/cache@v4
# id: node_modules
# with:
# path: |
# **/node_modules
# key: ${{ runner.os }}-node_modules-${{ hashFiles('**/package.lock') }}-${{ steps.node.outputs.version }}
# - name: Install dependencies
# run: npm ci
# - name: Install playwright browsers
# run: |
# sudo apt update
# npx playwright install --with-deps
# - name: Build
# run: npm run build
# - name: Run tests
# run: npm run test
bump-monorepo:
name: Bump monorepo
runs-on: ubuntu-latest
needs:
- linters
steps:
- uses: actions/checkout@v3
- name: Set env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Remove 'v' from RELEASE_VERSION
run: |
echo "Original RELEASE_VERSION: $RELEASE_VERSION"
RELEASE_VERSION=$(echo "$RELEASE_VERSION" | sed 's/^v//')
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
shell: bash
- name: Install SSH Client
uses: webfactory/ssh-agent@v0.7.0
with:
ssh-private-key: ${{ secrets.DEPLOY_KEY }}
- name: Checkout
uses: actions/checkout@v3
with:
ref: main
- name: Git user config
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x
- name: Install dependencies
run: npm ci
- name: Update root package version
run: npm version $RELEASE_VERSION --no-git-tag-version
- name: Update all package versions
run: |
# Custom ignore list (includes eslint-config which we don't want to bump)
IGNORE_PACKAGES="ecc-docs,@elixir-cloud/ro-crate,@elixir-cloud/tes,@elixir-cloud/eslint-config"
echo "Ignore list: $IGNORE_PACKAGES"
# Find all package.json files and update versions, excluding all node_modules directories
find . -name "package.json" \
-not -path "*/node_modules/*" \
-not -path "./.git/*" \
-not -path "./.changeset/*" \
-not -path "./.github/*" \
-not -path "./.husky/*" \
-not -path "./.turbo/*" | while read package_file; do
if [ "$package_file" != "./package.json" ]; then
# Extract package name from package.json
PACKAGE_NAME=$(node -e "
try {
const pkg = require('$package_file');
console.log(pkg.name || '');
} catch(e) {
console.log('');
}
")
# Check if package should be ignored
if [ -n "$PACKAGE_NAME" ]; then
SHOULD_IGNORE=$(echo "$IGNORE_PACKAGES" | grep -q "$PACKAGE_NAME" && echo "true" || echo "false")
if [ "$SHOULD_IGNORE" = "false" ]; then
echo "Updating $PACKAGE_NAME in $package_file to version $RELEASE_VERSION"
# Update version in package.json
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('$package_file', 'utf8'));
if (!pkg.private) {
pkg.version = '$RELEASE_VERSION';
fs.writeFileSync('$package_file', JSON.stringify(pkg, null, 2) + '\n');
}
"
else
echo "Skipping $PACKAGE_NAME (in ignore list)"
fi
fi
fi
done
- name: ReInstall Dependencies
run: |
npm install
- name: Commit version
run: |
git add .
git commit -m "bump: v$RELEASE_VERSION"
- name: Push changes
uses: ad-m/github-push-action@master
with:
force-with-lease: true
ssh: true
branch: main
publish:
name: Publish on npm
runs-on: ubuntu-latest
needs: bump-monorepo
steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
ref: main
- name: Set env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Remove 'v' from RELEASE_VERSION
run: |
echo "Original RELEASE_VERSION: $RELEASE_VERSION"
RELEASE_VERSION=$(echo "$RELEASE_VERSION" | sed 's/^v//')
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
shell: bash
- name: Setup Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20.x
- name: Login to npm
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
- name: Install Dependencies
run: npm ci
- name: Update internal dependencies
run: |
# Custom ignore list (includes eslint-config which we don't want to update dependencies for)
IGNORE_PACKAGES="ecc-docs,@elixir-cloud/ro-crate,@elixir-cloud/tes,@elixir-cloud/eslint-config"
echo "Ignore list: $IGNORE_PACKAGES"
echo "Updating internal @elixir-cloud dependencies to version $RELEASE_VERSION"
# Only process package.json files in workspace directories (apps/* and packages/*)
for workspace_dir in apps packages; do
if [ -d "$workspace_dir" ]; then
find "$workspace_dir" -maxdepth 2 -name "package.json" -not -path "*/node_modules/*" | while read package_file; do
# Extract package name from package.json
PACKAGE_NAME=$(node -e "
try {
const pkg = require('./$package_file');
console.log(pkg.name || '');
} catch(e) {
console.log('');
}
")
# Check if package should be processed (not in ignore list and starts with @elixir-cloud)
if [ -n "$PACKAGE_NAME" ]; then
SHOULD_IGNORE=$(echo "$IGNORE_PACKAGES" | grep -q "$PACKAGE_NAME" && echo "true" || echo "false")
IS_ELIXIR_CLOUD=$(echo "$PACKAGE_NAME" | grep -q "^@elixir-cloud/" && echo "true" || echo "false")
if [ "$SHOULD_IGNORE" = "false" ] && [ "$IS_ELIXIR_CLOUD" = "true" ]; then
echo "Updating internal dependencies in $PACKAGE_NAME ($package_file)"
# Update dependencies, devDependencies, and peerDependencies
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('./$package_file', 'utf8'));
let updated = false;
// Function to update dependencies in a section
const updateDepsSection = (section, sectionName) => {
if (pkg[section]) {
Object.keys(pkg[section]).forEach(depName => {
if (depName.startsWith('@elixir-cloud/')) {
// Check if this dependency is not in ignore list
const ignoreList = '$IGNORE_PACKAGES'.split(',');
const shouldIgnoreDep = ignoreList.includes(depName);
if (!shouldIgnoreDep && pkg[section][depName] !== '$RELEASE_VERSION') {
console.log(\` Updating \${depName} in \${sectionName}: \${pkg[section][depName]} -> $RELEASE_VERSION\`);
pkg[section][depName] = '$RELEASE_VERSION';
updated = true;
}
}
});
}
};
// Update all dependency sections
updateDepsSection('dependencies', 'dependencies');
updateDepsSection('devDependencies', 'devDependencies');
updateDepsSection('peerDependencies', 'peerDependencies');
// Write back if any updates were made
if (updated) {
fs.writeFileSync('./$package_file', JSON.stringify(pkg, null, 2) + '\n');
}
"
fi
fi
done
fi
done
- name: Build Packages
run: npm run build
- name: Publish to npm
run: npm run release