Skip to content

ci

ci #338

Workflow file for this run

#https://emojipedia.org for emotes
name: ci
on:
workflow_dispatch:
inputs:
cacheClean:
description: 'CI Cache Clean'
required: false
default: ''
name:
description: 'Name of the proceedings to update'
required: true
default: 'PFIAS'
domain:
description: 'Subdomain of the proceedings to update'
required: true
default: 'france'
# push:
# branches:
# - main
# paths-ignore:
# - 'infra/**'
env:
ENV: ${{ github.ref == 'refs/heads/main' && 'prod' || 'dev' }}
AWS_REGION: 'eu-west-3' # paris
NODE_OPTIONS: '--max_old_space_size=4096' # fix heap out of memory error (nuxt generate)
jobs:
install:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
node: [18]
steps:
- name: 🛎 Checkout ${{ github.event.inputs.name }}
uses: actions/checkout@v3
with:
submodules: true
token: ${{ secrets.SUBMODULE_GIT_TOKEN }}
# Cancel previous runs to avoid wasting resources
- name: 🧹 clean up runners
# TODO replace hard coded references to the repo with variables
run: |
ids=$(gh api -H "Accept: application/vnd.github+json" /repos/IEA-Paris/PIAS/actions/runs | jq -s -c 'sort_by(.created_at) | .[]' | jq '.workflow_runs[] | select([.status] | inside(["in_progress", "queued"])) | .id')
nids=$(echo $ids | wc -w)
if [ $nids -gt 2 ]; then
echo "too many runners"
# Delete first and last runner
ids=$(echo $ids | cut -d ' ' -f 2- | rev | cut -d ' ' -f 2- | rev)
set -- $ids
# Stop all runners between first and last
for i; do gh api --method POST -H "Accept: application/vnd.github+json" "/repos/IEA-Paris/PIAS/actions/runs/$i/cancel"; done
fi
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: 🏗 Setup node env
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
check-latest: true
- name: 🔄 Update submodules
shell: bash
run: |
git submodule update --init --remote && git submodule foreach git config pull.rebase true && git checkout main && git pull origin main --allow-unrelated-histories
rm -rf ./static/*
echo `ls submodules/${{ github.event.inputs.name }}`
cp -r ./submodules/${{ github.event.inputs.name }}/config.js ./config.js
cp -r ./submodules/${{ github.event.inputs.name }}/generated .
cp -r ./submodules/${{ github.event.inputs.name }}/static .
cp -r ./submodules/${{ github.event.inputs.name }}/pdfs ./static
cp -r ./submodules/${{ github.event.inputs.name }}/thumbnails ./static
cp -r ./submodules/${{ github.event.inputs.name }}/bibliography ./static
cp -r ./submodules/${{ github.event.inputs.name }}/svg ./static
cp -r ./admin ./static
- name: 🛠 Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: 📦 Cache node_modules
if: github.event.inputs.cacheClean == ''
uses: actions/cache@v3
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: 👨🏻‍💻 Install dependencies
run: yarn
- name: 🧪 Configure the CMS
run: yarn configCMS
#- name: Run tests 🧪
# run: yarn test
- name: 🤞 Generate ${{ github.event.inputs.name }}
run: yarn generate
env:
DEEPL_KEY: ${{ secrets.DEEPL_KEY }}
orcid: ${{secrets.ORCID_SANDBOX_ID}}
ORCID_SANDBOX_SECRET_KEY_ID: ${{secrets.ORCID_SANDBOX_SECRET_KEY_ID}}
# - name: Cache dist
# uses: actions/cache@v3
# with:
# path: dist
# key: ${{ matrix.os }}-node-v${{ matrix.node }}-${{ github.sha }}
- name: ⤴️ Retro push generated content 🧙‍♂️
# TODO replace hard coded references to the repo with variables
shell: bash
run: |
cd submodules/${{ github.event.inputs.name }}
rsync -av -a --include='*/' --exclude 'admin' --exclude='*' --exclude 'sw.js' ../../static/ ./static/
git config --global user.name "CI"
git config --global user.email "[email protected]"
git add .
echo `git commit -m "[skip ci] auto-generated content"`
echo `git status`
echo `git push -f origin HEAD:main`
- name: 🤫 Setting up AWS credentials
uses: 'aws-actions/configure-aws-credentials@v1'
with:
aws-access-key-id: ${{ env.ENV == 'prod' && secrets.AWS_ACCESS_KEY_ID || secrets.AWS_ACCESS_KEY_ID_DEV }}
aws-secret-access-key: ${{ env.ENV == 'prod' && secrets.AWS_SECRET_ACCESS_KEY || secrets.AWS_SECRET_ACCESS_KEY_DEV }}
aws-region: ${{ env.AWS_REGION }}
- name: 🤫 Getting cloudfront secrets
uses: 'marvinpinto/action-inject-ssm-secrets@latest'
with:
ssm_parameter: '/${{ github.event.inputs.name }}/cloudfront/id'
env_variable_name: 'ssm_cloudfront_id'
- name: 🤫 Getting S3 secrets
uses: 'marvinpinto/action-inject-ssm-secrets@latest'
with:
ssm_parameter: '/${{ github.event.inputs.name}}/s3/name'
env_variable_name: 'ssm_s3_name'
- name: 🚀 Deploy to S3 🚀🚀
uses: jakejarvis/s3-sync-action@master
with:
args: --acl public-read --follow-symlinks --delete
env:
AWS_S3_BUCKET: ${{ env.SSM_S3_NAME }}
SOURCE_DIR: 'dist'
- name: 🔃 Invalidate Cloudfront Cache
uses: chetan/invalidate-cloudfront-action@v2
env:
DISTRIBUTION: ${{ env.SSM_CLOUDFRONT_ID }}
PATHS: '/*'
- name: 🔌 Uptime Action
uses: srt32/[email protected]
# TODO replace hard coded references to the repo with variables
with:
url-to-hit: 'https://${{ github.event.inputs.domain }}.pias.science'
expected-statuses: '200,301'