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

chore(ci): CI with Github Actions #239

Merged
merged 10 commits into from
Apr 16, 2021
120 changes: 120 additions & 0 deletions .github/workflows/test_and_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: Test and Release

on:
workflow_dispatch:
release:
types: [published]
pull_request:
branches:
- master
- v[0-9]+.[0-9]+-dev

jobs:
test:
name: Run wallet-lib tests
strophy marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-20.04
timeout-minutes: 60
shumkov marked this conversation as resolved.
Show resolved Hide resolved
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '12'

- name: Enable NPM cache
uses: actions/cache@v2
with:
path: '~/.npm'
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-

- name: Cache Docker layers
uses: satackey/action-docker-layer-caching@v0.0.11
continue-on-error: true
with:
concurrency: 8

- name: Install NPM dependencies
run: npm ci

- name: Create dotenv file
run: cp .env.example .env
shumkov marked this conversation as resolved.
Show resolved Hide resolved

- uses: dashevo/gh-action-runtime-vars@master
strophy marked this conversation as resolved.
Show resolved Hide resolved
id: runtime-vars
if: ${{ contains(github.event.pull_request.body, '/set-var')}}
with:
pull-request-body: ${{ github.event.pull_request.body }}

- uses: dashevo/gh-action-platform-branches@master
strophy marked this conversation as resolved.
Show resolved Hide resolved
id: platform-branches
with:
override-major-version: 0
override-dashmate-branch: ${{ steps.runtime-vars.outputs.dashmate-branch }}
override-testsuite-branch: ${{ steps.runtime-vars.outputs.testsuite-branch }}

- uses: dashevo/gh-action-start-local-network@master
strophy marked this conversation as resolved.
Show resolved Hide resolved
with:
actions-cache-url: ${{ steps.platform-branches.outputs.cache-url }}
actions-cache-token: ${{ steps.platform-branches.outputs.cache-token }}
drive-branch: ${{ steps.runtime-vars.outputs.drive-branch }}
dapi-branch: ${{ steps.runtime-vars.outputs.dapi-branch }}
dashmate-branch: ${{ steps.platform-branches.outputs.dashmate-branch }}
install-sdk-version: ${{ steps.runtime-vars.outputs.install-sdk-version }}

- name: Parametrize environment
shumkov marked this conversation as resolved.
Show resolved Hide resolved
run: |
echo "DAPI_SEED=127.0.0.1" > .env
echo "FAUCET_PRIVATE_KEY=${{ env.faucet-private-key }}" >> .env
echo "NETWORK=regtest" >> .env
echo "DPNS_CONTRACT_ID=${{ env.dpns-contract-id }}" >> .env

- name: Check NPM package lock version is updated
shumkov marked this conversation as resolved.
Show resolved Hide resolved
run: npm run check-package # TODO: does this exist as an action already?

- name: Run ESLinter
run: npm run lint

- name: Run tests
run: npm run test

- name: Show Docker logs
if: ${{ failure() }}
uses: jwalton/gh-docker-logs@v1

release:
name: Release to NPM
strophy marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-20.04
needs: test
if: ${{ github.event_name == 'release' }}
steps:
- uses: actions/checkout@v2

- name: Check package version matches tag
uses: geritol/match-tag-to-package-version@0.1.0
env:
TAG_PREFIX: refs/tags/v

- name: Enable NPM cache
uses: actions/cache@v2
with:
path: '~/.npm'
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-

- name: Install NPM dependencies
run: npm ci

- name: Set release tag
uses: actions/github-script@v3
id: tag
with:
result-encoding: string
script: |
return (context.payload.release.tag_name.includes('dev') ? 'dev' : 'latest');

- uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
tag: ${{ steps.tag.outputs.result }}