Skip to content

Commit 0ce29b3

Browse files
committed
Refactor the scaffolding to use modrn action structure
Based on current structure in https://github.com/actions/typescript-action This uses [ncc](https://github.com/zeit/ncc) to build a self-contained distribution folder which avoids having to mess around with checking-in the `node_modules/` folder. This will also allow starting a new mainline 1.2 with releases cut from the master branch and avoid duplicating commits between v1 branch and master.
1 parent 98e5837 commit 0ce29b3

22 files changed

+17025
-3275
lines changed

.eslintignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist/
2+
lib/
3+
node_modules/

.eslintrc.json

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"plugins": ["jest", "@typescript-eslint"],
3+
"extends": ["plugin:github/recommended"],
4+
"parser": "@typescript-eslint/parser",
5+
"parserOptions": {
6+
"ecmaVersion": 9,
7+
"sourceType": "module",
8+
"project": "./tsconfig.json"
9+
},
10+
"rules": {
11+
"eslint-comments/no-use": "off",
12+
"import/no-namespace": "off",
13+
"no-unused-vars": "off",
14+
"@typescript-eslint/no-unused-vars": "error",
15+
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
16+
"@typescript-eslint/no-require-imports": "error",
17+
"@typescript-eslint/array-type": "error",
18+
"@typescript-eslint/await-thenable": "error",
19+
"@typescript-eslint/ban-ts-comment": "error",
20+
"camelcase": "off",
21+
"@typescript-eslint/consistent-type-assertions": "error",
22+
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
23+
"@typescript-eslint/func-call-spacing": ["error", "never"],
24+
"@typescript-eslint/no-array-constructor": "error",
25+
"@typescript-eslint/no-empty-interface": "error",
26+
"@typescript-eslint/no-explicit-any": "error",
27+
"@typescript-eslint/no-extraneous-class": "error",
28+
"@typescript-eslint/no-for-in-array": "error",
29+
"@typescript-eslint/no-inferrable-types": "error",
30+
"@typescript-eslint/no-misused-new": "error",
31+
"@typescript-eslint/no-namespace": "error",
32+
"@typescript-eslint/no-non-null-assertion": "warn",
33+
"@typescript-eslint/no-unnecessary-qualifier": "error",
34+
"@typescript-eslint/no-unnecessary-type-assertion": "error",
35+
"@typescript-eslint/no-useless-constructor": "error",
36+
"@typescript-eslint/no-var-requires": "error",
37+
"@typescript-eslint/prefer-for-of": "warn",
38+
"@typescript-eslint/prefer-function-type": "warn",
39+
"@typescript-eslint/prefer-includes": "error",
40+
"@typescript-eslint/prefer-string-starts-ends-with": "error",
41+
"@typescript-eslint/promise-function-async": "error",
42+
"@typescript-eslint/require-array-sort-compare": "error",
43+
"@typescript-eslint/restrict-plus-operands": "error",
44+
"semi": "off",
45+
"@typescript-eslint/semi": ["error", "never"],
46+
"@typescript-eslint/type-annotation-spacing": "error",
47+
"@typescript-eslint/unbound-method": "error"
48+
},
49+
"env": {
50+
"node": true,
51+
"es6": true,
52+
"jest/globals": true
53+
}
54+
}

.gitattributes

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
/lib/** linguist-detectable=false
2-
/node_modules/** linguist-detectable=false
1+
dist/** -diff linguist-generated=true

.github/dependabot.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: 2
2+
updates:
3+
# Enable version updates for npm
4+
- package-ecosystem: 'npm'
5+
# Look for `package.json` and `lock` files in the `root` directory
6+
directory: '/'
7+
# Check the npm registry for updates every day (weekdays)
8+
schedule:
9+
interval: 'daily'

.github/workflows/ci.yml

+15-13
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,31 @@ on:
77
- 'releases/*'
88

99
jobs:
10-
test:
10+
build: # make sure build/ci work properly
1111
runs-on: ubuntu-latest
1212
steps:
13-
14-
- name: Setup Node.js
15-
uses: actions/setup-node@v1
16-
with:
17-
node-version: '12.x'
18-
1913
- name: Checkout
20-
uses: actions/checkout@v1
14+
uses: actions/checkout@v2
2115

2216
- name: Install deps
23-
run: npm ci
17+
run: npm install
2418

25-
- name: Build
26-
run: npm run build
19+
- name: Build, apply formatting, lint, package and run unit tests
20+
run: npm run all
2721

2822
- name: Style check
2923
run: npm run format-check
3024

31-
- name: Test
32-
run: npm test
25+
test: # make sure the action works on a clean machine without building
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Setup Node.js
29+
uses: actions/setup-node@v1
30+
with:
31+
node-version: '12.x'
32+
33+
- name: Checkout
34+
uses: actions/checkout@v2
3335

3436
- name: Setup BATS
3537
uses: ./

.gitignore

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
__tests__/runner/*
2-
3-
# comment out in distribution branches
4-
node_modules/
1+
# Dependency directory
2+
node_modules
53

64
# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
75
# Logs
@@ -91,3 +89,11 @@ typings/
9189

9290
# DynamoDB Local files
9391
.dynamodb/
92+
93+
# OS metadata
94+
.DS_Store
95+
Thumbs.db
96+
97+
# Ignore built ts files
98+
__tests__/runner/*
99+
lib/**/*

.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist/
2+
lib/
3+
node_modules/

.prettierrc.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"printWidth": 80,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"semi": false,
6+
"singleQuote": true,
7+
"trailingComma": "none",
8+
"bracketSpacing": false,
9+
"arrowParens": "avoid"
10+
}

README.md

+23-17
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,14 @@ Install the dependencies
5656
$ npm install
5757
```
5858

59-
Build the typescript
59+
Build the typescript, apply formatting, lint and package the code for
60+
distribution and run unit tests:
6061

6162
```bash
62-
$ npm run build
63+
$ npm run all
6364
```
6465

65-
Run the tests :heavy_check_mark:
66+
Run the tests separately :heavy_check_mark:
6667

6768
```bash
6869
$ npm test
@@ -85,26 +86,31 @@ See the documentation:
8586

8687
#### Publishing to a distribution branch
8788

88-
Actions are run from GitHub repos. It's recommended for users to only refer to
89-
release branches instead of consuming master directly. To create a release
90-
branch, you'd normally do:
89+
Actions are run from GitHub repos so the branch which will be used at runtime
90+
needs to have the `dist/` folder checked-in. It's recommended for users to only
91+
refer to released versions instead of consuming master directly.
92+
93+
The distribution is created with [ncc](https://github.com/zeit/ncc) which can
94+
be invoked via:
9195

9296
``` bash
93-
$ git checkout -b releases/v1
94-
$ npm prune --production
95-
$ git add node_modules
96-
$ git commit -a -m "Release v1"
97+
$ npm run package
98+
$ git add dist
99+
$ git commit -a -m "prod package"
97100
```
98101

99-
However some of that is automated using [husky](https://github.com/typicode/husky)
100-
git hooks, so it's enough to just do:
102+
Now to release a new minor/patch versions (replace `.x.y` as appropriate):
101103

102104
``` bash
103-
$ git checkout -b releases/v1
104-
sed -i '/^node_modules/s/^/#/' .gitignore
105-
# update README.md to refer to @v1
106-
$ git commit -a -m "Release v1"
107-
$ git push origin releases/v1
105+
# update "version" property in `package.json`
106+
$ npm install
107+
$ npm run all
108+
$ git add -A
109+
$ git commit -v -m "Release v1.x.y"
110+
$ git push
111+
$ git tag -s v1.x.y
112+
$ git tag -fs v1 -m "Update v1 tag"
113+
$ git push --tags --force
108114
```
109115

110116
The action is now published! :rocket:

__tests__/installer.test.ts

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
import * as io from "@actions/io";
2-
import * as process from "process";
3-
import * as path from "path";
4-
import { existsSync } from "fs";
1+
import * as io from '@actions/io'
2+
import * as process from 'process'
3+
import * as path from 'path'
4+
import {existsSync} from 'fs'
55

6-
const toolDir = path.join(__dirname, "runner", "tools");
7-
const tempDir = path.join(__dirname, "runner", "temp");
6+
const toolDir = path.join(__dirname, 'runner', 'tools')
7+
const tempDir = path.join(__dirname, 'runner', 'temp')
88

9-
process.env["RUNNER_TOOL_CACHE"] = toolDir;
10-
process.env["RUNNER_TEMP"] = tempDir;
11-
import { ensureBatsAvailable } from "../src/installer";
9+
process.env['RUNNER_TOOL_CACHE'] = toolDir
10+
process.env['RUNNER_TEMP'] = tempDir
11+
import {ensureBatsAvailable} from '../src/installer'
1212

13-
describe("installer tests", () => {
13+
describe('installer tests', () => {
1414
beforeAll(async () => {
15-
await io.rmRF(toolDir);
16-
await io.rmRF(tempDir);
17-
}, 100000);
15+
await io.rmRF(toolDir)
16+
await io.rmRF(tempDir)
17+
}, 100000)
1818

19-
it("Acquires version of BATS if no matching version is installed", async () => {
20-
let batsDir = await ensureBatsAvailable("1.0.0");
19+
it('Acquires version of BATS if no matching version is installed', async () => {
20+
let batsDir = await ensureBatsAvailable('1.0.0')
2121

22-
expect(existsSync(`${batsDir}.complete`)).toBe(true);
23-
expect(existsSync(path.join(batsDir, "bin", "bats"))).toBe(true);
24-
}, 100000);
22+
expect(existsSync(`${batsDir}.complete`)).toBe(true)
23+
expect(existsSync(path.join(batsDir, 'bin', 'bats'))).toBe(true)
24+
}, 100000)
2525

26-
it("Throws if no matching version of BATS can be found", async () => {
27-
let thrown = false;
26+
it('Throws if no matching version of BATS can be found', async () => {
27+
let thrown = false
2828
try {
29-
await ensureBatsAvailable("0.0.0");
29+
await ensureBatsAvailable('0.0.0')
3030
} catch {
31-
thrown = true;
31+
thrown = true
3232
}
33-
expect(thrown).toBe(true);
34-
}, 100000);
35-
});
33+
expect(thrown).toBe(true)
34+
}, 100000)
35+
})

action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ inputs:
77
default: '1.2.1'
88
runs:
99
using: 'node12'
10-
main: 'lib/setup-bats.js'
10+
main: 'dist/index.js'

0 commit comments

Comments
 (0)