diff --git a/README.md b/README.md index af7b6589..0bfb9b88 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,12 @@ # node-build-prerelease -[![Build Status](https://travis-ci.org/nodenv/node-build-prerelease.svg?branch=master)](https://travis-ci.org/nodenv/node-build-prerelease) - 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). +[![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) +[![Latest Homebrew Release]()](https://github.com/nodenv/homebrew-nodenv/blob/main/Formula/node-build-prerelease.rb) +[![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) +[![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) + - [Installation](#installation) diff --git a/script/preversion b/script/preversion index 98c03c05..f33dfc45 100755 --- a/script/preversion +++ b/script/preversion @@ -1,29 +1,79 @@ #!/usr/bin/env bash -# Usage: script/release-precheck +# +# Ensures repo is ready to release. +# +# Usage: script/preversion [-v] [--] [FILES...] +# +# Options: +# -o Detect unreleased changes in (and only in) FILES +# -v Print log since last tag +# FILES Files to check for changes. +# [default: package.json#files read via $npm_package_files_*] # # - fetch from origin # - ensure it isn't already tagged -# - ensure currently on master branch +# - ensure currently on main branch # - ensure there are bin or definition changes to release set -euo pipefail -git fetch --quiet --tags origin master +[ -n "${DEBUG-}" ] && set -x + +unset verbose strict +while getopts "ov" opt; do + case "$opt" in + o) strict=1 ;; + v) verbose=1 ;; + *) break ;; + esac +done +shift $((OPTIND - 1)) + +if [ "${1-}" = -- ]; then + shift +fi + +abort() { + echo "Aborting: $1" >&2 + exit "${2:-1}" +} + +declare -a files +if [ "$#" -gt 0 ]; then + files=("$@") +else + IFS=" " read -r -a files <<<"$(node -p 'require("./package").files.join(" ")')" +fi + +git fetch --quiet --tags origin main existing="$(git tag --points-at HEAD)" if [ -n "$existing" ]; then - echo "Aborting: HEAD is already tagged as '${existing}'" >&2 - exit 1 + abort "HEAD is already tagged as '${existing}'" fi current_branch="$(git symbolic-ref --short HEAD)" -if [ "$current_branch" != master ]; then - echo "Aborting: Not currently on master branch" >&2 - exit 1 +if [ "$current_branch" != main ]; then + abort "Not currently on main branch" 2 fi previous_tag="$(git describe --tags --abbrev=0)" -if git diff --quiet "${previous_tag}..HEAD" -- bin share; then - echo "Aborting: No features to release since '${previous_tag}'" >&2 - exit 1 +if git diff --quiet "${previous_tag}..HEAD" -- "${files[@]}"; then + abort "No features to release since '${previous_tag}'" +fi + +allowed_changes=("${files[@]}" .github script *.md) +allowed_changes=("${allowed_changes[@]/#/\':!\'}") # prefix pathspecs with git's "ignore" + +if [ -n "${strict-}" ] && + ! git diff --quiet "${previous_tag}..HEAD" -- "${allowed_changes[@]}"; then + { + echo "git diff --stat ${previous_tag}..HEAD -- ${allowed_changes[*]}" + git diff --stat "${previous_tag}..HEAD" -- "${allowed_changes[@]}" + } >&2 + abort "Changes detected outside '${allowed_changes[*]#:!}'" 2 +fi + +if [ -n "${verbose-}" ]; then + git log "$previous_tag"... --oneline -- "${files[@]}" fi