Skip to content

Commit 66274d3

Browse files
authored
Merge pull request #145 from nodenv/release-flow
release flow
2 parents 72dca17 + 6972cfb commit 66274d3

File tree

2 files changed

+66
-13
lines changed

2 files changed

+66
-13
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# node-build-prerelease
22

3-
[![Build Status](https://travis-ci.org/nodenv/node-build-prerelease.svg?branch=master)](https://travis-ci.org/nodenv/node-build-prerelease)
4-
53
node-build-prerelease is an [nodenv][] plugin (or more precisely, a [node-build][] plugin) that provides build definitions for Node.js prereleases (primarily release candidates).
64

5+
[![Tests](https://img.shields.io/github/actions/workflow/status/nodenv/node-build-prerelease/test.yml?label=tests&logo=github)](https://github.com/nodenv/node-build-prerelease/actions/workflows/test.yml)
6+
[![Latest Homebrew Release](<https://img.shields.io/badge/dynamic/regex?url=https%3A%2F%2Fraw.githubusercontent.com%2Fnodenv%2Fhomebrew-nodenv%2Frefs%2Fheads%2Fmain%2FFormula%2Fnode-build-prerelease.rb&logo=homebrew&logoColor=white&label=homebrew-nodenv&color=orange&search=archive%2Frefs%2Ftags%2Fv(%3F%3Cversion%3E%5Cd%2B.*).tar.gz&replace=v%24%3Cversion%3E>)](https://github.com/nodenv/homebrew-nodenv/blob/main/Formula/node-build-prerelease.rb)
7+
[![Latest GitHub Release](https://img.shields.io/github/v/release/nodenv/node-build-prerelease?label=github&logo=github&sort=semver)](https://github.com/nodenv/node-build-prerelease/releases/latest)
8+
[![Latest npm Release](https://img.shields.io/npm/v/@nodenv/node-build-prerelease?logo=npm&logoColor=white)](https://www.npmjs.com/package/@nodenv/node-build-prerelease/v/latest)
9+
710
<!-- toc -->
811

912
- [Installation](#installation)

script/preversion

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,79 @@
11
#!/usr/bin/env bash
2-
# Usage: script/release-precheck
2+
#
3+
# Ensures repo is ready to release.
4+
#
5+
# Usage: script/preversion [-v] [--] [FILES...]
6+
#
7+
# Options:
8+
# -o Detect unreleased changes in (and only in) FILES
9+
# -v Print log since last tag
10+
# FILES Files to check for changes.
11+
# [default: package.json#files read via $npm_package_files_*]
312
#
413
# - fetch from origin
514
# - ensure it isn't already tagged
6-
# - ensure currently on master branch
15+
# - ensure currently on main branch
716
# - ensure there are bin or definition changes to release
817

918
set -euo pipefail
1019

11-
git fetch --quiet --tags origin master
20+
[ -n "${DEBUG-}" ] && set -x
21+
22+
unset verbose strict
23+
while getopts "ov" opt; do
24+
case "$opt" in
25+
o) strict=1 ;;
26+
v) verbose=1 ;;
27+
*) break ;;
28+
esac
29+
done
30+
shift $((OPTIND - 1))
31+
32+
if [ "${1-}" = -- ]; then
33+
shift
34+
fi
35+
36+
abort() {
37+
echo "Aborting: $1" >&2
38+
exit "${2:-1}"
39+
}
40+
41+
declare -a files
42+
if [ "$#" -gt 0 ]; then
43+
files=("$@")
44+
else
45+
IFS=" " read -r -a files <<<"$(node -p 'require("./package").files.join(" ")')"
46+
fi
47+
48+
git fetch --quiet --tags origin main
1249

1350
existing="$(git tag --points-at HEAD)"
1451
if [ -n "$existing" ]; then
15-
echo "Aborting: HEAD is already tagged as '${existing}'" >&2
16-
exit 1
52+
abort "HEAD is already tagged as '${existing}'"
1753
fi
1854

1955
current_branch="$(git symbolic-ref --short HEAD)"
20-
if [ "$current_branch" != master ]; then
21-
echo "Aborting: Not currently on master branch" >&2
22-
exit 1
56+
if [ "$current_branch" != main ]; then
57+
abort "Not currently on main branch" 2
2358
fi
2459

2560
previous_tag="$(git describe --tags --abbrev=0)"
26-
if git diff --quiet "${previous_tag}..HEAD" -- bin share; then
27-
echo "Aborting: No features to release since '${previous_tag}'" >&2
28-
exit 1
61+
if git diff --quiet "${previous_tag}..HEAD" -- "${files[@]}"; then
62+
abort "No features to release since '${previous_tag}'"
63+
fi
64+
65+
allowed_changes=("${files[@]}" .github script *.md)
66+
allowed_changes=("${allowed_changes[@]/#/\':!\'}") # prefix pathspecs with git's "ignore"
67+
68+
if [ -n "${strict-}" ] &&
69+
! git diff --quiet "${previous_tag}..HEAD" -- "${allowed_changes[@]}"; then
70+
{
71+
echo "git diff --stat ${previous_tag}..HEAD -- ${allowed_changes[*]}"
72+
git diff --stat "${previous_tag}..HEAD" -- "${allowed_changes[@]}"
73+
} >&2
74+
abort "Changes detected outside '${allowed_changes[*]#:!}'" 2
75+
fi
76+
77+
if [ -n "${verbose-}" ]; then
78+
git log "$previous_tag"... --oneline -- "${files[@]}"
2979
fi

0 commit comments

Comments
 (0)