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

Rewrite in ReScript #97

Merged
merged 111 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
a5294a5
Blindly convert `.ts` files to `.mjs`
brettcannon Jan 8, 2024
a0b1331
Move from Jest to Vitest
brettcannon Jan 9, 2024
9a02679
Fix formatting
brettcannon Jan 9, 2024
48426d1
Set up eslint to use modules
brettcannon Jan 9, 2024
87639ce
Drop `tsconfig.json`
brettcannon Jan 9, 2024
a2cac0a
Tweak command used to run vitest
brettcannon Jan 9, 2024
17a6ba1
Update config for ECMAScript version appropriate to Node 20
brettcannon Jan 9, 2024
ac619d5
Update `package-lock.json`
brettcannon Mar 22, 2024
2b266ea
Drop the `build` step of CI
brettcannon Mar 23, 2024
5ae9fc8
Bump to @vercel/ncc to 0.38.1
brettcannon Mar 23, 2024
9025ec7
Rename `index.mjs` to `index.js` to try and deal with an ncc problem …
brettcannon Mar 23, 2024
3bd8c66
Try not specifying the module type
brettcannon Mar 23, 2024
8914dcc
Move back to `index.mjs`
brettcannon Mar 23, 2024
ccd0c63
Minify ncc output
brettcannon Mar 23, 2024
a2cbc57
Use file extensions in imports
brettcannon Mar 23, 2024
7c9c2dd
Try moving to esbuild for bundling
brettcannon Mar 23, 2024
57497d7
Rename output file
brettcannon Mar 23, 2024
b62365e
Explicitly move to `dist/index.js`
brettcannon Mar 23, 2024
8b34e12
Don't explicitly say everything is a module
brettcannon Mar 23, 2024
fdacb92
Upgrade http-client
brettcannon Mar 23, 2024
190dee6
Specify the default glob pattern at the action level instead of the J…
brettcannon Apr 28, 2024
1b19d6d
Run `npm create rescript-app` and clean up `npm run` commands
brettcannon Apr 28, 2024
b14d28b
Remove some dead code due to moving default glob to `action.yml`
brettcannon Apr 28, 2024
5be604a
Merge branch 'rewrite/mjs' into rewrite/res
brettcannon Apr 28, 2024
2858137
Check for `.mjs` changes in PRs
brettcannon Apr 28, 2024
3bea908
Merge branch 'rewrite/mjs' into rewrite/res
brettcannon Apr 28, 2024
028af05
Check for changed `.res` files in PRs
brettcannon Apr 28, 2024
190d74b
Drop some lingering TS settings
brettcannon Apr 28, 2024
ce0f41c
Merge branch 'rewrite/mjs' into rewrite/res
brettcannon Apr 28, 2024
927732d
Add a task for launching the compile watching task
brettcannon Apr 28, 2024
ae13751
Run `npm run res:dev` on folder open via a task
brettcannon Apr 28, 2024
00dfcc5
Have the ReScript extension handle the builds
brettcannon Apr 29, 2024
83a0314
Delete the empty `tasks.json`
brettcannon Apr 29, 2024
bb9f429
Raw copy `matching.mjs` to `Matching.res`
brettcannon Apr 29, 2024
45a4823
Port `Matching.hasLabelMatch` to ReScript
brettcannon Apr 29, 2024
baeb092
Finish porting to `Matching.res`
brettcannon Apr 29, 2024
7d0b627
Copy `gh.mjs` over to `GH.res`
brettcannon Apr 30, 2024
72fec07
Port more of `GH.res` to ReScript
brettcannon Apr 30, 2024
8a6c877
Drop large block of `%%raw` from `GH.mjs`
brettcannon Apr 30, 2024
0fb8176
Remove ported `.mjs` files
brettcannon Apr 30, 2024
64fdf0a
Port `index.mjs` to ReScript
brettcannon Apr 30, 2024
f0ceb7c
Drop ported `index.mjs`
brettcannon Apr 30, 2024
d3457d9
Reformat `rescript.json`
brettcannon Apr 30, 2024
d7da6cd
Copy `main.mjs` into `Main.res`
brettcannon Apr 30, 2024
291f11e
Add a note about `Main.main()` not being declared async
brettcannon Apr 30, 2024
a107e03
Move isolated code out to ReScript
brettcannon Apr 30, 2024
08f2dcb
List more things to eventually clean up
brettcannon Apr 30, 2024
a8fe80b
Finish porting `main.mjs` to `Main.res`
brettcannon May 1, 2024
2cbaefc
Update what runs on CI
brettcannon May 2, 2024
f2ed1aa
Fix YAML
brettcannon May 2, 2024
ad0e064
Fix flags for tormat checking
brettcannon May 2, 2024
8bc11a1
Compile ReScript before running tests
brettcannon May 2, 2024
6af6558
Fix commands to run for testing
brettcannon May 2, 2024
0b29e43
Fix typo
brettcannon May 2, 2024
5d7af99
Drop testing
brettcannon May 2, 2024
87e02d6
Try to fix scoping
brettcannon May 2, 2024
e34f1d1
Make types from `external` much tighter
brettcannon May 2, 2024
b042b4e
Touch up comments
brettcannon May 2, 2024
f71ffa5
Turn `GH.payloadType` into an object to differentiate from `GH.prPayl…
brettcannon May 2, 2024
5cd125d
Use an opaque/abstract type for Octokit objects
brettcannon May 3, 2024
e4ea374
Set up testing using rescript-zora
brettcannon May 5, 2024
57add31
Port `Matching` tests to rescript-zora
brettcannon May 5, 2024
8bdda08
Run tests on CI
brettcannon May 5, 2024
d44034b
Build `.res` files for tests
brettcannon May 5, 2024
a87b9fa
Write tests for defaults found in `action.yml`
brettcannon May 5, 2024
a8184bf
Tweak how to check for files that weren't formatted
brettcannon May 7, 2024
73a941b
Test format change detection in GHA
brettcannon May 7, 2024
bc6ab7b
Fix formatting
brettcannon May 7, 2024
62c65db
Thorough tweak to format check in CI
brettcannon May 9, 2024
dca9824
Start of tests for `GH.pullRequestPayload()`
brettcannon May 9, 2024
7df2661
Fix attribute name
brettcannon May 9, 2024
530ac21
Set up `tasks.json` to build and test things
brettcannon May 9, 2024
895a014
Finish writing tests for `GH.pullRequestPayload()`
brettcannon May 10, 2024
a96768c
Simplify some test code by pulling out shared variables
brettcannon May 10, 2024
1f82e04
Add tests for `GH.pullRequestLabels()`
brettcannon May 11, 2024
907c633
Add a comment
brettcannon May 11, 2024
b50ba13
Set up file watching for test execution using `watchexec-cli`
brettcannon May 11, 2024
98cb863
Add a watching task that runs builds and then tests
brettcannon May 11, 2024
8b6c873
Make test watching more thorough and accurate
brettcannon May 11, 2024
57b8bb6
Simplify tasks.json
brettcannon May 11, 2024
869f0e2
Normalize names of tasks/scripts/commands
brettcannon May 11, 2024
0a7dc1c
Update `index.js`
brettcannon May 11, 2024
b2b1094
Write tests for `Main.formatFailureMessage()`
brettcannon May 13, 2024
245fc9f
Refactor `Main.res` for easier testing in the future
brettcannon May 13, 2024
2429e02
Refactor `Main.res` for easier testing in the future
brettcannon May 13, 2024
6082326
Merge branch 'rewrite/res' of github.com:brettcannon/check-for-change…
brettcannon May 13, 2024
b4d2b74
Add a comment
brettcannon May 13, 2024
e91a35c
More refactorings to make testing easier for `Main.res`
brettcannon May 15, 2024
7b673d7
Move over to a `result`-based flow
brettcannon May 16, 2024
1332d1e
Make sure all inputs either are required or have a default value
brettcannon May 17, 2024
da87617
Explicitly close `action.yml` file handle in `Action_test.res`
brettcannon May 17, 2024
1b920b3
Add `Action.resi` so that key names are more controlled for inputs
brettcannon May 17, 2024
5858248
Outline tests to write
brettcannon May 17, 2024
39edd81
Test when the payload isn't for a pull request
brettcannon May 17, 2024
ee0e061
Test for when a skip label is set
brettcannon May 18, 2024
0f44711
Add a test for the prerequisite pattern not matching
brettcannon May 18, 2024
18517d8
Add a comment
brettcannon May 18, 2024
6797580
Write a test for when the check fails
brettcannon May 18, 2024
d4f6ad7
Inline a function
brettcannon May 18, 2024
f991e54
Change how `getInput` is kept private
brettcannon May 19, 2024
56d2caf
More idiomatic code for `Matching.res`
brettcannon May 19, 2024
ffe662c
Add more tests for `action.yml`
brettcannon May 19, 2024
dcd2c40
Make `Action.res` more idiomatic
brettcannon May 19, 2024
fc7c433
Make `GH.res` more idiomatic
brettcannon May 20, 2024
ff07b61
Tweak a comment
brettcannon May 20, 2024
24cbd66
Use currying
brettcannon May 20, 2024
e1498b5
Add a check that when `action.yml` changes so does `README.md`
brettcannon May 22, 2024
ad8213f
Not what inputs are optional in the README
brettcannon May 22, 2024
0562fcc
Tweak a job name
brettcannon May 22, 2024
2c1664a
Temp step to verify skip labels still work
brettcannon May 22, 2024
2ec1c95
Remove temp test step
brettcannon May 22, 2024
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
20 changes: 12 additions & 8 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["jest", "@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"env": { "node": true, "jest/globals": true }
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2023, // https://node.green/#ES2023
"ecmaFeatures": {
"impliedStrict": true
}
},
"extends": ["eslint:recommended", "prettier"],
"env": {
"node": true,
"es2023": true // https://node.green/#ES2023
}
}
42 changes: 28 additions & 14 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ name: PR status checks

jobs:
lint:
name: Lint
name: Formatting
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -19,25 +19,32 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: "20"
- run: npm ci
- run: npm ci --include dev
- run: npm run format
- name: Check if any files changed
run: if [ -n "$(git status --untracked-files --porcelain)" ]; then (exit 1); fi
shell: bash

test:
name: Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install node
uses: actions/setup-node@v4
with:
node-version: "20"
- run: npm ci --include dev
- run: npm run build
- run: npm run lint
- run: npm run format-check
- run: npm run test

dogfood:
name: Dogfood the action
name: Dogfooding
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # To run the version of the action from the PR.

- name: package*.json updated
uses: ./
with:
file-pattern: |
package.json
package-lock.json
skip-label: "skip package*.json"

- name: package-lock.json updated
uses: ./
with:
Expand All @@ -48,6 +55,13 @@ jobs:
- name: dist/index.js updated
uses: ./
with:
prereq-pattern: "src/*.ts"
prereq-pattern: "src/*.res"
file-pattern: "dist/index.js"
skip-label: "skip packaging"

- name: README.md updated
uses: ./
with:
prereq-pattern: "action.yml"
file-pattern: "README.md"
skip-label: "skip README"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,7 @@ typings/

# Files built by tsc
out/

/lib/
.bsb.lock
**/*.res.mjs
21 changes: 1 addition & 20 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
{
"[javascript]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[markdown]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[yaml]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
"rescript.settings.askToStartBuild": false
}
40 changes: 26 additions & 14 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "typescript",
"tsconfig": "tsconfig.json",
"option": "watch",
"problemMatcher": ["$tsc-watch"],
"group": {
"kind": "build",
"isDefault": true
},
"label": "tsc: watch - tsconfig.json"
}
]
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "build",
"problemMatcher": [],
"label": "npm: build",
"detail": "rescript build",
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "npm",
"script": "test",
"dependsOn": "npm: build",
"group": {
"kind": "test",
"isDefault": true
},
"problemMatcher": [],
"label": "npm: test",
"detail": "pta tests/*.mjs"
}
]
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ file-pattern: |
acts as two patterns: `package.json` and `package-lock.json`. Success occurs if
_any_ of the patterns match.

### `prereq-pattern`
### `prereq-pattern` (optional)

A pre-requisite glob pattern that, if specified, will cause the action to proceed
only if the pattern matches. If a match isn't found then the action is considered
Expand All @@ -31,17 +31,17 @@ successful.
See the notes about patterns for `file-pattern` for details on how matching
occurs and the flexibility in specifying the pattern.

### `skip-label`
### `skip-label` (optional)

The name of a label to forcibly skip the changed file check.

### `failure-message`
### `failure-message` (optional)

The message to emit when the check fails. All other inputs can be specified in
the message using `${}` syntax, e.g. `${file-pattern}` for the `file-pattern`
input. All values will be quoted for easy identification of any whitespace.

### `token`
### `token` (optional)

A GitHub auth token to use for private repositories. Falls back to anonymous access if
not provided. Usually you want to use `${{ secrets.GITHUB_TOKEN }}` for this.
Expand Down
25 changes: 15 additions & 10 deletions __tests__/gh.test.ts → __tests__/gh.test.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { ImportMock } from "ts-mock-imports";
import * as github from "@actions/github";
import * as gh from "../src/gh";
import {
afterAll,
afterEach,
beforeEach,
describe,
expect,
test,
vi,
} from "vitest";
import * as gh from "../src/GH.res.mjs";

test("gh.pullRequestEvent() return undefined by default", () => {
expect(gh.pullRequestPayload()).toBeUndefined();
Expand All @@ -15,12 +23,10 @@ describe("Stub github.context w/ a pull_request payload", () => {
},
};

beforeEach(() => {
ImportMock.mockOther(github, "context", context);
});
afterEach(() => ImportMock.restore());
afterEach(() => vi.restoreAllMocks());

test("pull_request context is returned by gh.pullRequestEvent()", () => {
vi.spyOn(github, "context", "get").mockReturnValue(context);
expect(gh.pullRequestPayload()).toEqual(context.payload);
});
});
Expand All @@ -33,12 +39,11 @@ describe("Stub github.context w/ a 'push' payload", () => {
repository: { name: "test", owner: { login: "anonymous" } },
},
};
beforeEach(() => {
ImportMock.mockOther(github, "context", context);
});
afterEach(() => ImportMock.restore());

afterEach(() => vi.restoreAllMocks());

test("'undefined' is returned by gh.pullRequestEvent()", () => {
vi.spyOn(github, "context", "get").mockReturnValue(context);
expect(gh.pullRequestPayload()).toBeUndefined();
});
});
3 changes: 2 additions & 1 deletion __tests__/main.test.ts → __tests__/main.test.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as main from "../src/main";
import { describe, expect, test } from "vitest";
import * as main from "../src/Main.res.mjs";

describe("repr()", () => {
test("output quotes strings", () => {
Expand Down
83 changes: 0 additions & 83 deletions __tests__/matching.test.ts

This file was deleted.

2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ inputs:
prereq-pattern:
description: "Glob pattern that guards whether the action will run"
required: false
default: "**"
skip-label:
description: "Label to trigger skipping the check"
required: false
default: ""
failure-message:
description: "String template used when the check fails"
required: false
Expand Down
Loading
Loading