Skip to content

Undo last change, syntax #131

Undo last change, syntax

Undo last change, syntax #131

name: lint, test & push Docker image
on:
push:
branches:
- '*'
tags:
- 'release_*'
pull_request:
branches:
- '*'
env:
# We tell Playwright not to download browser binaries because we use microsoft/playwright-github-action.
# https://github.com/microsoft/playwright/blob/v1.16.2/installation-tests/installation-tests.sh#L200-L216
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1'
jobs:
# install dependencies, build shared components, cache both for subsequent jobs
install:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
# https://github.com/actions/cache/blob/8f1e2e02865c42348f9baddbbaafb1841dce610a/examples.md#node---yarn-2
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-v2-${{ hashFiles('**/yarn.lock') }}
- name: Cache .yarn/cache
if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' }}
uses: actions/cache@v3
with:
path: '.yarn/cache'
key: yarn-cache-${{ github.ref_name }}
restore-keys: yarn-cache-v3
- name: Install dependencies
if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' }}
run: yarn install --immutable --inline-builds
- name: cache shared components
id: cache-shared-components
uses: actions/cache@v3
with:
path: 'digitransit-*'
key: ${{ runner.os }}-shared-components-v2-${{ hashFiles('digitransit-*') }}
- name: build shared components
if: ${{ steps.cache-shared-components.outputs.cache-hit != 'true' }}
run: yarn run build-workspaces
lint:
needs: install
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: "Set time zone to Europe/Helsinki"
uses: zcong1993/setup-timezone@master
with:
timezone: "Europe/Helsinki"
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
# https://github.com/actions/cache/blob/8f1e2e02865c42348f9baddbbaafb1841dce610a/examples.md#node---yarn-2
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-v2-${{ hashFiles('**/yarn.lock') }}
- name: Cache .yarn/cache
if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' }}
uses: actions/cache@v3
with:
path: '.yarn/cache'
key: yarn-cache-${{ github.ref_name }}
restore-keys: yarn-cache-v3
- name: Install dependencies
if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' }}
run: yarn install --immutable --inline-builds
- name: cache shared components
id: cache-shared-components
uses: actions/cache@v3
with:
path: 'digitransit-*'
key: ${{ runner.os }}-shared-components-v2-${{ hashFiles('digitransit-*') }}
- name: Build shared components
if: ${{ steps.cache-shared-components.outputs.cache-hit != 'true' }}
run: yarn run build-workspaces
- name: Run linters
run: yarn lint
- name: lint SVG sprites using xmllint
run: |
sudo apt install -y libxml2-utils
xmllint --nonet --noout static/assets/svg-sprite.*.svg
build:
needs: install
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
# https://github.com/actions/cache/blob/8f1e2e02865c42348f9baddbbaafb1841dce610a/examples.md#node---yarn-2
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-v2-${{ hashFiles('**/yarn.lock') }}
- name: Cache .yarn/cache
if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' }}
uses: actions/cache@v3
with:
path: '.yarn/cache'
key: yarn-cache-${{ github.ref_name }}
restore-keys: yarn-cache-v3
- name: Install dependencies
if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' }}
run: yarn --immutable
- name: cache shared components
id: cache-shared-components
uses: actions/cache@v3
with:
path: 'digitransit-*'
key: ${{ runner.os }}-shared-components-v2-${{ hashFiles('digitransit-*') }}
- name: build shared components
if: ${{ steps.cache-shared-components.outputs.cache-hit != 'true' }}
run: yarn run build-workspaces
- name: cache built Relay queries & UI
id: cache-ui-build
uses: actions/cache@v3
with:
path: |
./_static
./manifest.json
./stats.json
./__generated__
**/__generated__
key: relay-ui-${{ github.sha }}
- name: build Relay queries & UI
if: ${{ steps.cache-ui-build.outputs.cache-hit != 'true' }}
run: |
yarn build
unit-test:
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: "Set time zone to Europe/Helsinki"
uses: zcong1993/setup-timezone@master
with:
timezone: "Europe/Helsinki"
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
# https://github.com/actions/cache/blob/8f1e2e02865c42348f9baddbbaafb1841dce610a/examples.md#node---yarn-2
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-v2-${{ hashFiles('**/yarn.lock') }}
- name: Cache .yarn/cache
if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' }}
uses: actions/cache@v3
with:
path: '.yarn/cache'
key: yarn-cache-${{ github.ref_name }}
restore-keys: yarn-cache-v3
- name: Install dependencies
if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' }}
run: yarn install --immutable --inline-builds
- name: cache shared components
id: cache-shared-components
uses: actions/cache@v3
with:
path: 'digitransit-*'
key: ${{ runner.os }}-shared-components-v2-${{ hashFiles('digitransit-*') }}
- name: Build shared components
if: ${{ steps.cache-shared-components.outputs.cache-hit != 'true' }}
run: yarn run build-workspaces
- name: cache built Relay queries & UI
id: cache-ui-build
uses: actions/cache@v3
with:
path: |
./_static
./manifest.json
./stats.json
./__generated__
**/__generated__
key: relay-ui-${{ github.sha }}
- name: build Relay queries & UI
if: ${{ steps.cache-ui-build.outputs.cache-hit != 'true' }}
run: |
yarn build
- name: Run unit tests
run: yarn run test-coverage
- name: Send test coverage report
run: yarn run test-report
docker-push:
# Because we use one full CI run for a deployment of *each* instance (i.e. n deployments for n instances),
# in order to deploy reasonably quickly, we assume the the Docker build caches intermediate layers across
# CI runs.
# The docker/build-push-action's GitHub caching option (cache-from, cache-to, see https://github.com/docker/build-push-action/blob/v4/README.md#customizing)
# uses BuildKit's GitHub caching feature (https://github.com/moby/buildkit/blob/c81deef18855d952247915d3418371f405719a23/README.md#github-actions-cache-experimental),
# which follows the general GitHub Actions caching restrictions (https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache).
# The means that Git tag CI runs *cannot* access each other's cached Docker layers, but only the default
# branch's one. This is why, on the default branch (`bbnavi`), we *do* build & cache the Docker layers
# but don't push and don't deploy the resulting image.
# todo: as of 2023-04-27, this fails because of https://github.com/moby/buildkit/issues/2887
if: github.ref_name == 'bbnavi' || (github.ref_type == 'tag' && startsWith(github.ref_name, 'release_'))
needs:
- lint
- unit-test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set time zone to Europe/Helsinki
uses: zcong1993/setup-timezone@master
with:
timezone: "Europe/Helsinki"
- name: Create buildInfo.js file
run: |
echo -e "export const COMMIT_ID = \"${GITHUB_SHA}\";\nexport const BUILD_TIME = \"$(date -Iminutes -u)\";" >app/buildInfo.js
- name: Configure Docker Buildx
uses: docker/setup-buildx-action@v1
- name: log into GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: parse name of bbnavi config from Git tag
id: bbnavi-config
# Strip "release_" prefix & date suffix from Git tag, set as output.
# With an invalid tag (e.g. `release_foo_bar`), this fails.
run: |
set -e -u -o pipefail # fail on errors
sudo apt install --no-install-recommends -qq -y pcre2-utils
set -x
# https://mattdood.com/2022/3/github-actions-conditional-environment-variables-20220325012837
if [[ -n "${{ github.ref_type == 'tag' && startsWith(github.ref_name, 'release_') || '' }}" ]]; then
cfg="$(echo -n "${{ github.ref_name }}" | pcre2grep -o1 '(?:release_)([\w-]+)(?:_\d{4}-\d{2}-\d{2})')"
echo 'should-deploy=yes' >>$GITHUB_OUTPUT
else
cfg="${{ github.ref_name }}"
fi
echo "cfg=\"$cfg\"" >>$GITHUB_OUTPUT
- name: compute Docker image metadata
id: docker-meta
run: |
set -e -x -u -o pipefail # fail on errors
echo "image=ghcr.io/${{ github.repository }}" >>$GITHUB_OUTPUT
echo "permanent-tag=$(date +"%Y-%m-%dT%H.%M.%S")-${GITHUB_SHA:0:7}" >>$GITHUB_OUTPUT
echo "release-tag=${{ github.ref_name }}" >>$GITHUB_OUTPUT
- name: build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
tags: |
${{ steps.docker-meta.outputs.image }}:${{ steps.docker-meta.outputs.permanent-tag }}
${{ steps.docker-meta.outputs.image }}:${{ steps.docker-meta.outputs.release-tag }}
# https://github.com/docker/build-push-action/blob/9472e9021074a3cb3279ba431598b8836d40433f/docs/advanced/cache.md#github-cache
# https://github.com/moby/buildkit#registry-push-image-and-cache-separately
cache-from: type=gha
cache-to: type=gha,mode=max,oci-mediatypes=true,compression=zstd
push: ${{ steps.bbnavi-config.outputs.should-deploy == 'yes' }}
- name: generate Docker Swarm stack definition
if: ${{ steps.bbnavi-config.outputs.should-deploy == 'yes' }}
env:
DOCKER_IMAGE: ${{ steps.docker-meta.outputs.image }}
DOCKER_TAG: ${{ steps.docker-meta.outputs.permanent-tag }}
FAHRGEMEINSCHAFT_API_KEY: ${{ secrets.FAHRGEMEINSCHAFT_API_KEY }}
run: |
set -e -x -u -o pipefail # fail on errors
docker-compose \
-f docker-compose.yml -f deployment/stack.yml \
-f "deployment/stack.${{ steps.bbnavi-config.outputs.cfg }}.yml" \
config | tee quantum.yml
- name: deploy stack using Planetary Quantum CLI
if: ${{ steps.bbnavi-config.outputs.should-deploy == 'yes' }}
env:
QUANTUM_ENDPOINT: tpwd-bb-navi
QUANTUM_PROJECT: bbnavi-digitransit-ui
QUANTUM_USER: ${{ secrets.QUANTUM_USER }}
QUANTUM_PASSWORD: ${{ secrets.QUANTUM_PASSWORD }}
run: |
set -e -x -u -o pipefail # fail on errors
# The "bb-" namespace stands for "Brandenburg", in case we ever have instances in other regions.
stack="$QUANTUM_PROJECT-bb-${{ steps.bbnavi-config.outputs.cfg }}"
docker run --rm -i \
-v $PWD:/app:ro -w /app \
-e QUANTUM_ENDPOINT -e QUANTUM_PROJECT -e QUANTUM_USER -e QUANTUM_PASSWORD \
r.planetary-quantum.com/quantum-public/cli:2 \
quantum-cli stack update --create --stack "$stack" --wait