Make properties public #71
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 deploy' | |
env: # Keep this in sync with Dockerfile version | |
NODE_VERSION: "20.13.1" | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
types: [ opened, synchronize ] | |
workflow_dispatch: | |
jobs: | |
lint: | |
name: 'Lint' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- uses: actions/cache@v3 | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: 'Install' | |
run: npm install | |
- name: 'Lint' | |
run: npm run lint | |
env: | |
NODE_OPTIONS: '--max-old-space-size=8192' | |
test: | |
name: 'Test' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- uses: actions/cache@v3 | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: 'Install' | |
run: npm install | |
- name: 'Test' | |
run: npm run test:ci | |
- name: 'Upload test results' | |
uses: actions/upload-artifact@v3 | |
if: always() | |
with: | |
name: Test Results | |
path: junit.xml | |
# Upload event file so test results can be processed for the PR | |
# https://github.com/EnricoMi/publish-unit-test-result-action#support-fork-repositories-and-dependabot-branches | |
event_file: | |
name: "Event File" | |
runs-on: ubuntu-latest | |
steps: | |
- name: Upload | |
uses: actions/upload-artifact@v3 | |
with: | |
name: Event File | |
path: ${{ github.event_path }} | |
build: | |
name: 'Build and deploy' | |
runs-on: ubuntu-22.04 | |
if: vars.DEPLOY == 'true' | |
env: | |
VERSION: snapshot | |
COMPOSE_PROJECT_NAME: ${{ vars.DEPLOY_PROJECT_NAME }}-snapshot | |
COMPOSE_FILE: docker-compose.yml:docker-compose.traefik.yml:../compose.yaml | |
BASE_HREF: / | |
HOST: ${{ vars.DEPLOY_HOSTNAME }} | |
ADMIN_HASHED_PASSWORD: ${{ vars.ADMIN_HASHED_PASSWORD }} | |
SOURCE_MAP_AUTH: ${{ secrets.SOURCE_MAP_AUTH }} | |
BUILDX_NO_DEFAULT_ATTESTATIONS: 1 | |
needs: [ lint, test ] | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
# If tags aren't fetched the bin/post-build-localized.js script will leave fields in generated/version.json empty | |
# https://github.com/actions/checkout/issues/701 | |
fetch-depth: 0 | |
- name: 'GitHub Slug Action' | |
uses: rlespinasse/github-slug-action@v4 | |
- name: 'Find Current Pull Request' | |
uses: jwalton/gh-find-current-pr@v1 | |
id: find-pr | |
- name: 'Set variables for PR' | |
# When running on a PR, build and tag the Docker image for a deployment with a different base-href and a static-only deployment on | |
# a path prefix, with the frontend using the /api URL from the main branch deployment. | |
if: ${{ success() && steps.find-pr.outputs.number }} | |
env: | |
PR: ${{ steps.find-pr.outputs.number }} | |
run: | | |
echo "VERSION=pr-${PR}" >> $GITHUB_ENV | |
echo "COMPOSE_PROJECT_NAME=${{ vars.DEPLOY_PROJECT_NAME }}-pr-${PR}" >> $GITHUB_ENV | |
echo "COMPOSE_FILE=docker-compose.yml:docker-compose.traefik.yml:ci/docker-compose.pr.yml" >> $GITHUB_ENV | |
echo "BASE_HREF=/pull-request/${PR}/${GITHUB_REF_NAME_SLUG_URL}/" >> $GITHUB_ENV | |
- name: 'Build image' | |
# Always uses the 'snapshot' tag of the tailormap-api base image by setting the API_VERSION build arg | |
run: | | |
docker build --progress plain --build-arg BASE_HREF=${BASE_HREF} --build-arg VERSION=${VERSION} --build-arg API_VERSION=snapshot --tag ${{ vars.DEPLOY_IMAGE_TAG }}:${VERSION} . | |
docker save ${{ vars.DEPLOY_IMAGE_TAG }}:${VERSION} > image.tar | |
- name: 'Set Docker context for deployment' | |
uses: arwynfr/actions-docker-context@v2 | |
with: | |
docker_host: ${{ secrets.DEPLOY_DOCKER_HOST }} | |
context_name: 'dev-server' | |
ssh_cert: ${{ secrets.DEPLOY_DOCKER_HOST_SSH_CERT }} | |
ssh_key: ${{ secrets.DEPLOY_DOCKER_HOST_SSH_KEY }} | |
use_context: true | |
- name: 'Add known hosts' | |
run: | | |
DEPLOY_DOCKER_HOST=${{ secrets.DEPLOY_DOCKER_HOST }} | |
ssh-keyscan -H ${DEPLOY_DOCKER_HOST##*@} > $HOME/.ssh/known_hosts | |
- name: 'Load Docker image' | |
run: | | |
docker image rm ${{ vars.DEPLOY_IMAGE_TAG }}:${VERSION} || true | |
cat image.tar | docker load | |
- uses: actions/checkout@v4 | |
with: | |
repository: B3Partners/tailormap-viewer | |
path: tailormap-viewer | |
sparse-checkout: | | |
docker-compose*.yml | |
sparse-checkout-cone-mode: false | |
- name: 'Update deployment using Docker Compose' | |
env: | |
TAILORMAP_IMAGE: ${{ vars.DEPLOY_IMAGE_TAG }} | |
run: | | |
cd tailormap-viewer | |
docker compose config | |
docker compose up -d --pull=always | |
- name: 'Create GitHub deployment' | |
if: success() | |
uses: chrnorm/deployment-action@v2 | |
with: | |
token: "${{ secrets.GITHUB_TOKEN }}" | |
environment-url: "https://${{ vars.DEPLOY_HOSTNAME }}${{ env.BASE_HREF }}" | |
description: "Deployment for ${{ env.VERSION }}" | |
environment: test | |
initial-status: success | |
ref: "${{ env.GITHUB_HEAD_REF }}" |