Skip to content

Commit 8a04c3e

Browse files
committed
chore: migrate workflows to gagen
1 parent 3acbe7b commit 8a04c3e

9 files changed

Lines changed: 470 additions & 197 deletions

File tree

.github/workflows/ci.generated.yml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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: Lint
43+
if: matrix.config.kind == 'test_debug'
44+
run: cargo clippy
45+
- name: Test debug
46+
if: matrix.config.kind == 'test_debug'
47+
run: cargo test
48+
- name: Build release
49+
if: matrix.config.kind == 'test_release'
50+
run: cargo build --target wasm32-unknown-unknown --features "wasm" --release
51+
- name: Test release
52+
if: matrix.config.kind == 'test_release'
53+
run: cargo test --release
54+
- name: Wasm integration test - Setup
55+
if: matrix.config.kind == 'test_release'
56+
run: 'echo ''{ "plugins": ["./target/wasm32-unknown-unknown/release/dprint_plugin_typescript.wasm"] }'' >> dprint.test.json'
57+
- name: Wasm integration test - Run
58+
uses: dprint/check@2f1cf31537886c3bfb05591c031f7744e48ba8a1 # v2.2
59+
if: matrix.config.kind == 'test_release'
60+
with:
61+
config-path: dprint.test.json
62+
- name: Wasm integration test - Cleanup
63+
if: matrix.config.kind == 'test_release'
64+
run: rm dprint.test.json
65+
- name: Get tag version
66+
id: get_tag_version
67+
if: 'matrix.config.kind == ''test_release'' && startsWith(github.ref, ''refs/tags/'')'
68+
run: 'echo "TAG_VERSION=${GITHUB_REF/refs\/tags\//}" >> "$GITHUB_OUTPUT"'
69+
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
70+
if: matrix.config.kind == 'test_release'
71+
with:
72+
node-version: 24.x
73+
registry-url: 'https://registry.npmjs.org'
74+
- name: Setup and test npm deployment
75+
if: matrix.config.kind == 'test_release'
76+
run: |-
77+
cd deployment/npm
78+
npm install
79+
node setup.js
80+
npm run test
81+
- name: Pre-release
82+
if: 'matrix.config.kind == ''test_release'' && startsWith(github.ref, ''refs/tags/'')'
83+
run: |-
84+
# update config schema to have version
85+
sed -i 's/typescript\/0.0.0/typescript\/${{ steps.get_tag_version.outputs.TAG_VERSION }}/' deployment/schema.json
86+
# rename the wasm file
87+
(cd target/wasm32-unknown-unknown/release/ && mv dprint_plugin_typescript.wasm plugin.wasm)
88+
# create release notes
89+
deno run -A ./scripts/generate_release_notes.ts ${{ steps.get_tag_version.outputs.TAG_VERSION }} > ${{ github.workspace }}-CHANGELOG.txt
90+
- name: Release
91+
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844
92+
if: 'matrix.config.kind == ''test_release'' && startsWith(github.ref, ''refs/tags/'')'
93+
env:
94+
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
95+
with:
96+
files: |-
97+
target/wasm32-unknown-unknown/release/plugin.wasm
98+
deployment/schema.json
99+
body_path: '${{ github.workspace }}-CHANGELOG.txt'
100+
draft: false
101+
- name: Lint workflow generation
102+
if: matrix.config.kind == 'test_debug'
103+
run: |-
104+
./.github/workflows/ci.ts --lint
105+
./.github/workflows/publish.ts --lint
106+
./.github/workflows/release.ts --lint

.github/workflows/ci.ts

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
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 = "typescript";
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+
{ name: "Lint", if: isDebug, run: "cargo clippy" },
60+
{ name: "Test debug", if: isDebug, run: "cargo test" },
61+
62+
{
63+
name: "Build release",
64+
if: isRelease,
65+
run: `cargo build --target wasm32-unknown-unknown --features "wasm" --release`,
66+
},
67+
{ name: "Test release", if: isRelease, run: "cargo test --release" },
68+
69+
// wasm integration test (typescript-specific)
70+
{
71+
name: "Wasm integration test - Setup",
72+
if: isRelease,
73+
run:
74+
`echo '{ "plugins": ["./target/wasm32-unknown-unknown/release/${cargoWasmName}.wasm"] }' >> dprint.test.json`,
75+
},
76+
{
77+
name: "Wasm integration test - Run",
78+
if: isRelease,
79+
uses: "dprint/check@v2.2",
80+
with: { "config-path": "dprint.test.json" },
81+
},
82+
{
83+
name: "Wasm integration test - Cleanup",
84+
if: isRelease,
85+
run: "rm dprint.test.json",
86+
},
87+
88+
getTagVersion,
89+
90+
// NPM
91+
{
92+
uses: "actions/setup-node@v6",
93+
if: isRelease,
94+
with: {
95+
"node-version": "24.x",
96+
"registry-url": "https://registry.npmjs.org",
97+
},
98+
},
99+
{
100+
name: "Setup and test npm deployment",
101+
if: isRelease,
102+
run: [
103+
"cd deployment/npm",
104+
"npm install",
105+
"node setup.js",
106+
"npm run test",
107+
],
108+
},
109+
110+
// GITHUB RELEASE
111+
{
112+
name: "Pre-release",
113+
if: isReleaseAndTag,
114+
run: [
115+
"# update config schema to have version",
116+
`sed -i 's/${pluginName}\\/0.0.0/${pluginName}\\/${getTagVersion.outputs.TAG_VERSION}/' deployment/schema.json`,
117+
"# rename the wasm file",
118+
`(cd target/wasm32-unknown-unknown/release/ && mv ${cargoWasmName}.wasm plugin.wasm)`,
119+
"# create release notes",
120+
`deno run -A ./scripts/generate_release_notes.ts ${getTagVersion.outputs.TAG_VERSION} > \${{ github.workspace }}-CHANGELOG.txt`,
121+
],
122+
},
123+
{
124+
name: "Release",
125+
// pinned because softprops/action-gh-release was once compromised
126+
uses: "softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844",
127+
if: isReleaseAndTag,
128+
env: { GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" },
129+
with: {
130+
files: [
131+
"target/wasm32-unknown-unknown/release/plugin.wasm",
132+
"deployment/schema.json",
133+
].join("\n"),
134+
body_path: "${{ github.workspace }}-CHANGELOG.txt",
135+
draft: false,
136+
},
137+
},
138+
{
139+
name: "Lint workflow generation",
140+
if: isDebug,
141+
run: [
142+
"./.github/workflows/ci.ts --lint",
143+
"./.github/workflows/publish.ts --lint",
144+
"./.github/workflows/release.ts --lint",
145+
],
146+
},
147+
],
148+
});
149+
150+
workflow({
151+
name: "CI",
152+
on: {
153+
pull_request: { branches: ["main"] },
154+
push: { branches: ["main"], tags: ["*"] },
155+
},
156+
jobs: [buildJob],
157+
}).writeOrLint({
158+
filePath: new URL("./ci.generated.yml", import.meta.url),
159+
header: "# GENERATED BY ./ci.ts -- DO NOT DIRECTLY EDIT",
160+
pinDeps: true,
161+
});

.github/workflows/ci.yml

Lines changed: 0 additions & 113 deletions
This file was deleted.

0 commit comments

Comments
 (0)