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