Skip to content
This repository has been archived by the owner on Dec 9, 2022. It is now read-only.

Commit

Permalink
feat: add gh pipeline (#161)
Browse files Browse the repository at this point in the history
* ci: gh actions pipeline

* add lockfile

* chore: update for chai 4.3.6
  • Loading branch information
YOU54F authored Apr 19, 2022
1 parent 35ee09a commit c66ef47
Show file tree
Hide file tree
Showing 19 changed files with 3,682 additions and 21 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Build

on:
push:
pull_request:
branches: [main]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x, 14.x, 16.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- id: publish
run: scripts/ci/build-and-test.sh
38 changes: 38 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Publish and release

on:
repository_dispatch:
types:
- release-triggered

env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
ENV_SUT: ${{ secrets.ENV_SUT }}
CI_PROVIDER_TO_TEST: 'github'

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: 12
registry-url: 'https://registry.npmjs.org'
- id: publish
run: scripts/ci/release.sh
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTOMATION_TOKEN}}
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: v${{ steps.publish.outputs.version }}
release_name: Release v${{ steps.publish.outputs.version }}
body: ${{steps.publish.outputs.notes}}
draft: false
prerelease: false
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,3 @@ node_modules

.idea
.nyc_output

yarn.lock
package-lock.json
5 changes: 4 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ xunit.xml
commitlint.config.js
.nyc_output/
coverage
cypress-multi-reporters.tar.gz
cypress-multi-reporters.tar.gz
renovate.json
.editorconfig
.ncurc.js
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
]
},
"scripts": {
"devtest": "nyc mocha --require chai/register-expect --no-coverage --timeout 5000 tests/**/*.test.js*",
"devtest": "nyc mocha --require node_modules/chai/register-expect --no-coverage --timeout 5000 tests/**/*.test.js*",
"lint": "eslint .",
"test": "nyc mocha --require chai/register-expect --timeout 5000 tests/**/*.test.js*",
"test": "nyc mocha --require node_modules/chai/register-expect --timeout 5000 tests/**/*.test.js*",
"deploy:prepare": "./scripts/create_npmrc_file.sh",
"release": "standard-version --release-as 1.5.0"
},
Expand Down
3 changes: 3 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# scripts

This directory contains entry points for scripts intended to be run manually by maintainers + contributors, or from `npm` steps
6 changes: 0 additions & 6 deletions scripts/build.sh

This file was deleted.

5 changes: 5 additions & 0 deletions scripts/ci/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# scripts/CI

This directory contains entry points for scripts intended to be run by CI

Each file in here should map to a CI step.
12 changes: 12 additions & 0 deletions scripts/ci/build-and-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash -eu
set -eu # Have to set explicitly as github's windows runners don't respect the `eu` in the shebang

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)" # Figure out where the script is running
. "$SCRIPT_DIR"/../lib/robust-bash.sh

yarn install
yarn run lint
yarn run devtest
yarn run test
rm -rf node_modules
yarn install --production
3 changes: 3 additions & 0 deletions scripts/ci/lib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# script/CI/lib

This directory contains scripts that are only used by scripts in the CI directory.
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#!/bin/bash -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)" # Figure out where the script is running
. "$SCRIPT_DIR"/../../lib/robust-bash.sh

require_env_var NODE_AUTH_TOKEN

set +x #Don't echo the NPM key

NPMRC_FILE=.npmrc
echo "YOU54F:registry=https://registry.npmjs.org/" > $NPMRC_FILE
echo "//registry.npmjs.org/:_authToken=${NPM_KEY}" >> $NPMRC_FILE
echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" >> $NPMRC_FILE
echo "//registry.npmjs.org/:username=you54f" >> $NPMRC_FILE
echo "//registry.npmjs.org/:[email protected]" >> $NPMRC_FILE
echo "//registry.npmjs.org/:always-auth=true" >> $NPMRC_FILE

set -x
set -x
10 changes: 10 additions & 0 deletions scripts/ci/lib/get-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash -eu
set -eu # Have to set explicitly as github's windows runners don't respect the `eu` in the shebang

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)" # Figure out where the script is running
. "$SCRIPT_DIR"/../../lib/robust-bash.sh

require_binary grep

VERSION="$(jq -r .version package.json)"
echo "$VERSION"
19 changes: 19 additions & 0 deletions scripts/ci/lib/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash -eu
set -eu # Have to set explicitly as github's windows runners don't respect the `eu` in the shebang

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)" # Figure out where the script is running
. "$SCRIPT_DIR"/../../lib/robust-bash.sh

require_binary npm

VERSION="$("$SCRIPT_DIR/get-version.sh")"

echo "--> Preparing npmrc file"
"$SCRIPT_DIR"/create_npmrc_file.sh

echo "--> Releasing version ${VERSION}"

echo "--> Releasing artifacts"
echo " Publishing cypress-multi-reporters@${VERSION}..."
npm publish --tag latest
echo " done!"
41 changes: 41 additions & 0 deletions scripts/ci/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash -eu
set -eu # Have to set explicitly as github's windows runners don't respect the `eu` in the shebang

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)" # Figure out where the script is running
. "$SCRIPT_DIR"/../lib/robust-bash.sh

require_env_var CI "This script must be run from CI. If you are running locally, note that it stamps your repo git settings."
require_env_var GITHUB_ACTOR
require_env_var NODE_AUTH_TOKEN

# Setup git for github actions
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git config user.name "${GITHUB_ACTOR}"

# It's easier to read the release notes
# from the standard version tool before it runs
RELEASE_NOTES="$(npx standard-version --dry-run | awk 'BEGIN { flag=0 } /^---$/ { if (flag == 0) { flag=1 } else { flag=2 }; next } flag == 1')"
# Don't release if there are no changes
if [ "$(echo "$RELEASE_NOTES" | wc -l)" -eq 1 ] ; then
error "This release would have no release notes. Does it include changes?"
echo " - You must have at least one fix / feat commit to generate release notes"
echo "*** STOPPING RELEASE PROCESS ***"
exit 1
fi
# This is github actions' method for emitting multi-line values
RELEASE_NOTES="${RELEASE_NOTES//'%'/'%25'}"
RELEASE_NOTES="${RELEASE_NOTES//$'\n'/'%0A'}"
RELEASE_NOTES="${RELEASE_NOTES//$'\r'/'%0D'}"
echo "::set-output name=notes::$RELEASE_NOTES"

"$SCRIPT_DIR"/build-and-test.sh
npm run release

# Emit version to next step
VERSION="$("$SCRIPT_DIR/lib/get-version.sh")"
echo "::set-output name=version::$VERSION"

"$SCRIPT_DIR"/lib/publish.sh

# Push the new commit back to the repo.
git push --follow-tags
3 changes: 3 additions & 0 deletions scripts/lib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# scripts/lib

This directory contains scripts that are only used by other scripts
54 changes: 54 additions & 0 deletions scripts/lib/robust-bash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash -eu
set -eu # Have to set explicitly as github's windows runners don't respect the `eu` in the shebang

if [ -z "${LIB_ROBUST_BASH_SH:-}" ]; then
LIB_ROBUST_BASH_SH=included

function error {
echo "${1:-}"
}

function log {
echo "🔵 ${1:-}"
}

function debug_log {
if [ ! -z "${LIB_ROBUST_BASH_DEBUG:-}" ]; then
echo "🔎 ${1:-}"
fi
}

function warn {
echo "🟡 ${1:-}"
}

# Check to see that we have a required binary on the path
# and fail the script if it is not present
function require_binary {
if [ -z "${1:-}" ]; then
error "${FUNCNAME[0]} requires an argument"
exit 1
fi

if ! [ -x "$(command -v "$1")" ]; then
error "The required executable '$1' is not on the path."
exit 1
fi
}

# Check to see that we have a required environment variable set,
# and fail the script if it is not set.
#
# Optionally, a second argument can be provided to display
# a helpful message before failing
function require_env_var {
var_name="${1:-}"
if [ -z "${!var_name:-}" ]; then
error "The required environment variable ${var_name} is empty"
if [ ! -z "${2:-}" ]; then
echo " - $2"
fi
exit 1
fi
}
fi
7 changes: 0 additions & 7 deletions scripts/publish.sh

This file was deleted.

24 changes: 24 additions & 0 deletions scripts/trigger-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# Script to trigger release of the repository
# Requires a Github API token with repo scope stored in the
# environment variable GITHUB_ACCESS_TOKEN_FOR_PF_RELEASES
# Borrowed from Beth Skurrie's excellent script at
# https://github.com/pact-foundation/pact-ruby/blob/master/script/trigger-release.sh

: "${GITHUB_ACCESS_TOKEN_FOR_YOU54F_RELEASES:?Please set environment variable GITHUB_ACCESS_TOKEN_FOR_YOU54F_RELEASES}"

repository_slug=$(git remote get-url $(git remote show) | cut -d':' -f2 | sed 's/\.git//')

output=$(curl -L -v -X POST https://api.github.com/repos/${repository_slug}/dispatches \
-H 'Accept: application/vnd.github.everest-preview+json' \
-H "Authorization: Bearer $GITHUB_ACCESS_TOKEN_FOR_YOU54F_RELEASES" \
-d "{\"event_type\": \"release-triggered\"}" 2>&1)

if ! echo "${output}" | grep "HTTP\/2 204" > /dev/null; then
echo "$output" | sed "s/${GITHUB_ACCESS_TOKEN_FOR_YOU54F_RELEASES}/********/g"
echo "Failed to trigger release"
exit 1
else
echo "Release workflow triggered"
fi
Loading

0 comments on commit c66ef47

Please sign in to comment.