Skip to content

Commit 5dbd6a7

Browse files
committed
ci: tests and makework
1 parent dbda065 commit 5dbd6a7

File tree

5 files changed

+120
-0
lines changed

5 files changed

+120
-0
lines changed

.github/workflows/ci.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
strategy:
8+
matrix:
9+
node-version: [12.x, 14.x, 16.x, 17.x]
10+
platform:
11+
- os: ubuntu-latest
12+
shell: bash
13+
- os: macos-latest
14+
shell: bash
15+
- os: windows-latest
16+
shell: bash
17+
- os: windows-latest
18+
shell: powershell
19+
fail-fast: false
20+
21+
runs-on: ${{ matrix.platform.os }}
22+
defaults:
23+
run:
24+
shell: ${{ matrix.platform.shell }}
25+
26+
steps:
27+
- name: Checkout Repository
28+
uses: actions/[email protected]
29+
30+
- name: Use Nodejs ${{ matrix.node-version }}
31+
uses: actions/setup-node@v1
32+
with:
33+
node-version: ${{ matrix.node-version }}
34+
35+
- name: Install dependencies
36+
run: npm install
37+
38+
- name: Run Tests
39+
run: npm test -- -c -t0
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
git config --global user.email "$1"
3+
shift
4+
git config --global user.name "$1"
5+
shift
6+
message="$1"
7+
shift
8+
if [ $(git status --porcelain "$@" | egrep '^ M' | wc -l) -gt 0 ]; then
9+
git add "$@"
10+
git commit -m "$message"
11+
git push || git pull --rebase
12+
git push
13+
fi

.github/workflows/copyright-year.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
dir=${1:-$PWD}
3+
dates=($(git log --date=format:%Y --pretty=format:'%ad' --reverse | sort | uniq))
4+
if [ "${#dates[@]}" -eq 1 ]; then
5+
datestr="${dates}"
6+
else
7+
datestr="${dates}-${dates[${#dates[@]}-1]}"
8+
fi
9+
10+
stripDate='s/^((.*)Copyright\b(.*?))((?:,\s*)?(([0-9]{4}\s*-\s*[0-9]{4})|(([0-9]{4},\s*)*[0-9]{4})))(?:,)?\s*(.*)\n$/$1$9\n/g'
11+
addDate='s/^.*Copyright(?:\s*\(c\))? /Copyright \(c\) '$datestr' /g'
12+
for l in $dir/LICENSE*; do
13+
perl -pi -e "$stripDate" $l
14+
perl -pi -e "$addDate" $l
15+
done

.github/workflows/isaacs-makework.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: "various tidying up tasks to silence nagging"
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
jobs:
10+
makework:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
with:
15+
fetch-depth: 0
16+
- name: Use Node.js
17+
uses: actions/[email protected]
18+
with:
19+
node-version: 16.x
20+
- name: put repo in package.json
21+
run: node .github/workflows/package-json-repo.js
22+
- name: check in package.json if modified
23+
run: |
24+
bash -x .github/workflows/commit-if-modified.sh \
25+
26+
"package.json Repo Bot" \
27+
"chore: add repo to package.json" \
28+
package.json package-lock.json
29+
- name: put all dates in license copyright line
30+
run: bash .github/workflows/copyright-year.sh
31+
- name: check in licenses if modified
32+
run: |
33+
bash .github/workflows/commit-if-modified.sh \
34+
35+
"License Year Bot" \
36+
"chore: add copyright year to license" \
37+
LICENSE*
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env node
2+
3+
const pf = require.resolve(`${process.cwd()}/package.json`)
4+
const pj = require(pf)
5+
6+
if (!pj.repository && process.env.GITHUB_REPOSITORY) {
7+
const fs = require('fs')
8+
const server = process.env.GITHUB_SERVER_URL || 'https://github.com'
9+
const repo = `${server}/${process.env.GITHUB_REPOSITORY}`
10+
pj.repository = repo
11+
const json = fs.readFileSync(pf, 'utf8')
12+
const match = json.match(/^\s*\{[\r\n]+([ \t]*)"/)
13+
const indent = match[1]
14+
const output = JSON.stringify(pj, null, indent || 2) + '\n'
15+
fs.writeFileSync(pf, output)
16+
}

0 commit comments

Comments
 (0)