Skip to content

Commit fe610d6

Browse files
authored
ci: Force the same version bumps for rs and js packages (#2130)
1 parent a7e58f5 commit fe610d6

File tree

4 files changed

+136
-2
lines changed

4 files changed

+136
-2
lines changed

.changes/config.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@
170170
},
171171
"dialog-js": {
172172
"path": "./plugins/dialog",
173-
"manager": "javascript"
173+
"manager": "javascript",
174+
"dependencies": ["fs-js"]
174175
},
175176
"geolocation": {
176177
"path": "./plugins/geolocation",
@@ -211,7 +212,8 @@
211212
},
212213
"http-js": {
213214
"path": "./plugins/http",
214-
"manager": "javascript"
215+
"manager": "javascript",
216+
"dependencies": ["fs-js"]
215217
},
216218
"localhost": {
217219
"path": "./plugins/localhost",

.changes/readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ As you create PRs and make changes that require a version bump, please add a new
66

77
When you select the version bump required, you do _not_ need to consider dependencies. Only note the package with the actual change, and any packages that depend on that package will be bumped automatically in the process.
88

9+
**Note, that in this repository, even if only the Rust code or only the JavaScript code of a plugin changed, both packages need to be bumped with the same increment!**
10+
911
Use the following format:
1012

1113
```md
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright 2019-2023 Tauri Programme within The Commons Conservancy
2+
# SPDX-License-Identifier: Apache-2.0
3+
# SPDX-License-Identifier: MIT
4+
5+
name: check change files
6+
7+
on:
8+
pull_request:
9+
paths:
10+
- '.changes/*.md'
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
check:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: check change files end with .md
23+
run: |
24+
for file in .changes/*
25+
do
26+
if [[ ! "$file" =~ \.(md|json)$ ]]; then
27+
echo ".changes directory should only contain files that end with .md"
28+
echo "found an invalid file in .changes directory:"
29+
echo "$file"
30+
exit 1
31+
fi
32+
done
33+
34+
- uses: dorny/paths-filter@v3
35+
id: filter
36+
with:
37+
list-files: shell
38+
filters: |
39+
changes:
40+
- added|modified: '.changes/*.md'
41+
42+
- name: check
43+
run: node ./.scripts/ci/check-change-files.js ${{ steps.filter.outputs.changes_files }}
44+
if: ${{ steps.filter.outputs.changes == 'true' }}

.scripts/ci/check-change-files.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env node
2+
3+
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
4+
// SPDX-License-Identifier: Apache-2.0
5+
// SPDX-License-Identifier: MIT
6+
7+
import { readFileSync, readdirSync } from 'fs'
8+
import { join } from 'path'
9+
10+
/* const ignorePackages = [
11+
'api-example',
12+
'api-example-js',
13+
'deep-link-example',
14+
'deep-link-example-js'
15+
] */
16+
17+
const rsOnly = ['localhost', 'persisted-scope']
18+
19+
function checkChangeFiles(changeFiles) {
20+
let code = 0
21+
22+
for (const file of changeFiles) {
23+
const content = readFileSync(file, 'utf8')
24+
const [frontMatter] = /^---[\s\S.]*---\n/i.exec(content)
25+
const packages = frontMatter
26+
.split('\n')
27+
.filter((l) => !(l === '---' || !l))
28+
.map((l) => l.replace(/('|")/g, '').split(':'))
29+
30+
const rsPackages = Object.fromEntries(
31+
packages
32+
.filter((v) => !v[0].endsWith('-js'))
33+
.map((v) => [v[0], v[1].trim()])
34+
)
35+
const jsPackages = Object.fromEntries(
36+
packages
37+
.filter((v) => v[0].endsWith('-js'))
38+
.map((v) => [v[0].slice(0, -3), v[1].trim()])
39+
)
40+
41+
for (const pkg in rsPackages) {
42+
if (rsOnly.includes(pkg)) continue
43+
44+
if (!jsPackages[pkg]) {
45+
console.error(
46+
`Missing "${rsPackages[pkg]}" bump for JS package "${pkg}-js" in ${file}.`
47+
)
48+
code = 1
49+
} else if (rsPackages[pkg] != jsPackages[pkg]) {
50+
console.error(
51+
`"${pkg}" and "${pkg}-js" have different version bumps in ${file}.`
52+
)
53+
code = 1
54+
}
55+
}
56+
57+
for (const pkg in jsPackages) {
58+
if (!rsPackages[pkg]) {
59+
console.error(
60+
`Missing "${jsPackages[pkg]}" bump for Rust package "${pkg}" in ${file}.`
61+
)
62+
code = 1
63+
} else if (rsPackages[pkg] != jsPackages[pkg]) {
64+
console.error(
65+
`"${pkg}" and "${pkg}-js" have different version bumps in ${file}.`
66+
)
67+
code = 1
68+
}
69+
}
70+
}
71+
72+
process.exit(code)
73+
}
74+
75+
const [_bin, _script, ...files] = process.argv
76+
77+
if (files.length > 0) {
78+
checkChangeFiles(
79+
files.filter((f) => f.toLowerCase() !== '.changes/readme.md')
80+
)
81+
} else {
82+
const changeFiles = readdirSync('.changes')
83+
.filter((f) => f.endsWith('.md') && f.toLowerCase() !== 'readme.md')
84+
.map((p) => join('.changes', p))
85+
checkChangeFiles(changeFiles)
86+
}

0 commit comments

Comments
 (0)