Skip to content

Commit 20a9d82

Browse files
committed
Make the workflows maintainable
1 parent de359fa commit 20a9d82

7 files changed

Lines changed: 280 additions & 136 deletions

File tree

files/.github/workflows/ci.yml

Lines changed: 1 addition & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1 @@
1-
name: CI
2-
3-
on:
4-
push:
5-
branches:
6-
- main
7-
- master
8-
pull_request: {}
9-
10-
concurrency:
11-
group: ci-${{ github.head_ref || github.ref }}
12-
cancel-in-progress: true
13-
14-
jobs:
15-
lint:
16-
name: "Lints"
17-
runs-on: ubuntu-latest
18-
timeout-minutes: 10
19-
20-
steps:
21-
- uses: actions/checkout@v4<% if (pnpm) { %>
22-
- uses: pnpm/action-setup@v4<% } %>
23-
- uses: actions/setup-node@v4
24-
with:
25-
node-version: 22
26-
cache: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm' %>
27-
- name: Install Dependencies
28-
run: <%= pnpm ? 'pnpm install --frozen-lockfile' : yarn ? 'yarn install --frozen-lockfile' : 'npm ci' %>
29-
- name: Lint
30-
run: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm run' %> lint
31-
32-
test:
33-
name: "Tests"
34-
runs-on: ubuntu-latest
35-
timeout-minutes: 10
36-
outputs:
37-
matrix: ${{ steps.set-matrix.outputs.matrix }}
38-
39-
steps:
40-
- uses: actions/checkout@v4<% if (pnpm) { %>
41-
- uses: pnpm/action-setup@v4<% } %>
42-
- uses: actions/setup-node@v4
43-
with:
44-
node-version: 22
45-
cache: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm' %>
46-
- name: Install Dependencies
47-
run: <%= pnpm ? 'pnpm install --frozen-lockfile' : yarn ? 'yarn install --frozen-lockfile' : 'npm ci' %>
48-
- name: Run Tests
49-
run: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm run' %> test
50-
# For the Try Scenarios
51-
- id: set-matrix
52-
run: |
53-
<% if (pnpm) { %> echo "matrix=$(pnpm -s dlx @embroider/try list)" >> $GITHUB_OUTPUT<% } %>
54-
<% if (npm) { %> echo "matrix=$(npx @embroider/try list)" >> $GITHUB_OUTPUT<% } %>
55-
56-
floating:
57-
name: "Floating Dependencies"
58-
runs-on: ubuntu-latest
59-
timeout-minutes: 10
60-
61-
steps:
62-
- uses: actions/checkout@v4<% if (pnpm) { %>
63-
- uses: pnpm/action-setup@v4<% } %>
64-
- uses: actions/setup-node@v4
65-
with:
66-
node-version: 22
67-
cache: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm' %>
68-
- name: Install Dependencies
69-
run: <%= pnpm ? 'pnpm install --no-lockfile' : yarn ? 'yarn install --no-lockfile' : 'npm install --no-package-lock' %>
70-
- name: Run Tests
71-
run: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm run' %> test
72-
73-
try-scenarios:
74-
name: ${{ matrix.name }}
75-
runs-on: ubuntu-latest
76-
needs: "test"
77-
timeout-minutes: 10
78-
strategy:
79-
fail-fast: false
80-
matrix: ${{fromJson(needs.test.outputs.matrix)}}
81-
82-
steps:
83-
- uses: actions/checkout@v4<% if (pnpm) { %>
84-
- uses: pnpm/action-setup@v4<% } %>
85-
- uses: actions/setup-node@v4
86-
with:
87-
node-version: 22
88-
cache: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm' %>
89-
- name: Apply Scenario
90-
run: |
91-
<% if (pnpm) { %> pnpm dlx @embroider/try apply ${{ matrix.name }}<% } %>
92-
<% if (npm) { %> npx @embroider/try apply ${{ matrix.name }}<% } %>
93-
- name: Install Dependencies
94-
run: <%= pnpm ? 'pnpm install --no-lockfile' : yarn ? 'yarn install --no-lockfile' : 'npm install --no-package-lock' %>
95-
- name: Run Tests
96-
run: |
97-
<% if (pnpm) { %>pnpm test<% } %>
98-
<% if (npm) { %>npm test<% } %>
99-
env: ${{ matrix.env }}
1+
# Replaced from src/.github, based on selected packageManager
Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1 @@
1-
# Because this library needs to be built,
2-
# we can't easily point package.json files at the git repo for easy cross-repo testing.
3-
#
4-
# This workflow brings back that capability by placing the compiled assets on a "dist" branch
5-
# (configurable via the "branch" option below)
6-
name: Push dist
7-
8-
on:
9-
push:
10-
branches:
11-
- main
12-
- master
13-
14-
jobs:
15-
push-dist:
16-
name: Push dist
17-
permissions:
18-
contents: write
19-
runs-on: ubuntu-latest
20-
timeout-minutes: 10
21-
22-
steps:
23-
- uses: actions/checkout@v4<% if (pnpm) { %>
24-
- uses: pnpm/action-setup@v4<% } %>
25-
- uses: actions/setup-node@v4
26-
with:
27-
node-version: 22
28-
cache: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm' %>
29-
- name: Install Dependencies
30-
run: <%= pnpm ? 'pnpm install --frozen-lockfile' : yarn ? 'yarn install --frozen-lockfile' : 'npm ci' %>
31-
- uses: kategengler/[email protected]
32-
with:
33-
branch: dist
34-
token: ${{ secrets.GITHUB_TOKEN }}
1+
# Replaced from src/.github, based on selected packageManager

index.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { readFileSync } = require('fs');
4+
const { join } = require('path');
35
const { sortPackageJson } = require('sort-package-json');
46

57
let date = new Date();
@@ -10,12 +12,25 @@ function stringifyAndNormalize(contents) {
1012
return `${JSON.stringify(contents, null, 2)}\n`;
1113
}
1214

15+
const workflows = join(__dirname, 'src/.github/workflows/');
16+
1317
const replacers = {
14-
'package.json'(content) {
18+
'.github/workflows/ci.yml'(templateVariables) {
19+
let sourcePath = join(workflows, templateVariables.packageManager, 'ci.yml');
20+
21+
return readFileSync(sourcePath);
22+
},
23+
'.github/workflows/push-dist.yml'(templateVariables) {
24+
let sourcePath = join(workflows, templateVariables.packageManager, 'push-dist.yml');
25+
26+
return readFileSync(sourcePath);
27+
},
28+
'package.json'(_templateVariables, content) {
1529
return this.updatePackageJson(content);
1630
},
1731
};
1832

33+
1934
module.exports = {
2035
description,
2136

@@ -93,11 +108,11 @@ module.exports = {
93108
* _js_eslint.config.mjs is deleted
94109
* _ts_eslint.config.mjs is renamed to eslint.config.mjs
95110
*/
96-
buildFileInfo(_intoDir, _templateVariables, file, _commandOptions) {
111+
buildFileInfo(_intoDir, templateVariables, file, _commandOptions) {
97112
let fileInfo = this._super.buildFileInfo.apply(this, arguments);
98113

99114
if (file in replacers) {
100-
fileInfo.replacer = replacers[file].bind(this);
115+
fileInfo.replacer = replacers[file].bind(this, templateVariables);
101116
}
102117

103118
return fileInfo;

src/.github/workflows/npm/ci.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
pull_request: {}
9+
10+
concurrency:
11+
group: ci-${{ github.head_ref || github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
lint:
16+
name: "Lints"
17+
runs-on: ubuntu-latest
18+
timeout-minutes: 10
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: actions/setup-node@v4
23+
with:
24+
node-version: 22
25+
cache: npm
26+
- name: Install Dependencies
27+
run: npm ci
28+
- name: Lint
29+
run: npm run lint
30+
31+
test:
32+
name: "Tests"
33+
runs-on: ubuntu-latest
34+
timeout-minutes: 10
35+
outputs:
36+
matrix: ${{ steps.set-matrix.outputs.matrix }}
37+
38+
steps:
39+
- uses: actions/checkout@v4
40+
- uses: actions/setup-node@v4
41+
with:
42+
node-version: 22
43+
cache: npm
44+
- name: Install Dependencies
45+
run: npm ci
46+
- name: Run Tests
47+
run: npm run test
48+
# For the Try Scenarios
49+
- id: set-matrix
50+
run: |
51+
52+
echo "matrix=$(npx @embroider/try list)" >> $GITHUB_OUTPUT
53+
54+
floating:
55+
name: "Floating Dependencies"
56+
runs-on: ubuntu-latest
57+
timeout-minutes: 10
58+
59+
steps:
60+
- uses: actions/checkout@v4
61+
- uses: actions/setup-node@v4
62+
with:
63+
node-version: 22
64+
cache: npm
65+
- name: Install Dependencies
66+
run: npm install --no-package-lock
67+
- name: Run Tests
68+
run: npm run test
69+
70+
try-scenarios:
71+
name: ${{ matrix.name }}
72+
runs-on: ubuntu-latest
73+
needs: "test"
74+
timeout-minutes: 10
75+
strategy:
76+
fail-fast: false
77+
matrix: ${{fromJson(needs.test.outputs.matrix)}}
78+
79+
steps:
80+
- uses: actions/checkout@v4
81+
- uses: actions/setup-node@v4
82+
with:
83+
node-version: 22
84+
cache: npm
85+
- name: Apply Scenario
86+
run: |
87+
88+
npx @embroider/try apply ${{ matrix.name }}
89+
- name: Install Dependencies
90+
run: npm install --no-package-lock
91+
- name: Run Tests
92+
run: |
93+
94+
npm test
95+
env: ${{ matrix.env }}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Because this library needs to be built,
2+
# we can't easily point package.json files at the git repo for easy cross-repo testing.
3+
#
4+
# This workflow brings back that capability by placing the compiled assets on a "dist" branch
5+
# (configurable via the "branch" option below)
6+
name: Push dist
7+
8+
on:
9+
push:
10+
branches:
11+
- main
12+
- master
13+
14+
jobs:
15+
push-dist:
16+
name: Push dist
17+
permissions:
18+
contents: write
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 10
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
- uses: actions/setup-node@v4
25+
with:
26+
node-version: 22
27+
cache: npm
28+
- name: Install Dependencies
29+
run: npm ci
30+
- uses: kategengler/[email protected]
31+
with:
32+
branch: dist
33+
token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)