Merge pull request #94 from idmc-labs/fix/good-practice-query #383
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 | |
on: | |
pull_request: | |
push: | |
branches: | |
- release | |
jobs: | |
build_test: | |
name: π΄ Build + Lint + Test π΄ # Match the name below (8398a7/action-slack). | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: π³ Prepare Docker | |
id: prep | |
run: | | |
TAG=$(echo $GITHUB_SHA | head -c7) | |
IMAGE="ghcr.io/${GITHUB_REPOSITORY}" | |
echo ::set-output name=tagged_image::${IMAGE}:${TAG} | |
echo ::set-output name=tag::${TAG} | |
- name: π³ Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@master | |
- name: π³ Cache Docker layers | |
uses: actions/cache@v2 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-single-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-single-buildx | |
- name: π³ Build image | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
builder: ${{ steps.buildx.outputs.name }} | |
file: Dockerfile | |
push: false # This would be set to true in a real world deployment scenario. | |
load: true | |
tags: ${{ steps.prep.outputs.tagged_image }} | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache-new | |
- name: π€ Run Lint π§ͺ | |
env: | |
DOCKER_IMAGE: ${{ steps.prep.outputs.tagged_image }} | |
run: | | |
docker run --rm --workdir="/code/" $DOCKER_IMAGE sh -c 'yarn lint' | |
# - name: π€ Run Test π§ͺ | |
# env: | |
# DOCKER_IMAGE: ${{ steps.prep.outputs.tagged_image }} | |
# run: | | |
# docker run --rm --workdir="/code/" $DOCKER_IMAGE sh -c 'yarn test' | |
# | |
- name: π€ Run Build π§ͺ (PREVIEW) | |
env: | |
DOCKER_IMAGE: ${{ steps.prep.outputs.tagged_image }} | |
REACT_APP_GIDD_GRAPHQL_ENDPOINT: https://website-api.idmcdb.org/graphql/ | |
REACT_APP_HELIX_GRAPHQL_ENDPOINT: https://helix-tools-api.idmcdb.org/graphql | |
REACT_APP_HELIX_REST_ENDPOINT: https://helix-tools-api.idmcdb.org/external-api/ | |
REACT_APP_HELIX_CLIENT_ID: IDMCWSHSOLO009 | |
REACT_APP_MAPBOX_ACCESS_TOKEN: pk.eyJ1IjoidG9nZ2xlY29ycCIsImEiOiJjazk5ZXMza2YxZmQ1M2dvNWxneTEycnQwIn0.K3u-ns63rFzM7CzrnOBm2w | |
REACT_APP_MAPBOX_STYLE: mapbox://styles/togglecorp/cl50rwy0a002d14mo6w9zprio | |
REACT_APP_HCAPTCHA_SITEKEY: c81616ab-e71b-466a-a03a-650b2472fb34 | |
REACT_APP_TINY_MCE_KEY: o65ezg70uejj1ibo2janhtw6n1eiii7fm2w2yanfnvqe6ipa | |
REACT_APP_SENTRY_DSN: https://[email protected]/6409048 | |
# Release config (ONLY DIFFERENT) | |
REACT_APP_DRUPAL_ENDPOINT: https://staging.internal-displacement.org | |
REACT_APP_ENVIRONMENT: preview | |
REACT_APP_DATA_RELEASE: PRE_RELEASE | |
run: | | |
env > .env | |
docker run --rm --workdir="/code/" -v `pwd`/.env:/code/.env -v `pwd`/build-preview/:/code/build/ $DOCKER_IMAGE sh -c 'yarn build' | |
- name: π€ Run Build π§ͺ (RELEASE) | |
env: | |
DOCKER_IMAGE: ${{ steps.prep.outputs.tagged_image }} | |
REACT_APP_GIDD_GRAPHQL_ENDPOINT: https://website-api.idmcdb.org/graphql/ | |
REACT_APP_HELIX_GRAPHQL_ENDPOINT: https://helix-tools-api.idmcdb.org/graphql | |
REACT_APP_HELIX_REST_ENDPOINT: https://helix-tools-api.idmcdb.org/external-api/ | |
REACT_APP_HELIX_CLIENT_ID: IDMCWSHSOLO009 | |
REACT_APP_MAPBOX_ACCESS_TOKEN: pk.eyJ1IjoidG9nZ2xlY29ycCIsImEiOiJjazk5ZXMza2YxZmQ1M2dvNWxneTEycnQwIn0.K3u-ns63rFzM7CzrnOBm2w | |
REACT_APP_MAPBOX_STYLE: mapbox://styles/togglecorp/cl50rwy0a002d14mo6w9zprio | |
REACT_APP_HCAPTCHA_SITEKEY: c81616ab-e71b-466a-a03a-650b2472fb34 | |
REACT_APP_TINY_MCE_KEY: o65ezg70uejj1ibo2janhtw6n1eiii7fm2w2yanfnvqe6ipa | |
REACT_APP_SENTRY_DSN: https://[email protected]/6409048 | |
# Release config (ONLY DIFFERENT) | |
REACT_APP_DRUPAL_ENDPOINT: https://www.internal-displacement.org | |
REACT_APP_ENVIRONMENT: release | |
REACT_APP_DATA_RELEASE: RELEASE | |
run: | | |
env > .env | |
docker run --rm --workdir="/code/" -v `pwd`/.env:/code/.env -v `pwd`/build-release/:/code/build/ $DOCKER_IMAGE sh -c 'yarn build' | |
- name: Save build files as artifact (PREVIEW) | |
uses: actions/upload-artifact@v1 | |
with: | |
name: preview-idmc-website-components | |
path: build-preview | |
- name: Save build files as artifact (RELEASE) | |
uses: actions/upload-artifact@v1 | |
with: | |
name: release-idmc-website-components | |
path: build-release | |
# Temp fix | |
# https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#github-cache | |
# https://github.com/docker/build-push-action/issues/252 | |
# https://github.com/moby/buildkit/issues/1896 | |
- name: π³ Move docker cache (π§ Hack fix) | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache | |
preview_deploy: | |
name: Deploy (PREVIEW) | |
needs: build_test | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' | |
environment: | |
name: preview | |
url: https://preview-website-components.idmcdb.org | |
steps: | |
- uses: actions/download-artifact@v1 | |
with: | |
name: preview-idmc-website-components | |
path: build | |
# Copy build to S3 | |
- name: S3 Sync | |
uses: jakejarvis/s3-sync-action@master | |
with: | |
args: --follow-symlinks --delete | |
env: | |
AWS_S3_BUCKET: ${{ secrets.PREVIEW_AWS_S3_BUCKET }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.PREVIEW_AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.PREVIEW_AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: ${{ secrets.PREVIEW_AWS_REGION }} | |
SOURCE_DIR: './build' | |
# Invalidate Cloudfront (this action) | |
- name: Cloudfront Invalidate | |
uses: chetan/invalidate-cloudfront-action@master | |
env: | |
DISTRIBUTION: ${{ secrets.PREVIEW_AWS_CLOUDFRONT_DISTRIBUTION }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.PREVIEW_AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.PREVIEW_AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: ${{ secrets.PREVIEW_AWS_REGION }} | |
PATHS: '/*' | |
release_deploy: | |
name: Deploy (RELEASE) | |
needs: [build_test, preview_deploy] | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' | |
environment: | |
name: release | |
url: https://release-website-components.idmcdb.org | |
steps: | |
- uses: actions/download-artifact@v1 | |
with: | |
name: release-idmc-website-components | |
path: build | |
# Copy build to S3 | |
- name: S3 Sync | |
uses: jakejarvis/s3-sync-action@master | |
with: | |
args: --follow-symlinks --delete | |
env: | |
AWS_S3_BUCKET: ${{ secrets.RELEASE_AWS_S3_BUCKET }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.RELEASE_AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.RELEASE_AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: ${{ secrets.RELEASE_AWS_REGION }} | |
SOURCE_DIR: './build' | |
# Invalidate Cloudfront (this action) | |
- name: Cloudfront Invalidate | |
uses: chetan/invalidate-cloudfront-action@master | |
env: | |
DISTRIBUTION: ${{ secrets.RELEASE_AWS_CLOUDFRONT_DISTRIBUTION }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.RELEASE_AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.RELEASE_AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: ${{ secrets.RELEASE_AWS_REGION }} | |
PATHS: '/*' |