Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esm + tests #20

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
16 changes: 16 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/** @type {import('eslint').Linter.Config} */
module.exports = {
extends: [
"@remix-run/eslint-config",
"@remix-run/eslint-config/node",
"@remix-run/eslint-config/internal",
],
// We're using vitest which has a very similar API to jest
// (so the linting plugins work nicely), but we have to
// set the jest version explicitly.
settings: {
jest: {
version: 28,
},
},
};
8 changes: 0 additions & 8 deletions .eslintrc.js

This file was deleted.

10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: build and commit
name: 📦 Build

on:
push:
Expand All @@ -12,12 +12,18 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: write

jobs:
build:
name: 📦 Build
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: ⎔ Setup node
uses: actions/setup-node@v3
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ concurrency:
jobs:
format:
if: github.repository == 'remix-run/release-comment-action'
name: 👔 Format
runs-on: ubuntu-latest

steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: 🟧 Setup pnpm
uses: pnpm/action-setup@v2
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Lint
name: 🔬 Lint

on:
push:
Expand All @@ -12,11 +12,12 @@ concurrency:

jobs:
lint:
name: ⬣ Lint
if: github.repository == 'remix-run/release-comment-action'
name: 🔬 Lint
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: 🟧 Setup pnpm
uses: pnpm/action-setup@v2
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/no-response.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
stale:
if: github.repository == 'remix-run/release-comment-action'
runs-on: ubuntu-latest
name: 🥺 Handle Ghosting
steps:
- name: 🥺 Handle Ghosting
uses: actions/stale@v8
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ concurrency:

jobs:
comment:
name: Comment on Release
name: 📝 Comment on Release
if: github.repository == 'remix-run/release-comment-action'
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: 📝 Comment on issues
- name: 📝 Comment on Release
uses: ./
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: 🧪 Test

on:
push:
branches:
- main
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
name: 🧪 Test
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v4

- name: 🟧 Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8
run_install: |
- recursive: true
args: [--frozen-lockfile, --strict-peer-dependencies]

- name: 🧪 Test
run: pnpm run test
env:
GH_TOKEN: ${{ github.token }}
74 changes: 74 additions & 0 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import type { SyncOptions } from "execa";
import { execaSync } from "execa";
import { afterAll, beforeAll, expect, test } from "vitest";

import { findMergedPRs, getCommits, getTags } from "../src/lib.js";

//////////////////////////////////////////////// SET UP ////////////////////////////////////////////////
let OWNER = `remix-run` as const;
let REPO = `remix` as const;
let REPOSITORY = `${OWNER}/${REPO}` as const;
let PACKAGE_TO_TRACK = `remix` as const;
let RANDOM_STRING = Math.random().toString(36).substring(7);
let TMP_DIR = `${REPO}-${RANDOM_STRING}`;

let cwd: string;

beforeAll(() => {
let execaOptions: SyncOptions = { stdio: "inherit" };
let cloneArgs = ["clone", `https://github.com/${REPOSITORY}`, TMP_DIR];
let fetchArgs = ["fetch", "--tags"];
// clone the repo
execaSync("git", cloneArgs, execaOptions);
// fetch git tags
execaSync("git", fetchArgs, execaOptions);
cwd = process.cwd();
process.chdir(TMP_DIR);

let currentDate = new Date("2023-09-21T23:31:48.180Z");

// remove tags prior to 2.0.1
let tagsToRemove = execaSync("git", [
"tag",
"-l",
"--sort",
"-creatordate",
"--format",
"%(refname:strip=2) %(taggerdate)",
])
.stdout.split("\n")
.filter((line) => {
let [, tagTag] = line.split(" ");
let date = new Date(tagTag);
return date < currentDate;
});

for (let tag of tagsToRemove) {
console.log(`removing tag ${tag}`);
execaSync("git", ["tag", "-d", tag]);
}
});

afterAll(() => {
process.chdir(cwd);
execaSync("rm", ["-rf", TMP_DIR], { stdio: "inherit" });
});

//////////////////////////////////////////////// TESTS ////////////////////////////////////////////////
test("the whole shooting match", async () => {
let tags = await getTags(PACKAGE_TO_TRACK, false);

expect(tags).toEqual({
latest: { raw: `[email protected]`, clean: `2.0.1` },
previous: { raw: `[email protected]`, clean: `2.0.0` },
isNightly: false,
isStable: true,
isPreRelease: false,
});

let commits = await getCommits(tags.previous, tags.latest, "./packages");
expect(commits).toHaveLength(22);

let prs = await findMergedPRs(commits);
expect(prs).toHaveLength(16);
});
3 changes: 3 additions & 0 deletions __tests__/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// first mark the test as dry run so we don't interact with the GitHub API
// TODO: look into adding msw to mock the API calls
process.env.INPUT_DRY_RUN = "TRUE";
31 changes: 18 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,34 @@
"version": "0.4.1",
"description": "",
"main": "index.js",
"module": "index.js",
"type": "module",
"scripts": {
"build": "ncc build src/index.ts --license licenses.txt",
"lint": "eslint --cache --fix --ignore-path .eslintignore .",
"format": "prettier --write --ignore-path .eslintignore ."
"format": "prettier --write --ignore-path .eslintignore .",
"test": "vitest --no-threads run"
},
"author": "Logan McAnsh <[email protected]> (https://mcan.sh/)",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.10.0",
"execa": "^7.1.1",
"semver": "^7.5.2",
"@actions/core": "^1.10.1",
"execa": "^8.0.1",
"semver": "^7.5.4",
"trim-newlines": "^5.0.0",
"zod": "^3.21.4"
"zod": "^3.22.2"
},
"devDependencies": {
"@remix-run/eslint-config": "^1.16.0",
"@tsconfig/node16": "^1.0.3",
"@types/node": "^18.16.3",
"@types/semver": "^7.3.13",
"@vercel/ncc": "^0.36.1",
"eslint": "^8.39.0",
"@remix-run/eslint-config": "^2.0.0",
"@tsconfig/node16": "^16.1.1",
"@types/node": "^20.6.2",
"@types/semver": "^7.5.2",
"@vercel/ncc": "^0.38.0",
"eslint": "^8.49.0",
"eslint-plugin-prefer-let": "^3.0.1",
"prettier": "^2.8.8",
"typescript": "^5.0.4"
"prettier": "^3.0.3",
"typescript": "^5.2.2",
"vite": "^4.4.9",
"vitest": "^0.34.5"
}
}
Loading