Skip to content

Commit

Permalink
feat: github actions (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian authored Mar 3, 2021
1 parent 7ccc292 commit 017898a
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 318 deletions.
271 changes: 6 additions & 265 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,271 +1,12 @@
version: 2
version: 2.1
jobs:
test-node-8:
noop:
docker:
- image: circleci/node:8
working_directory: ~/project
- image: alpine:3.11.3
steps:
- checkout
- restore_cache:
keys:
- yarn-cache-8-{{ .Branch }}-{{ checksum "yarn.lock" }}
- yarn-cache-8-{{ .Branch }}
- yarn-cache-8-
- run: yarn install --ignore-engines
- save_cache:
key: yarn-cache-8-{{ .Branch }}-{{ checksum "yarn.lock" }}
paths: [node_modules]
- run: yarn test

test-node-10:
docker:
- image: circleci/node:10
working_directory: ~/project
steps:
- checkout
- restore_cache:
keys:
- yarn-cache-10-{{ .Branch }}-{{ checksum "yarn.lock" }}
- yarn-cache-10-{{ .Branch }}
- yarn-cache-10-
- run: yarn install
- save_cache:
key: yarn-cache-10-{{ .Branch }}-{{ checksum "yarn.lock" }}
paths: [node_modules]
- run: yarn test

test-node-12:
docker:
- image: circleci/node:12
working_directory: ~/project
steps:
- checkout
- attach_workspace:
at: ~/project
- restore_cache:
keys:
- yarn-cache-12-{{ .Branch }}-{{ checksum "yarn.lock" }}
- yarn-cache-12-{{ .Branch }}
- yarn-cache-12-

- run: yarn install

- save_cache:
key: yarn-cache-12-{{ .Branch }}-{{ checksum "yarn.lock" }}
paths: [node_modules]

- run: yarn test
- run: yarn send-coverage
- run: yarn docs:test

- persist_to_workspace:
root: .
paths: [.]
- store_artifacts:
path: ./coverage/clover.xml
prefix: tests
- store_artifacts:
path: coverage
prefix: coverage
- store_test_results:
path: ./coverage/clover.xml

test-node-latest:
docker:
- image: circleci/node
working_directory: ~/project
steps:
- checkout
- restore_cache:
keys:
- yarn-cache-latest-{{ .Branch }}-{{ checksum "yarn.lock" }}
- yarn-cache-latest-{{ .Branch }}
- yarn-cache-latest-
- run: yarn install
- save_cache:
key: yarn-cache-latest-{{ .Branch }}-{{ checksum "yarn.lock" }}
paths: [node_modules]
- run: yarn test

validate-dependencies:
docker:
- image: circleci/node:12
working_directory: ~/project
steps:
- checkout
- restore_cache:
keys:
- yarn-cache-12-{{ .Branch }}-{{ checksum "yarn.lock" }}
- yarn-cache-12-{{ .Branch }}
- yarn-cache-12-

- run: yarn install
- run:
name: yarn validate:dependencies
command: |
if ! git log --format=oneline -n 1 | grep -q "\[ignore-audit\]"; then
yarn validate:dependencies
else
echo "Skipping audit"
fi
validate-all-dependencies:
docker:
- image: circleci/node:12
working_directory: ~/project
steps:
- checkout
- restore_cache:
keys:
- yarn-cache-12-{{ .Branch }}-{{ checksum "yarn.lock" }}
- yarn-cache-12-{{ .Branch }}
- yarn-cache-12-

- run: yarn install
- run: yarn validate:dependencies
- run: yarn validate:dev-dependencies

release:
docker:
- image: circleci/node:12
working_directory: ~/project
steps:
- checkout
# Clean working tree and install dependencies
- run: yarn reset
- run: yarn install
- run:
name: Determine release type
command: |
PACKAGE_NAME=$(yarn info -s . name)
PUBLISHED_VERSION=$(yarn info -s $PACKAGE_NAME version)
THIS_VERSION=$(node -p "require('./package.json').version")
# Simple bash helper to comapre version numbers
verlte() {
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
}
verlt() {
[ "$1" = "$2" ] && return 1 || verlte $1 $2
}
if verlt $PUBLISHED_VERSION $THIS_VERSION
then
echo 'export PUBLISH_ARGS="--tag latest"' >> $BASH_ENV
echo "Publishing latest"
else
echo 'export PUBLISH_ARGS="--tag hotfix"' >> $BASH_ENV
echo "Publishing hotfix"
fi
source $BASH_ENV
- run: yarn build
# Setup git
- add_ssh_keys:
fingerprints:
- '8d:f8:a8:b0:86:33:58:1c:fb:24:53:2b:03:73:9c:34'
- run: mkdir -p ~/.ssh
- run:
name: Keyscan Github
command: ssh-keyscan -H github.com >> ~/.ssh/known_hosts
- run: git config --global user.email "[email protected]"
- run: git config --global user.name "superflytvab"
# Publish docs
- run:
name: yarn docs:publish
command: |
if [[ $PUBLISH_ARGS == *"latest"* ]]; then
echo "Publishing docs"
yarn docs:publish
else
echo "Skipping docs"
fi
# Publish npm
- run:
name: Write NPM Token to ~/.npmrc
command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
- run:
name: Publish to NPM with yarn
command: NEW_VERSION=$(node -p "require('./package.json').version") && yarn publish --access=public --new-version=$NEW_VERSION --network-timeout 100000 $PUBLISH_ARGS

prerelease:
docker:
- image: circleci/node:12
working_directory: ~/project
steps:
- checkout
# Clean working tree and install dependencies
- run: yarn reset
- run: yarn install
# Locally bump the version
- run:
name: yarn release
command: |
COMMIT_TIMESTAMP=$(git log -1 --pretty=format:%ct HEAD)
COMMIT_DATE=$(date -d @$COMMIT_TIMESTAMP +%Y%m%d-%H%M%S)
GIT_HASH=$(git rev-parse --short HEAD)
if [[ "${CIRCLE_BRANCH}" == "master" ]]
then
PRERELEASE_TAG=nightly
echo 'export PUBLISH_ARGS="--tag nightly"' >> $BASH_ENV
else
PRERELEASE_TAG=nightly-$(echo $CIRCLE_BRANCH | sed -r 's/[^a-z0-9]+/-/gi')
echo 'export PUBLISH_ARGS="--tag experimental"' >> $BASH_ENV
fi
yarn release --prerelease $PRERELEASE_TAG-$COMMIT_DATE-$GIT_HASH --skip.changelog --skip.tag --skip.commit
# Build and deploy
- run: yarn build
- run:
name: Write NPM Token to ~/.npmrc
command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
- run:
name: Publish to NPM with yarn
command: NEW_VERSION=$(node -p "require('./package.json').version") && yarn publish --access=public --new-version=$NEW_VERSION --network-timeout 100000 $PUBLISH_ARGS
- run: exit 0

workflows:
version: 2
build-test-publish:
build:
jobs:
- test-node-8
- test-node-12
- test-node-10
- test-node-latest
- validate-all-dependencies:
filters:
branches:
only:
- master
- develop
- validate-dependencies:
filters:
branches:
only:
- master
- develop
tags:
only: /^[0-9]+\.[0-9]+\.[0-9]+.*/
- prerelease:
requires:
- test-node-8
- test-node-12
- test-node-10
- test-node-latest
filters:
tags:
ignore: /.*/
branches:
only: /.*/
- release:
requires:
- validate-dependencies
- test-node-8
- test-node-12
- test-node-10
- test-node-latest
filters:
tags:
only: /^[0-9]+\.[0-9]+\.[0-9]+.*/
branches:
ignore: /.*/
- noop
Loading

0 comments on commit 017898a

Please sign in to comment.