Skip to content
Merged
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
14 changes: 14 additions & 0 deletions .github/actions/ci-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Setup CI

runs:
using: composite
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".node-version"
cache: yarn

- name: Install dependencies
shell: bash
run: yarn install --frozen-lockfile
11 changes: 3 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Use Node.js 20
uses: actions/setup-node@v4
- uses: actions/checkout@v4
with:
node-version: 20.x
ref: ${{ github.event.pull_request.head.sha }}

- name: Install Dependencies
run: yarn --frozen-lockfile
- uses: ./.github/actions/ci-setup

- name: Typecheck
run: yarn typecheck
Expand Down
9 changes: 1 addition & 8 deletions .github/workflows/release-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
needs: release_check
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/ci-setup

- name: Checkout pull request
run: gh pr checkout ${{ github.event.issue.number }}
Expand All @@ -54,14 +55,6 @@ jobs:
if: steps.check_version_packages.outputs.version_packages == 'true'
run: git reset --hard HEAD~1

- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20.x

- name: Install Dependencies
run: yarn --frozen-lockfile

- run: yarn changeset version --snapshot pr${{ github.event.issue.number }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
12 changes: 2 additions & 10 deletions .github/workflows/version-or-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,8 @@ jobs:
changesets:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20.x

- name: Install Dependencies
run: yarn --frozen-lockfile
- uses: actions/checkout@v4
- uses: ./.github/actions/ci-setup

- name: Build
run: yarn build
Expand Down
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v22.9.0
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fuzzy on this. This repo only has to support one node version. I had issues using --experimental-strip-types on node 20 so I decided to use node 22 here - for dev workflows and on CI. But then only node 20 is currently supported for GitHub Actions (using: 'node22' doesn't work yet).

16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Current Test File",
"autoAttachChildProcesses": true,
"program": "${workspaceRoot}/node_modules/vitest/vitest.mjs",
"args": ["run", "${relativeFile}"],
"smartStep": true,
"console": "integratedTerminal"
}
]
}
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
"name": "@changesets/action",
"version": "1.5.2",
"main": "dist/index.js",
"type": "module",
"license": "MIT",
"devDependencies": {
"@changesets/changelog-github": "^0.4.2",
"@changesets/cli": "^2.20.0",
"@changesets/write": "^0.1.6",
"@changesets/changelog-github": "^0.5.1",
"@changesets/cli": "^2.29.3",
"@changesets/write": "^0.4.0",
"@types/node": "^22.15.17",
"@types/semver": "^7.5.0",
"esbuild": "^0.25.4",
Expand All @@ -17,14 +18,14 @@
"vitest": "^3.1.3"
},
"scripts": {
"build": "esbuild src/index.ts --bundle --platform=node --target=node20 --minify --outfile=dist/index.js",
"build": "esbuild src/index.ts --bundle --platform=node --target=node20 --format=esm --minify --outfile=dist/index.js",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory... this should be quite safe but then... who knows. Perhaps this should only land after testing this e2e in some repo. It feels like a somewhat risky change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used to migrate to esbuild & esm in my actions but reverted back due to some issues I've forgotten, so probably good to look out here too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn. That's not great :p I think I'll still try to run with it - but I have to definitely test it e2e first

"test": "vitest",
"test:watch": "yarn test --watch",
"typecheck": "tsc",
"changeset": "changeset",
"bump": "node ./scripts/bump.js",
"release": "node ./scripts/release.js",
"release:pr": "node ./scripts/release-pr.js"
"bump": "node --experimental-strip-types ./scripts/bump.ts",
"release": "node --experimental-strip-types ./scripts/release.ts",
"release:pr": "node --experimental-strip-types ./scripts/release-pr.ts"
},
"engines": {
"node": ">= 20"
Expand All @@ -34,16 +35,15 @@
"@actions/exec": "^1.1.1",
"@actions/github": "^6.0.1",
"@changesets/ghcommit": "^2.0.0",
"@changesets/pre": "^1.0.9",
"@changesets/read": "^0.5.3",
"@changesets/pre": "^2.0.2",
"@changesets/read": "^0.6.5",
"@manypkg/get-packages": "^1.1.3",
"@octokit/core": "^5.2.1",
"@octokit/plugin-throttling": "^8.0.0",
"@types/mdast": "^3.0.0",
"mdast-util-to-string": "^1.0.6",
"remark-parse": "^7.0.1",
"remark-stringify": "^7.0.3",
"resolve-from": "^5.0.0",
"semver": "^7.5.3",
"unified": "^8.3.2"
},
Expand Down
19 changes: 0 additions & 19 deletions scripts/bump.js

This file was deleted.

18 changes: 18 additions & 0 deletions scripts/bump.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { exec } from "@actions/exec";
import fs from "node:fs";
import path from "node:path";
import pkgJson from "../package.json" with { type: "json" };

process.chdir(path.join(import.meta.dirname, ".."));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only use import.meta.dirname in tests and script so far so it's fine anyway. But I wonder if there are any compatibility gotchas to consider if we'd use this in the code of the action itself.

I'm not sure what is the caveat the docs mention here:

Caveat: only present on file: modules.

Is that only that it wouldn't be present for modules imported/downloaded using HTTP(s) etc?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think that's what it means. On GitHub workflows the code should be ran as files though and shouldn't have this issue, though you need to account for it resolving from dist instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

though you need to account for it resolving from dist instead.

Good point. It's not an issue right now as we don't use it in src (and all files are nested directly in src too). But I'll keep that in mind as something to be more careful about.


await exec("changeset", ["version"]);

const releaseLine = `v${pkgJson.version.split(".")[0]}`;

const readmePath = path.join(import.meta.dirname, "..", "README.md");
const content = fs.readFileSync(readmePath, "utf8");
const updatedContent = content.replace(
/changesets\/action@[^\s]+/g,
`changesets/action@${releaseLine}`
);
fs.writeFileSync(readmePath, updatedContent);
21 changes: 0 additions & 21 deletions scripts/release-pr.js

This file was deleted.

20 changes: 20 additions & 0 deletions scripts/release-pr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { exec } from "@actions/exec";
import path from "node:path";

import pkgJson from "../package.json" with { type: "json" };

const tag = `v${pkgJson.version}`;
const releaseLine = "pr-release";

process.chdir(path.join(__dirname, ".."));

await exec("git", ["checkout", "--detach"]);
await exec("git", ["add", "--force", "dist"]);
await exec("git", ["commit", "-m", tag]);

await exec("git", [
"push",
"--force",
"origin",
`HEAD:refs/heads/${releaseLine}`,
]);
13 changes: 7 additions & 6 deletions scripts/release.js → scripts/release.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const path = require("path");
const { exec, getExecOutput } = require("@actions/exec");
import { exec, getExecOutput } from "@actions/exec";
import path from "node:path";

const { version } = require("../package.json");
const tag = `v${version}`;
const releaseLine = `v${version.split(".")[0]}`;
import pkgJson from "../package.json" with { type: "json" };

process.chdir(path.join(__dirname, ".."));
const tag = `v${pkgJson.version}`;
const releaseLine = `v${pkgJson.version.split(".")[0]}`;

process.chdir(path.join(import.meta.dirname, ".."));

(async () => {
const { exitCode, stderr } = await getExecOutput(
Expand Down
2 changes: 1 addition & 1 deletion src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as core from "@actions/core";
import { exec, getExecOutput } from "@actions/exec";
import * as github from "@actions/github";
import { commitChangesFromRepo } from "@changesets/ghcommit/git";
import { Octokit } from "./octokit";
import type { Octokit } from "./octokit.ts";

type GitOptions = {
cwd: string;
Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as core from "@actions/core";
import fs from "node:fs/promises";
import path from "node:path";
import { Git } from "./git";
import { setupOctokit } from "./octokit";
import readChangesetState from "./readChangesetState";
import { runPublish, runVersion } from "./run";
import { fileExists } from "./utils";
import { Git } from "./git.ts";
import { setupOctokit } from "./octokit.ts";
import readChangesetState from "./readChangesetState.ts";
import { runPublish, runVersion } from "./run.ts";
import { fileExists } from "./utils.ts";

const getOptionalInput = (name: string) => core.getInput(name) || undefined;

Expand Down
2 changes: 1 addition & 1 deletion src/readChangesetState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PreState, NewChangeset } from "@changesets/types";
import type { PreState, NewChangeset } from "@changesets/types";
import { readPreState } from "@changesets/pre";
import readChangesets from "@changesets/read";

Expand Down
14 changes: 7 additions & 7 deletions src/run.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Changeset } from "@changesets/types";
import type { Changeset } from "@changesets/types";
import writeChangeset from "@changesets/write";
import fixturez from "fixturez";
import fs from "node:fs/promises";
import path from "node:path";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { Git } from "./git";
import { setupOctokit } from "./octokit";
import { runVersion } from "./run";
import { Git } from "./git.ts";
import { setupOctokit } from "./octokit.ts";
import { runVersion } from "./run.ts";

vi.mock("@actions/github", () => ({
context: {
Expand All @@ -21,7 +21,7 @@ vi.mock("@actions/github", () => ({
rest: mockedGithubMethods,
}),
}));
vi.mock("./git");
vi.mock("./git.ts");
vi.mock("@changesets/ghcommit/git");

let mockedGithubMethods = {
Expand All @@ -34,11 +34,11 @@ let mockedGithubMethods = {
},
};

let f = fixturez(__dirname);
let f = fixturez(import.meta.dirname);

const linkNodeModules = async (cwd: string) => {
await fs.symlink(
path.join(__dirname, "..", "node_modules"),
path.join(import.meta.dirname, "..", "node_modules"),
path.join(cwd, "node_modules")
);
};
Expand Down
37 changes: 25 additions & 12 deletions src/run.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import * as core from "@actions/core";
import { exec, getExecOutput } from "@actions/exec";
import * as github from "@actions/github";
import { PreState } from "@changesets/types";
import { Package, getPackages } from "@manypkg/get-packages";
import type { PreState } from "@changesets/types";
import { type Package, getPackages } from "@manypkg/get-packages";
import fs from "node:fs/promises";
import { createRequire } from "node:module";
import path from "node:path";
import resolveFrom from "resolve-from";
import semverLt from "semver/functions/lt";
import { Git } from "./git";
import { Octokit } from "./octokit";
import readChangesetState from "./readChangesetState";
import semverLt from "semver/functions/lt.js";
import { Git } from "./git.ts";
import type { Octokit } from "./octokit.ts";
import readChangesetState from "./readChangesetState.ts";
import {
getChangedPackages,
getChangelogEntry,
getVersionsByDirectory,
isErrorWithCode,
sortTheThings,
} from "./utils";
} from "./utils.ts";

const require = createRequire(import.meta.url);

// GitHub Issues/PRs messages have a max size limit on the
// message body payload.
Expand Down Expand Up @@ -162,7 +164,9 @@ export async function runPublish({

const requireChangesetsCliPkgJson = (cwd: string) => {
try {
return require(resolveFrom(cwd, "@changesets/cli/package.json"));
return require(require.resolve("@changesets/cli/package.json", {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we were using resolveFrom. require.resolve supported this for a long time already. It also just seems like using require here is an easier option than dancing around this using import-meta-resolve.

paths: [cwd],
}));
} catch (err) {
if (isErrorWithCode(err, "MODULE_NOT_FOUND")) {
throw new Error(
Expand Down Expand Up @@ -286,9 +290,18 @@ export async function runVersion({
let cmd = semverLt(changesetsCliPkgJson.version, "2.0.0")
? "bump"
: "version";
await exec("node", [resolveFrom(cwd, "@changesets/cli/bin.js"), cmd], {
cwd,
});
await exec(
"node",
[
require.resolve("@changesets/cli/bin.js", {
paths: [cwd],
}),
cmd,
],
{
cwd,
}
);
}

let changedPackages = await getChangedPackages(cwd, versionsByDirectory);
Expand Down
2 changes: 1 addition & 1 deletion src/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from "vitest";
import { BumpLevels, getChangelogEntry, sortTheThings } from "./utils";
import { BumpLevels, getChangelogEntry, sortTheThings } from "./utils.ts";

let changelog = `# @keystone-alpha/email

Expand Down
Loading