Skip to content

Commit 7510e03

Browse files
committed
chore: migrate workflows to gagen
1 parent 7c0644f commit 7510e03

11 files changed

Lines changed: 469 additions & 179 deletions

.github/workflows/check_updates.yml renamed to .github/workflows/check_updates.generated.yml

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
1-
name: check_updates
1+
# GENERATED BY ./check_updates.ts -- DO NOT DIRECTLY EDIT
22

3+
name: check_updates
34
on:
4-
workflow_dispatch:
5+
workflow_dispatch: {}
56
schedule:
6-
# do this once per day
7-
- cron: "0 7 * * *"
8-
7+
- cron: 0 7 * * *
98
jobs:
109
build:
1110
name: check updates
1211
if: github.repository == 'dprint/dprint-plugin-biome'
1312
runs-on: ubuntu-latest
1413
timeout-minutes: 45
15-
1614
steps:
1715
- name: Clone repository
18-
uses: actions/checkout@v6
16+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
1917
with:
20-
token: ${{ secrets.GH_DPRINTBOT_PAT }}
21-
22-
- uses: denoland/setup-deno@v2
23-
- uses: dsherret/rust-toolchain-file@v1
24-
18+
token: '${{ secrets.GH_DPRINTBOT_PAT }}'
19+
- uses: denoland/setup-deno@667a34cdef165d8d2b2e98dde39547c9daac7282 # v2
20+
- uses: dsherret/rust-toolchain-file@3551321aa44dd44a0393eb3b6bdfbc5d25ecf621 # v1
2521
- name: Run script
26-
run: |
22+
run: |-
2723
git config user.email "dprintbot@users.noreply.github.com"
2824
git config user.name "dprintbot"
2925
deno run -A ./scripts/update.ts
30-
# This is necessary to prevent GH automatically disabling this workflow after 60 days.
3126
workflow-keepalive:
3227
if: github.event_name == 'schedule'
3328
runs-on: ubuntu-latest

.github/workflows/check_updates.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env -S deno run -A
2+
import { job, workflow } from "jsr:@david/gagen@^0.5.0";
3+
4+
const buildJob = job("build", {
5+
name: "check updates",
6+
if: "github.repository == 'dprint/dprint-plugin-biome'",
7+
runsOn: "ubuntu-latest",
8+
timeoutMinutes: 45,
9+
steps: [
10+
{
11+
name: "Clone repository",
12+
uses: "actions/checkout@v6",
13+
with: { token: "${{ secrets.GH_DPRINTBOT_PAT }}" },
14+
},
15+
{ uses: "denoland/setup-deno@v2" },
16+
{ uses: "dsherret/rust-toolchain-file@v1" },
17+
{
18+
name: "Run script",
19+
run: [
20+
`git config user.email "dprintbot@users.noreply.github.com"`,
21+
`git config user.name "dprintbot"`,
22+
"deno run -A ./scripts/update.ts",
23+
],
24+
},
25+
],
26+
});
27+
28+
// This is necessary to prevent GH automatically disabling this workflow after 60 days.
29+
const keepaliveJob = job("workflow-keepalive", {
30+
if: "github.event_name == 'schedule'",
31+
runsOn: "ubuntu-latest",
32+
permissions: { actions: "write" },
33+
steps: [
34+
{ uses: "liskin/gh-workflow-keepalive@f72ff1a1336129f29bf0166c0fd0ca6cf1bcb38c" },
35+
],
36+
});
37+
38+
workflow({
39+
name: "check_updates",
40+
on: {
41+
workflow_dispatch: {},
42+
schedule: [{ cron: "0 7 * * *" }],
43+
},
44+
jobs: [buildJob, keepaliveJob],
45+
}).writeOrLint({
46+
filePath: new URL("./check_updates.generated.yml", import.meta.url),
47+
header: "# GENERATED BY ./check_updates.ts -- DO NOT DIRECTLY EDIT",
48+
pinDeps: true,
49+
});

.github/workflows/ci.generated.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# GENERATED BY ./ci.ts -- DO NOT DIRECTLY EDIT
2+
3+
name: CI
4+
on:
5+
pull_request:
6+
branches:
7+
- main
8+
push:
9+
branches:
10+
- main
11+
tags:
12+
- '*'
13+
jobs:
14+
build:
15+
name: '${{ matrix.config.kind }} ${{ matrix.config.os }}'
16+
runs-on: '${{ matrix.config.os }}'
17+
strategy:
18+
matrix:
19+
config:
20+
- os: ubuntu-latest
21+
kind: test_release
22+
- os: ubuntu-latest
23+
kind: test_debug
24+
env:
25+
CARGO_INCREMENTAL: 0
26+
RUST_BACKTRACE: full
27+
steps:
28+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
29+
- uses: dsherret/rust-toolchain-file@3551321aa44dd44a0393eb3b6bdfbc5d25ecf621 # v1
30+
- name: Install wasm32 target
31+
if: matrix.config.kind == 'test_release'
32+
run: rustup target add wasm32-unknown-unknown
33+
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2
34+
with:
35+
save-if: '${{ github.ref == ''refs/heads/main'' }}'
36+
- uses: denoland/setup-deno@667a34cdef165d8d2b2e98dde39547c9daac7282 # v2
37+
with:
38+
deno-version: v2.x
39+
- name: Build debug
40+
if: matrix.config.kind == 'test_debug'
41+
run: cargo build
42+
- name: Build release
43+
if: matrix.config.kind == 'test_release'
44+
run: cargo build --target wasm32-unknown-unknown --features wasm --release
45+
- name: Test debug
46+
if: matrix.config.kind == 'test_debug'
47+
run: cargo test
48+
- name: Test release
49+
if: matrix.config.kind == 'test_release'
50+
run: cargo test --release
51+
- name: Get tag version
52+
id: get_tag_version
53+
if: 'matrix.config.kind == ''test_release'' && startsWith(github.ref, ''refs/tags/'')'
54+
run: 'echo "TAG_VERSION=${GITHUB_REF/refs\/tags\//}" >> "$GITHUB_OUTPUT"'
55+
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
56+
if: matrix.config.kind == 'test_release'
57+
with:
58+
node-version: 24.x
59+
registry-url: 'https://registry.npmjs.org'
60+
- name: Setup and test npm deployment
61+
if: matrix.config.kind == 'test_release'
62+
run: |-
63+
cd deployment/npm
64+
npm install
65+
node setup.js
66+
npm run test
67+
- name: Pre-release
68+
if: 'matrix.config.kind == ''test_release'' && startsWith(github.ref, ''refs/tags/'')'
69+
run: |-
70+
# update config schema to have version
71+
sed -i 's/biome\/0.0.0/biome\/${{ steps.get_tag_version.outputs.TAG_VERSION }}/' deployment/schema.json
72+
# rename the wasm file
73+
(cd target/wasm32-unknown-unknown/release/ && mv dprint_plugin_biome.wasm plugin.wasm)
74+
# create release notes
75+
deno run -A ./scripts/generateReleaseNotes.ts ${{ steps.get_tag_version.outputs.TAG_VERSION }} > ${{ github.workspace }}-CHANGELOG.txt
76+
- name: Release
77+
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844
78+
if: 'matrix.config.kind == ''test_release'' && startsWith(github.ref, ''refs/tags/'')'
79+
env:
80+
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
81+
with:
82+
files: |-
83+
target/wasm32-unknown-unknown/release/plugin.wasm
84+
deployment/schema.json
85+
body_path: '${{ github.workspace }}-CHANGELOG.txt'
86+
draft: false
87+
- name: Lint workflow generation
88+
if: matrix.config.kind == 'test_debug'
89+
run: |-
90+
./.github/workflows/ci.ts --lint
91+
./.github/workflows/publish_npm.ts --lint
92+
./.github/workflows/release.ts --lint
93+
./.github/workflows/check_updates.ts --lint

.github/workflows/ci.ts

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#!/usr/bin/env -S deno run -A
2+
import { conditions, defineMatrix, expr, job, step, workflow } from "jsr:@david/gagen@^0.5.0";
3+
4+
const pluginName = "biome";
5+
const cargoWasmName = `dprint_plugin_${pluginName}`;
6+
7+
const matrix = defineMatrix({
8+
config: [
9+
{ os: "ubuntu-latest", kind: "test_release" },
10+
{ os: "ubuntu-latest", kind: "test_debug" },
11+
],
12+
});
13+
14+
const kind = expr("matrix.config.kind");
15+
const os = expr("matrix.config.os");
16+
17+
const isRelease = kind.equals("test_release");
18+
const isDebug = kind.equals("test_debug");
19+
const isTag = conditions.isTag();
20+
const isReleaseAndTag = isRelease.and(isTag);
21+
22+
const getTagVersion = step({
23+
id: "get_tag_version",
24+
name: "Get tag version",
25+
if: isReleaseAndTag,
26+
run: `echo "TAG_VERSION=\${GITHUB_REF/refs\\/tags\\//}" >> "$GITHUB_OUTPUT"`,
27+
outputs: ["TAG_VERSION"],
28+
});
29+
30+
const buildJob = job("build", {
31+
name: `${kind} ${os}`,
32+
runsOn: os,
33+
strategy: { matrix },
34+
env: {
35+
CARGO_INCREMENTAL: 0,
36+
RUST_BACKTRACE: "full",
37+
},
38+
steps: [
39+
{ uses: "actions/checkout@v6" },
40+
{ uses: "dsherret/rust-toolchain-file@v1" },
41+
{
42+
name: "Install wasm32 target",
43+
if: isRelease,
44+
run: "rustup target add wasm32-unknown-unknown",
45+
},
46+
{
47+
uses: "Swatinem/rust-cache@v2",
48+
with: { "save-if": "${{ github.ref == 'refs/heads/main' }}" },
49+
},
50+
// deno is needed by the "Lint workflow generation" step (test_debug)
51+
// and by the "Pre-release" step (test_release on tag). Install it
52+
// once at the top of every job to keep the matrix steps simple.
53+
{
54+
uses: "denoland/setup-deno@v2",
55+
with: { "deno-version": "v2.x" },
56+
},
57+
58+
{ name: "Build debug", if: isDebug, run: "cargo build" },
59+
{
60+
name: "Build release",
61+
if: isRelease,
62+
run: "cargo build --target wasm32-unknown-unknown --features wasm --release",
63+
},
64+
65+
{ name: "Test debug", if: isDebug, run: "cargo test" },
66+
{ name: "Test release", if: isRelease, run: "cargo test --release" },
67+
68+
getTagVersion,
69+
70+
// NPM
71+
{
72+
uses: "actions/setup-node@v6",
73+
if: isRelease,
74+
with: {
75+
"node-version": "24.x",
76+
"registry-url": "https://registry.npmjs.org",
77+
},
78+
},
79+
{
80+
name: "Setup and test npm deployment",
81+
if: isRelease,
82+
run: [
83+
"cd deployment/npm",
84+
"npm install",
85+
"node setup.js",
86+
"npm run test",
87+
],
88+
},
89+
90+
// GITHUB RELEASE
91+
{
92+
name: "Pre-release",
93+
if: isReleaseAndTag,
94+
run: [
95+
"# update config schema to have version",
96+
`sed -i 's/${pluginName}\\/0.0.0/${pluginName}\\/${getTagVersion.outputs.TAG_VERSION}/' deployment/schema.json`,
97+
"# rename the wasm file",
98+
`(cd target/wasm32-unknown-unknown/release/ && mv ${cargoWasmName}.wasm plugin.wasm)`,
99+
"# create release notes",
100+
`deno run -A ./scripts/generateReleaseNotes.ts ${getTagVersion.outputs.TAG_VERSION} > \${{ github.workspace }}-CHANGELOG.txt`,
101+
],
102+
},
103+
{
104+
name: "Release",
105+
// pinned because softprops/action-gh-release was once compromised
106+
uses: "softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844",
107+
if: isReleaseAndTag,
108+
env: { GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" },
109+
with: {
110+
files: [
111+
"target/wasm32-unknown-unknown/release/plugin.wasm",
112+
"deployment/schema.json",
113+
].join("\n"),
114+
body_path: "${{ github.workspace }}-CHANGELOG.txt",
115+
draft: false,
116+
},
117+
},
118+
{
119+
name: "Lint workflow generation",
120+
if: isDebug,
121+
run: [
122+
"./.github/workflows/ci.ts --lint",
123+
"./.github/workflows/publish_npm.ts --lint",
124+
"./.github/workflows/release.ts --lint",
125+
"./.github/workflows/check_updates.ts --lint",
126+
],
127+
},
128+
],
129+
});
130+
131+
workflow({
132+
name: "CI",
133+
on: {
134+
pull_request: { branches: ["main"] },
135+
push: { branches: ["main"], tags: ["*"] },
136+
},
137+
jobs: [buildJob],
138+
}).writeOrLint({
139+
filePath: new URL("./ci.generated.yml", import.meta.url),
140+
header: "# GENERATED BY ./ci.ts -- DO NOT DIRECTLY EDIT",
141+
pinDeps: true,
142+
});

0 commit comments

Comments
 (0)