Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions .github/workflows/ci.generated.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# GENERATED BY ./ci.ts -- DO NOT DIRECTLY EDIT

name: CI
on:
pull_request:
branches:
- main
push:
branches:
- main
tags:
- '*'
jobs:
build:
name: '${{ matrix.config.kind }} ${{ matrix.config.os }}'
runs-on: '${{ matrix.config.os }}'
strategy:
matrix:
config:
- os: ubuntu-latest
kind: test_release
- os: ubuntu-latest
kind: test_debug
env:
CARGO_INCREMENTAL: 0
RUST_BACKTRACE: full
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: dsherret/rust-toolchain-file@3551321aa44dd44a0393eb3b6bdfbc5d25ecf621 # v1
- name: Install wasm32 target
if: matrix.config.kind == 'test_release'
run: rustup target add wasm32-unknown-unknown
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2
with:
save-if: '${{ github.ref == ''refs/heads/main'' }}'
- uses: denoland/setup-deno@667a34cdef165d8d2b2e98dde39547c9daac7282 # v2
with:
deno-version: v2.x
- name: Build debug
if: matrix.config.kind == 'test_debug'
run: cargo build
- name: Build release
if: matrix.config.kind == 'test_release'
run: cargo build --target wasm32-unknown-unknown --features wasm --release
- name: Test debug
if: matrix.config.kind == 'test_debug'
run: cargo test
- name: Test release
if: matrix.config.kind == 'test_release'
run: cargo test --release
- name: Get tag version
id: get_tag_version
if: 'matrix.config.kind == ''test_release'' && startsWith(github.ref, ''refs/tags/'')'
run: 'echo "TAG_VERSION=${GITHUB_REF/refs\/tags\//}" >> "$GITHUB_OUTPUT"'
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
if: matrix.config.kind == 'test_release'
with:
node-version: 24.x
registry-url: 'https://registry.npmjs.org'
- name: Setup and test npm deployment
if: matrix.config.kind == 'test_release'
run: |-
cd deployment/npm
npm install
node setup.js
npm run test
- name: Pre-release
if: 'matrix.config.kind == ''test_release'' && startsWith(github.ref, ''refs/tags/'')'
run: |-
# update config schema to have version
sed -i 's/dockerfile\/0.0.0/dockerfile\/${{ steps.get_tag_version.outputs.TAG_VERSION }}/' deployment/schema.json
# rename the wasm file
(cd target/wasm32-unknown-unknown/release/ && mv dprint_plugin_dockerfile.wasm plugin.wasm)
# create release notes
deno run -A ./scripts/generate_release_notes.ts ${{ steps.get_tag_version.outputs.TAG_VERSION }} > ${{ github.workspace }}-CHANGELOG.txt
- name: Release
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844
if: 'matrix.config.kind == ''test_release'' && startsWith(github.ref, ''refs/tags/'')'
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
with:
files: |-
target/wasm32-unknown-unknown/release/plugin.wasm
deployment/schema.json
body_path: '${{ github.workspace }}-CHANGELOG.txt'
draft: false
- name: Lint workflow generation
if: matrix.config.kind == 'test_debug'
run: |-
./.github/workflows/ci.ts --lint
./.github/workflows/publish.ts --lint
./.github/workflows/release.ts --lint
141 changes: 141 additions & 0 deletions .github/workflows/ci.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/usr/bin/env -S deno run -A
import { conditions, defineMatrix, expr, job, step, workflow } from "jsr:@david/gagen@^0.5.0";

const pluginName = "dockerfile";
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/generate_release_notes.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.ts --lint",
"./.github/workflows/release.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,
});
108 changes: 0 additions & 108 deletions .github/workflows/ci.yml

This file was deleted.

45 changes: 45 additions & 0 deletions .github/workflows/publish.generated.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# GENERATED BY ./publish.ts -- DO NOT DIRECTLY EDIT

name: publish
on:
workflow_dispatch: {}
push:
tags:
- '*'
permissions:
id-token: write
contents: read
jobs:
cargo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: dsherret/rust-toolchain-file@3551321aa44dd44a0393eb3b6bdfbc5d25ecf621 # v1
- id: auth
uses: rust-lang/crates-io-auth-action@b7e9a28eded4986ec6b1fa40eeee8f8f165559ec # v1
- name: Cargo publish
env:
CARGO_REGISTRY_TOKEN: '${{ steps.auth.outputs.token }}'
run: cargo publish
npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: dsherret/rust-toolchain-file@3551321aa44dd44a0393eb3b6bdfbc5d25ecf621 # v1
- name: Install wasm32 target
run: rustup target add wasm32-unknown-unknown
- name: Build release
run: cargo build --target wasm32-unknown-unknown --features wasm --release
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: 24.x
registry-url: 'https://registry.npmjs.org'
- name: Setup and test npm deployment
run: |-
cd deployment/npm
npm install
node setup.js sync-version
- name: npm publish
run: |-
cd deployment/npm
npm publish --access public
Loading