Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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://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)
[![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)

<!-- toc -->

- [Installation](#installation)
Expand Down
72 changes: 61 additions & 11 deletions script/preversion
Original file line number Diff line number Diff line change
@@ -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