chore: add license #3
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: CI/CD Pipeline | |
on: | |
push: | |
jobs: | |
hadolint: | |
runs-on: ubuntu-latest | |
name: 'Hadolint' | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: jbergstroem/hadolint-gh-action@v1 | |
with: | |
error_level: 0 | |
dockerfile: 'Dockerfile' | |
test: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: | |
- 16.14.0-buster | |
container: | |
image: node:${{ matrix.node-version }} | |
services: | |
postgres: | |
image: registry.opensource.zalan.do/acid/spilo-14:2.1-p6 | |
env: | |
ALLOW_NOSSL: 'true' | |
PGVERSION: '14' | |
SPILO_PROVIDER: local | |
PGUSER_SUPERUSER: postgres | |
PGPASSWORD_SUPERUSER: zalando | |
options: >- | |
--health-cmd "pg_isready" | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 10 | |
env: | |
NODE_ENV: test | |
BASE_URL: 'localhost:3000' | |
TEST_POSTGRES_URL: 'postgres://postgres:zalando@postgres:5432/postgres' | |
TWILIO_ACCOUNT_SID: ${{ secrets.TWILIO_ACCOUNT_SID }} | |
TWILIO_AUTH_TOKEN: ${{ secrets.TWILIO_AUTH_TOKEN }} | |
TELNYX_API_KEY: ${{ secrets.TELNYX_API_KEY }} | |
steps: | |
- name: checkout | |
uses: actions/checkout@v2 | |
- uses: actions/cache@v2 | |
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) | |
with: | |
path: node_modules | |
key: ${{ runner.os }}-node-${{ matrix.node-version }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-node-${{ matrix.node-version }}-yarn- | |
- run: yarn install | |
- name: Lint Apps | |
shell: bash | |
run: yarn test:lint | |
- name: Run migrations | |
shell: bash | |
run: yarn migrate:worker && yarn migrate up | |
- name: Run Tests | |
shell: bash | |
run: yarn test:unit | |
publish-docker-image: | |
if: startsWith( github.ref, 'refs/tags/v') | |
needs: test | |
name: Publish Docker image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
with: | |
version: latest | |
# Caching strategy from: https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#github-cache | |
- name: Cache Docker layers for ${{ matrix.service }} | |
uses: actions/cache@v2 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-switchboard-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx-switchboard- | |
- name: Get image tags | |
id: image-tags | |
run: | | |
export GIT_SHA="${{ github.sha }}" | |
export GIT_SHA_SHORT=${GIT_SHA:0:7} | |
echo "::set-output name=sha::$GIT_SHA_SHORT" | |
export GIT_REF=${GITHUB_REF#refs/*/} | |
echo "$GIT_REF" | |
export SWITCHBOARD_VERSION=${GIT_REF#"v"} | |
echo "::set-output name=version::$SWITCHBOARD_VERSION" | |
- name: Login to GAR | |
uses: docker/login-action@v1 | |
with: | |
registry: us-east4-docker.pkg.dev | |
username: _json_key | |
password: ${{ secrets.GCR_JSON_KEY }} | |
- name: Build and push ${{ matrix.service }} | |
id: docker_build | |
uses: docker/build-push-action@v2 | |
with: | |
push: true | |
tags: | | |
us-east4-docker.pkg.dev/assemble-services/switchboard/core:latest | |
us-east4-docker.pkg.dev/assemble-services/switchboard/core:${{ steps.image-tags.outputs.version }} | |
us-east4-docker.pkg.dev/assemble-services/switchboard/core:${{ steps.image-tags.outputs.sha }} | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache-new | |
# Temp fix | |
# https://github.com/docker/build-push-action/issues/252 | |
# https://github.com/moby/buildkit/issues/1896 | |
- name: Move cache | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache |