-
Notifications
You must be signed in to change notification settings - Fork 0
172 lines (149 loc) · 6.3 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#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'