-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add CI workflows for GitHub Actions; add automated release script
- Loading branch information
1 parent
ca449f9
commit 38ae1ac
Showing
4 changed files
with
113 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Install Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16' | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Run tests | ||
run: npm t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Release | ||
run-name: ${{ github.workflow }} ${{ github.event.inputs.release-version }} | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
release-version: | ||
description: Enter version to release (e.g., 1.0.1). | ||
required: false | ||
jobs: | ||
perform: | ||
if: github.repository_owner == 'bespokejs' && github.event_name == 'workflow_dispatch' | ||
runs-on: ubuntu-latest | ||
environment: releases | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Install Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16' | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Run tests | ||
run: npm t | ||
- name: Set up release environment | ||
run: | | ||
echo RELEASE_VERSION=${{ github.event.inputs.release-version }} >> $GITHUB_ENV | ||
echo RELEASE_NPM_TOKEN=${{ secrets[format('NPM_TOKEN_{0}', github.actor)] }} >> $GITHUB_ENV | ||
- name: Build, tag, and publish npm package | ||
run: ./release.sh |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/bin/bash | ||
|
||
# required packages (for ubuntu:kinetic): curl git jq nodejs npm | ||
|
||
if [ -z "$RELEASE_NPM_TOKEN" ]; then | ||
echo No npm token specified for publishing to npmjs.com. Stopping release. | ||
exit 1 | ||
fi | ||
export RELEASE_BRANCH=${GITHUB_REF_NAME:-main} | ||
if [ ! -v RELEASE_USER ]; then | ||
export RELEASE_USER=$GITHUB_ACTOR | ||
fi | ||
RELEASE_GIT_NAME=$(curl -s https://api.github.com/users/$RELEASE_USER | jq -r .name) | ||
RELEASE_GIT_EMAIL=$RELEASE_USER@users.noreply.github.com | ||
|
||
# RELEASE_VERSION can be a version number (exact) or increment keyword (next in sequence) | ||
if [ -z "$RELEASE_VERSION" ]; then RELEASE_VERSION=prerelease; fi | ||
if [ -z "$RELEASE_NPM_TAG" ]; then | ||
if case $RELEASE_VERSION in major|minor|patch) ;; *) false;; esac; then | ||
RELEASE_NPM_TAG=latest | ||
elif case $RELEASE_VERSION in pre*) ;; *) false;; esac; then | ||
RELEASE_NPM_TAG=testing | ||
elif [ "$RELEASE_VERSION" != "${RELEASE_VERSION/-/}" ] && [ "${RELEASE_VERSION#*-}" != "stable" ]; then | ||
RELEASE_NPM_TAG=testing | ||
else | ||
RELEASE_NPM_TAG=latest | ||
fi | ||
fi | ||
|
||
# configure git to push changes | ||
git config --local user.name "$RELEASE_GIT_NAME" | ||
git config --local user.email "$RELEASE_GIT_EMAIL" | ||
|
||
# configure npm client for publishing | ||
echo -e "//registry.npmjs.org/:_authToken=$RELEASE_NPM_TOKEN" > $HOME/.npmrc | ||
|
||
# release! | ||
( | ||
set -e | ||
npm version --no-git-tag-version $RELEASE_VERSION | ||
RELEASE_VERSION=$(npm exec -c 'echo -n $npm_package_version') | ||
if case $RELEASE_VERSION in 1.0.0-*) ;; *) false;; esac; then | ||
RELEASE_NPM_TAG=latest | ||
fi | ||
git commit -a -m "release $RELEASE_VERSION [no ci]" | ||
git tag -m "version $RELEASE_VERSION" v$RELEASE_VERSION | ||
git push origin $(git describe --tags --exact-match) | ||
npm publish --access public --tag $RELEASE_NPM_TAG | ||
git push origin $RELEASE_BRANCH | ||
) | ||
|
||
exit_code=$? | ||
|
||
# nuke npm settings | ||
rm -f $HOME/.npmrc | ||
|
||
# check for any uncommitted files | ||
git status -s -b | ||
|
||
exit $exit_code |