Skip to content

Commit c122ce4

Browse files
authored
fix(package.json): move astro from dependencies to peerDependencies (#668)
* fix(package.json): move astro from dependencies to peerDependencies * chore(knip.config.ts): enable astro plugin manually * test(tests/e2e/fixtures/package.json): add astro to dependencies * test(tests/e2e/fixtures/bun.lockb): update lockfile * chore(knip.config.ts): remove ignoreBinaries in test fixtures workspace * fix(package.json): add carets to dependency versions * fix(package.json): loose peerDependencies version constraint and add astro to devDependencies * chore(renovate.json5): disable version pinning for dependencies and peerDependencies * ci(.github/workflows/e2e.yml): handle multiple versions of astro * ci(.github/workflows/lint.yml): add job to conclude the result * ci(.github/workflows/lint.yml): run actions-timeline after lint-status * ci(.github/workflows/lint.yml): handle skipped and cancelled status for conclusion job * ci(.github/workflows/lint.yml): fix if statement in bash script * ci(.github/workflows/lint.yml): fix check status bash script * ci(.github/workflows/lint.yml): split actions-timeline job * ci(.github/workflows/e2e.yml): test several astro versions in the fixture * fix(package.json): narrow astro peerDependencies range
1 parent 56c2fe4 commit c122ce4

File tree

9 files changed

+156
-10
lines changed

9 files changed

+156
-10
lines changed

.github/workflows/e2e.yml

+70-4
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,55 @@ defaults:
1414
shell: bash
1515

1616
jobs:
17+
list-astro-versions:
18+
runs-on: ubuntu-24.04
19+
timeout-minutes: 10
20+
permissions:
21+
contents: read # for checkout
22+
23+
outputs:
24+
astro-versions: ${{ steps.list.outputs.versions }}
25+
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
29+
30+
- name: Install mise
31+
uses: jdx/mise-action@f8dfbcc150159126838e44b882bf34bd98fd90f3 # v2.1.0
32+
with:
33+
experimental: true
34+
install: false
35+
36+
- name: Install mise tools
37+
# cspell:ignore reshim
38+
# reshim is required to avoid "No such file or directory" error
39+
# ref: https://github.com/jdx/mise/issues/2260
40+
run: mise install || (mise reshim && mise install)
41+
42+
- name: Install package.json dependencies
43+
run: mise run buni
44+
45+
- name: List astro versions for E2E tests
46+
id: list
47+
run: |
48+
versions=$(bun run .github/workflows/scripts/list-astro-versions.ts)
49+
echo "versions=$versions" >> "$GITHUB_OUTPUT"
50+
1751
test-e2e-general:
52+
needs:
53+
- list-astro-versions
54+
1855
runs-on: ubuntu-24.04
1956
timeout-minutes: 10
2057
permissions:
2158
contents: read # for checkout
2259

60+
name: test-e2e-general-astro-${{ matrix.version }}
61+
strategy:
62+
fail-fast: false
63+
matrix:
64+
version: ${{ fromJson(needs.list-astro-versions.outputs.astro-versions) }}
65+
2366
steps:
2467
- name: Checkout
2568
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
@@ -43,7 +86,7 @@ jobs:
4386
run: mise run build
4487

4588
- name: Install E2E Test Fixtures Dependencies
46-
run: bun install --frozen-lockfile
89+
run: bun install astro@${{ matrix.version }}
4790
working-directory: tests/e2e/fixtures
4891

4992
- name: Build E2E Test Fixtures with astro-better-image-service
@@ -89,7 +132,7 @@ jobs:
89132
if: failure() && steps.playwright-test.outcome == 'failure'
90133
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
91134
with:
92-
name: playwright-report-${{ github.sha }}
135+
name: playwright-report-astro-${{ matrix.version }}-${{ github.sha }}
93136
path: playwright-report/
94137

95138
test-e2e-conversion:
@@ -124,7 +167,12 @@ jobs:
124167
id: dependency-versions
125168
run: |
126169
playwright_version=$(bun pm ls | sed -nE 's/.*@playwright\/test@(.+)/\1/p')
127-
astro_version=$(bun pm ls | sed -nE 's/.*astro@(.+)/\1/p')
170+
astro_version=$(bun pm ls | sed -nE 's/.*astro@(.+)/\1/p' | uniq)
171+
# throw error if several versions are found
172+
if [[ $(echo "$astro_version" | wc -l) -gt 1 ]]; then
173+
echo "Multiple versions of Astro found: $astro_version"
174+
exit 1
175+
fi
128176
echo "playwright=$playwright_version" >> "$GITHUB_OUTPUT"
129177
echo "astro=$astro_version" >> "$GITHUB_OUTPUT"
130178
@@ -203,14 +251,32 @@ jobs:
203251
name: playwright-report-conversion-${{ github.sha }}
204252
path: playwright-report/
205253

206-
actions-timeline:
254+
test-e2e-status:
207255
needs:
208256
- test-e2e-general
209257
- test-e2e-conversion
210258

211259
# skip if the workflow is called from another workflow
212260
if: ${{ !cancelled() && contains(github.workflow_ref, '/e2e.yml') }}
213261

262+
runs-on: ubuntu-24.04
263+
timeout-minutes: 5
264+
265+
steps:
266+
- name: Check the status of the jobs
267+
run: |
268+
if [[ $(echo '${{ toJson(needs.*.result) }}' | jq 'all(. == "success")') == "false" ]]; then
269+
echo 'Some jobs are failed, cancelled, or skipped.'
270+
exit 1
271+
fi
272+
echo 'All jobs are successful.'
273+
274+
actions-timeline:
275+
needs:
276+
- test-e2e-status
277+
278+
if: needs.test-e2e-status.result == 'success' || needs.test-e2e-status.result == 'failure'
279+
214280
runs-on: ubuntu-24.04
215281
timeout-minutes: 5
216282
permissions:

.github/workflows/lint.yml

+19-1
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,32 @@ jobs:
148148
if: steps.commitlint-push-initial.outcome == 'skipped' && steps.commitlint-push.outcome == 'skipped' && steps.commitlint-pr.outcome == 'skipped'
149149
run: bun run commitlint --verbose --from ${{ github.sha }}~1 --to ${{ github.sha }}
150150

151-
actions-timeline:
151+
lint-status:
152152
needs:
153153
- lint
154154
- lint-commitlint
155155

156156
# skip if the workflow is called from another workflow
157157
if: ${{ !cancelled() && contains(github.workflow_ref, '/lint.yml') }}
158158

159+
runs-on: ubuntu-24.04
160+
timeout-minutes: 5
161+
162+
steps:
163+
- name: Check the status of the jobs
164+
run: |
165+
if [[ $(echo '${{ toJson(needs.*.result) }}' | jq 'all(. == "success")') == "false" ]]; then
166+
echo 'Some jobs are failed, cancelled, or skipped.'
167+
exit 1
168+
fi
169+
echo 'All jobs are successful.'
170+
171+
actions-timeline:
172+
needs:
173+
- lint-status
174+
175+
if: needs.lint-status.result == 'success' || needs.lint-status.result == 'failure'
176+
159177
runs-on: ubuntu-24.04
160178
timeout-minutes: 5
161179
permissions:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { $ } from "bun";
2+
import { compare, parse, satisfies } from "semver";
3+
import packageJson from "../../../package.json" with { type: "json" };
4+
5+
$.throws(true);
6+
7+
const peerRange = packageJson.peerDependencies.astro as string;
8+
9+
const versions = (await $`npm view astro versions --json`.json()) as string[];
10+
11+
const versionsInRange = versions
12+
.filter((version) => satisfies(version, peerRange))
13+
.sort(compare);
14+
15+
const groupedVersions = Object.groupBy(versionsInRange, (version) => {
16+
const semver = parse(version);
17+
if (!semver) {
18+
throw new Error(`Invalid version: ${version}`);
19+
}
20+
return `${semver.major}.${semver.minor}`;
21+
});
22+
23+
const versionsToTest = [
24+
...new Set([
25+
// oldest 3 versions
26+
...versionsInRange.slice(0, 3),
27+
// oldest version of each major version
28+
...Object.entries(groupedVersions)
29+
.filter(([key]) => key.endsWith(".0"))
30+
.map(([, versions]) => versions?.at(0)),
31+
// latest version of each minor version
32+
...Object.values(groupedVersions).map((versions) => versions?.at(-1)),
33+
// latest 5 versions
34+
...versionsInRange.slice(-5),
35+
]),
36+
];
37+
38+
console.write(JSON.stringify(versionsToTest));

bun.lockb

-7.02 KB
Binary file not shown.

knip.config.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ const config: KnipConfig = {
77
workspaces: {
88
".": {
99
ignoreDependencies: [
10-
// mise.toml is not recognized by Knip
10+
// mise.toml is not recognized
1111
"@biomejs/biome",
1212
"cspell",
1313
"ignore-sync",
1414
"markdownlint-cli2",
1515
"renovate",
16-
// bun run cannot be detected by Knip
16+
// bun run cannot be detected
1717
"@commitlint/cli",
1818
"semantic-release",
1919
],
2020
entry: ["src/index.ts", "**/scripts/**"],
21+
// peerDependencies are not recognized as plugins
22+
astro: true,
2123
},
2224
"tests/e2e/fixtures": {},
2325
},

package.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
"prepare": "husky && bun link"
2525
},
2626
"dependencies": {
27-
"astro": "4.15.11",
28-
"sharp": "0.33.5",
29-
"svgo": "3.3.2"
27+
"sharp": "^0.33.5",
28+
"svgo": "^3.3.2"
29+
},
30+
"peerDependencies": {
31+
"astro": "^4.7.0"
3032
},
3133
"devDependencies": {
3234
"@biomejs/biome": "1.9.3",
@@ -45,6 +47,7 @@
4547
"ajv": "8.17.1",
4648
"ajv-draft-04": "1.0.0",
4749
"ajv-formats": "3.0.1",
50+
"astro": "4.15.11",
4851
"commitizen": "4.3.1",
4952
"cspell": "8.14.4",
5053
"husky": "9.1.6",
@@ -57,6 +60,7 @@
5760
"prettier": "3.3.3",
5861
"renovate": "38.110.2",
5962
"semantic-release": "24.1.2",
63+
"semver": "7.6.3",
6064
"ts-graphviz": "2.1.4",
6165
"typescript": "5.6.2"
6266
},

renovate.json5

+17
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,24 @@
8282
},
8383
],
8484
packageRules: [
85+
// disable pinning for dependencies and peerDependencies
86+
{
87+
matchFileNames: ["package.json"],
88+
matchDepTypes: ["dependencies"],
89+
// bump for dependencies and release a patch update
90+
rangeStrategy: "bump",
91+
},
92+
{
93+
matchFileNames: ["package.json"],
94+
matchDepTypes: ["peerDependencies"],
95+
// widen range for peerDependencies as far as possible
96+
rangeStrategy: "widen",
97+
},
8598
// set semantic commit types
99+
{
100+
matchFileNames: ["tests/"],
101+
semanticCommitType: "test",
102+
},
86103
{
87104
matchCategories: ["ci"],
88105
semanticCommitType: "ci",

tests/e2e/fixtures/bun.lockb

152 KB
Binary file not shown.

tests/e2e/fixtures/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"private": true,
44
"type": "module",
55
"dependencies": {
6+
"astro": "4.15.11",
67
"astro-better-image-service": "link:astro-better-image-service"
78
},
89
"scripts": {

0 commit comments

Comments
 (0)