build: add curl and cmake in Dockerfile #54
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
name: Test and Release | |
on: | |
workflow_dispatch: | |
release: | |
types: | |
- published | |
pull_request: | |
branches: | |
- master | |
- v[0-9]+.[0-9]+-dev | |
jobs: | |
test: | |
name: Run Insight API tests | |
runs-on: ubuntu-20.04 | |
timeout-minutes: 10 | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions/setup-node@v2 | |
with: | |
node-version: '16' | |
- 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: Run tests | |
run: npm run test | |
release-npm: | |
name: Release NPM package | |
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/[email protected] | |
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: | | |
const tag = context.payload.release.tag_name; | |
const [, major, minor] = tag.match(/^v([0-9]+)\.([0-9]+)/); | |
return (tag.includes('dev') ? `${major}.${minor}-dev` : 'latest'); | |
- name: Publish NPM package | |
uses: JS-DevTools/npm-publish@v1 | |
with: | |
token: ${{ secrets.NPM_TOKEN }} | |
tag: ${{ steps.tag.outputs.result }} | |
release-docker: | |
name: Release Docker image | |
runs-on: ubuntu-20.04 | |
needs: release-npm | |
if: ${{ github.event_name == 'release' }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v1 | |
- name: Set up Docker BuildX | |
uses: docker/setup-buildx-action@v1 | |
with: | |
version: v0.7.0 | |
install: true | |
driver-opts: image=moby/buildkit:buildx-stable-1 | |
- name: Cache Docker layers | |
uses: actions/cache@v2 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Set suffix to Docker tags | |
uses: actions/github-script@v3 | |
id: suffix | |
with: | |
result-encoding: string | |
script: "return (context.payload.release.tag_name.includes('-dev') ? '-dev' : '');" | |
- name: Set Docker tags and labels | |
id: docker_meta | |
uses: docker/metadata-action@v3 | |
with: | |
images: dashpay/insight-api | |
tags: | | |
type=match,pattern=v(\d+),group=1 | |
type=match,pattern=v(\d+.\d+),group=1 | |
type=match,pattern=v(\d+.\d+.\d+),group=1 | |
type=match,pattern=v(.*),group=1,suffix=,enable=${{ contains(github.event.release.tag_name, '-dev') }} | |
flavor: | | |
latest=${{ !contains(github.event.release.tag_name, '-dev') }} | |
suffix=${{ steps.suffix.outputs.result }} | |
- name: Build and push Docker image | |
id: docker_build | |
uses: docker/build-push-action@v2 | |
with: | |
context: docker | |
file: docker/Dockerfile | |
push: true | |
tags: ${{ steps.docker_meta.outputs.tags }} | |
labels: ${{ steps.docker_meta.outputs.labels }} | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new | |
platforms: linux/amd64,linux/arm64,linux/arm/v7 | |
build-args: VERSION=${{ github.event.release.tag_name }} | |
# https://github.com/docker/build-push-action/issues/252 | |
# https://github.com/moby/buildkit/issues/1896 | |
- name: Run temporary fix for Docker cache action | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache | |
- name: Output Docker image digest | |
run: echo ${{ steps.docker_build.outputs.digest }} |