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
50 changes: 16 additions & 34 deletions .github/workflows/ci.generated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,19 @@ jobs:
- build
if: 'startsWith(github.ref, ''refs/tags/'')'
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Download artifacts
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
- uses: denoland/setup-deno@667a34cdef165d8d2b2e98dde39547c9daac7282 # v2
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: 22.x
registry-url: 'https://registry.npmjs.org'
- name: Move downloaded artifacts to root directory
run: |-
mv x86_64-apple-darwin-artifacts/dprint-plugin-prettier-x86_64-apple-darwin.zip .
Expand All @@ -204,6 +211,10 @@ jobs:
- name: Get plugin file checksum
id: get_plugin_file_checksum
run: 'echo "CHECKSUM=$(shasum -a 256 plugin.json | awk ''{print $1}'')" >> $GITHUB_OUTPUT'
- name: Build npm packages
run: deno run -A scripts/create_npm_packages.ts
- name: Create release notes
run: 'deno run -A ./scripts/generate_release_notes.ts ${{ steps.get_prettier_version.outputs.PRETTIER_VERSION }} ${{ steps.get_tag_version.outputs.TAG_VERSION }} ${{ steps.get_plugin_file_checksum.outputs.CHECKSUM }} > ${{ github.workspace }}-CHANGELOG.txt'
- name: Release
uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 # v2
env:
Expand All @@ -216,38 +227,9 @@ jobs:
dprint-plugin-prettier-x86_64-unknown-linux-gnu.zip
dprint-plugin-prettier-aarch64-unknown-linux-gnu.zip
plugin.json
body: |
Prettier ${{ steps.get_prettier_version.outputs.PRETTIER_VERSION }}
## Install

Dependencies:

- Install dprint's CLI >= 0.40.0
- Create a config file via `dprint init`

Then:

1. Run `dprint add prettier`, which will update the config file like so:

```jsonc
{
// etc...
"plugins": [
// ...add other dprint plugins here that you want to take precedence over prettier...
"https://plugins.dprint.dev/prettier-${{ steps.get_tag_version.outputs.TAG_VERSION }}.json@${{ steps.get_plugin_file_checksum.outputs.CHECKSUM }}"
]
}
```
2. Add a `"prettier"` configuration property if desired.

```jsonc
{
// ...etc...
"prettier": {
"trailingComma": "all",
"singleQuote": true,
"proseWrap": "always"
}
}
```
body_path: '${{ github.workspace }}-CHANGELOG.txt'
draft: false
- name: Upgrade npm
run: npm install --global npm@latest
- name: Publish npm packages
run: deno run -A scripts/publish_npm_packages.ts
61 changes: 27 additions & 34 deletions .github/workflows/ci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,16 @@ const draftReleaseJob = job("draft_release", {
if: isTag,
needs: [buildJob],
runsOn: "ubuntu-latest",
// id-token: write is required for npm --provenance
permissions: { contents: "write", "id-token": "write" },
steps: [
{ name: "Checkout", uses: "actions/checkout@v4" },
{ name: "Download artifacts", uses: "actions/download-artifact@v4" },
{ uses: "denoland/setup-deno@v2" },
{
uses: "actions/setup-node@v4",
with: { "node-version": "22.x", "registry-url": "https://registry.npmjs.org" },
},
{
name: "Move downloaded artifacts to root directory",
run: profiles.map((profile) => `mv ${profile.artifactsName}/${profile.zipFileName} .`),
Expand All @@ -261,6 +267,17 @@ const draftReleaseJob = job("draft_release", {
getPrettierVersion,
getTagVersion,
getPluginFileChecksum,
{
// must run before "Create release notes" — the notes embed the main
// npm tarball's sha256 from npm-dist/publish-manifest.json.
name: "Build npm packages",
run: "deno run -A scripts/create_npm_packages.ts",
},
{
name: "Create release notes",
run:
`deno run -A ./scripts/generate_release_notes.ts ${getPrettierVersion.outputs.PRETTIER_VERSION} ${getTagVersion.outputs.TAG_VERSION} ${getPluginFileChecksum.outputs.CHECKSUM} > \${{ github.workspace }}-CHANGELOG.txt`,
},
{
name: "Release",
uses: "softprops/action-gh-release@v2",
Expand All @@ -270,43 +287,19 @@ const draftReleaseJob = job("draft_release", {
...profiles.map((profile) => profile.zipFileName),
"plugin.json",
].join("\n"),
body: `Prettier ${getPrettierVersion.outputs.PRETTIER_VERSION}
## Install

Dependencies:

- Install dprint's CLI >= 0.40.0
- Create a config file via \`dprint init\`

Then:

1. Run \`dprint add prettier\`, which will update the config file like so:

\`\`\`jsonc
{
// etc...
"plugins": [
// ...add other dprint plugins here that you want to take precedence over prettier...
"https://plugins.dprint.dev/prettier-${getTagVersion.outputs.TAG_VERSION}.json@${getPluginFileChecksum.outputs.CHECKSUM}"
]
}
\`\`\`
2. Add a \`"prettier"\` configuration property if desired.

\`\`\`jsonc
{
// ...etc...
"prettier": {
"trailingComma": "all",
"singleQuote": true,
"proseWrap": "always"
}
}
\`\`\`
`,
body_path: "${{ github.workspace }}-CHANGELOG.txt",
draft: false,
},
},
{
// npm trusted publishing (OIDC) requires npm >= 11.5.1.
name: "Upgrade npm",
run: "npm install --global npm@latest",
},
{
name: "Publish npm packages",
run: "deno run -A scripts/publish_npm_packages.ts",
},
],
});

Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
},
"imports": {
"@david/gagen": "jsr:@david/gagen@^0.5.0",
"@dprint/automation": "jsr:@dprint/automation@^0.10.3",
"@dprint/automation": "jsr:@dprint/automation@^0.11.2",
"dax": "jsr:@david/dax@0.45",
"@std/semver": "jsr:@std/semver@1",
"@std/yaml": "jsr:@std/yaml@1"
Expand Down
79 changes: 1 addition & 78 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions scripts/create_npm_packages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env -S deno run -A
import { CargoToml, getChecksum, processPlugin } from "@dprint/automation";
import $ from "dax";

const pluginName = "dprint-plugin-prettier";
const mainPackageName = "@dprint/prettier";
const outDir = "npm-dist";
// where the platform zips are extracted before being repacked as npm sub-packages.
const extractDir = "npm-binaries";

const platforms: processPlugin.Platform[] = [
"darwin-x86_64",
"darwin-aarch64",
"linux-x86_64",
"linux-aarch64",
"windows-x86_64",
];

const rootDir = $.path(import.meta.dirname!).parentOrThrow();
const version = new CargoToml(rootDir.join("plugin/Cargo.toml")).version();

const extractRoot = rootDir.join(extractDir);
extractRoot.mkdirSync({ recursive: true });

const platformInputs = await Promise.all(platforms.map(async (platform) => {
const zipPath = rootDir.join(
processPlugin.getStandardZipFileName(pluginName, platform),
);
const platformDir = extractRoot.join(platform);
platformDir.mkdirSync({ recursive: true });
await $`unzip -o ${zipPath.toString()} -d ${platformDir.toString()}`.quiet();
const binaryName = platform.startsWith("windows-") ? `${pluginName}.exe` : pluginName;
return {
platform,
binaryPath: platformDir.join(binaryName).toString(),
};
}));

const result = await processPlugin.createDprintOrgNpmPackages({
pluginName,
mainPackageName,
version,
outDir: rootDir.join(outDir).toString(),
platforms: platformInputs,
packageJsonExtra: {
description: "Use Prettier as a dprint plugin to format code.",
license: "MIT",
repository: {
type: "git",
url: "git+https://github.com/dprint/dprint-plugin-prettier.git",
},
homepage: "https://github.com/dprint/dprint-plugin-prettier",
},
});

// hash the main tarball so the release-notes step can embed it in the
// `npm:@dprint/prettier@<version>/plugin.json@<hash>` reference users paste
// into dprint.json. This is the hash dprint verifies before extracting.
const mainPackageChecksum = await getChecksum(await Deno.readFile(result.mainPackageTarball));

// emit a manifest so publish_npm_packages.ts knows the order and which
// tarballs to publish without having to re-derive it from the directory.
await Deno.writeTextFile(
rootDir.join(outDir, "publish-manifest.json").toString(),
JSON.stringify(
{
mainPackageName,
version,
subPackageTarballs: result.subPackageTarballs,
mainPackageTarball: result.mainPackageTarball,
mainPackageChecksum,
},
undefined,
2,
) + "\n",
);

console.log("Main package tarball:", result.mainPackageTarball);
console.log("Sub-package tarballs:");
for (const tgz of result.subPackageTarballs) {
console.log(" " + tgz);
}
Loading
Loading