Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Commit

Permalink
chore: add 'make cutarelease' and other dev conveniences (#191)
Browse files Browse the repository at this point in the history
Separate 'lint' and 'test'. Add testing of node v19.
  • Loading branch information
trentm authored Dec 8, 2022
1 parent 8aaa1f3 commit d3842f6
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 3 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Lint this change with the latest node LTS.
name: Lint

# https://gitpro.ttaallkk.topmunity/t/how-to-trigger-an-action-on-push-or-pull-request-but-not-both/16662/2
on:
push:
branches:
- main
paths-ignore:
- '*.md'
pull_request:
branches:
- main
paths-ignore:
- '*.md'

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '18'
- run: npm install
- run: npm run lint
7 changes: 6 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
# Test with all supported node versions.
name: Test

# https://gitpro.ttaallkk.topmunity/t/how-to-trigger-an-action-on-push-or-pull-request-but-not-both/16662/2
on:
push:
branches:
- main
paths-ignore:
- '*.md'
pull_request:
branches:
- main
paths-ignore:
- '*.md'

jobs:
test-vers:
strategy:
matrix:
node: ['8.6', '8', '10', '12', '14', '15', '16', '18']
node: ['8.6', '8', '10', '12', '14', '15', '16', '18', '19']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down
51 changes: 51 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Some targets depend on https://github/trentm/json being on the PATH.
JSON ?= json

.PHONY: all
all:
npm install

.PHONY: test
test:
npm test

.PHONY: lint
lint:
npm run lint

# Ensure CHANGELOG.md and package.json have the same version for a release.
.PHONY: check-version
check-version:
@echo version is: $(shell cat package.json | json version)
[[ v`cat package.json | $(JSON) version` == `grep '^## ' CHANGELOG.md | head -1 | tail -1 | awk '{print $$2}'` ]]

.PHONY: check
check: lint check-version

# Tag and release a new release based on the current package.json#version.
# This long bit of Makefile does the following:
# - ensure the repo isn't dirty (changed files)
# - warn if we have a tag for this release already
# - interactively confirm
# - git tag
# - npm publish
.PHONY: cutarelease
cutarelease: check
[[ `basename $(shell git symbolic-ref HEAD)` == 'main' ]] # Can only release from 'main' branch.
[[ -z `git status --short` ]] # If this fails, the working dir is dirty.
@which $(JSON) 2>/dev/null 1>/dev/null && \
ver=$(shell $(JSON) -f package.json version) && \
name=$(shell $(JSON) -f package.json name) && \
publishedVer=$(shell npm view -j $(shell $(JSON) -f package.json name)@$(shell $(JSON) -f package.json version) version 2>/dev/null) && \
if [[ -n "$$publishedVer" ]]; then \
echo "error: $$name@$$ver is already published to npm"; \
exit 1; \
fi && \
echo "** Are you sure you want to tag and publish $$name@$$ver to npm?" && \
echo "** Enter to continue, Ctrl+C to abort." && \
read
ver=$(shell cat package.json | $(JSON) version) && \
date=$(shell date -u "+%Y-%m-%d") && \
git tag -a "v$$ver" -m "version $$ver ($$date)" && \
git push origin "v$$ver" && \
npm publish
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"lib"
],
"scripts": {
"test": "standard && nyc ./test/run_tests.sh"
"lint": "standard",
"test": "nyc ./test/run_tests.sh"
},
"engines": {
"node": "^8.6.0 || 10 || >=12"
Expand Down
2 changes: 1 addition & 1 deletion test/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ EXIT_CODE=0
TOP=$(cd $(dirname $0)/../ >/dev/null; pwd)
runTest() {
echo ""
echo "# runnign 'node $1'"
echo "# running 'node $1'"
node $1 || EXIT_CODE=$?
}

Expand Down

0 comments on commit d3842f6

Please sign in to comment.