deploy-prod #181
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: Deploy app to production | |
on: | |
repository_dispatch: | |
types: deploy-prod | |
env: | |
CI: true | |
NODE_ENV: production | |
DB_URI: ${{ secrets.DB_URI }} | |
AZURE_STORAGE_ACCOUNT: ${{ secrets.AZURE_STORAGE_ACCOUNT }} | |
jobs: | |
initial-setup: | |
name: "Initial setup" | |
uses: engagementlab/el-next/.github/workflows/init.yml@main | |
with: | |
branch: production | |
run-cms: | |
needs: initial-setup | |
name: "Run CMS, make build" | |
# Do not run on automated commits (interpretation of TravisCI feature) | |
if: "!contains(github.event.head_commit.message, 'skip ci') && github.actor != 'dependabot[bot]'" | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [16.13.1] | |
steps: | |
- name: Setup node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: Download artifacts from initial-setup job | |
uses: actions/download-artifact@v3 | |
with: | |
name: ${{ format('artifact-repo-{0}', github.run_id) }} | |
- name: Install global packages | |
run: npm install -g yarn pm2 @preconstruct/cli | |
- name: Install local monorepo packages and run preconstruct | |
run: yarn | |
- name: Generate build notes and summary from user | |
if: ${{ github.event.client_payload.note != 'null' && github.event.client_payload.note.length > 0 }} | |
run: | | |
echo "**Publishing summary from user:**" >> $GITHUB_STEP_SUMMARY | |
echo "_${{ github.event.client_payload.note }}_" >> $GITHUB_STEP_SUMMARY | |
- name: Make production build | |
working-directory: ${{ format('apps/{0}', github.event.client_payload.appName) }} | |
env: | |
GRAPHQL_APP: ${{ github.event.client_payload.appName }} | |
NODE_TLS_REJECT_UNAUTHORIZED: '0' | |
run: | | |
yarn add typescript @types/node | |
yarn | |
yarn build | |
- name: Archive production artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ format('artifact-build-{0}', github.run_id) }} | |
retention-days: 1 | |
path: | | |
${{ format('apps/{0}/out', github.event.client_payload.appName) }} | |
./scripts/upload.sh | |
./scripts/commit.sh | |
outputRoutes.mjs | |
package.json | |
production-publish: | |
name: "Publish new build to production" | |
needs: [initial-setup, run-cms] | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [16.13.1] | |
steps: | |
- name: Download artifacts from production build job | |
uses: actions/download-artifact@v3 | |
with: | |
name: ${{ format('artifact-build-{0}', github.run_id) }} | |
# - name: Install packages | |
# run: npm i -g pa11y-ci http-server pm2 && npm i | |
# - name: Serve build | |
# working-directory: ./ | |
# run: pm2 start `which http-server` --name server | |
# - name: Output all build paths to .pa11yci config and run pa11y | |
# run: | | |
# node outputRoutes.mjs --app ${{ github.event.client_payload.appName }} | |
# pa11y-ci | |
- name: Login to Azure | |
uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
# Deploy static build to Azure storage if succeeded | |
- name: Deploy static build | |
uses: azure/CLI@v1 | |
with: | |
inlineScript: | | |
az storage blob upload-batch --overwrite true --account-name ${{ github.event.client_payload.storageAccount }} --auth-mode key -d '$web' -s ./apps/${{ github.event.client_payload.appName }}/out | |
- name: Purge CDN endpoint | |
uses: azure/CLI@v1 | |
with: | |
inlineScript: | | |
az cdn endpoint purge --content-paths "/*" --profile-name web-apps -n ${{ github.event.client_payload.cdnName }} -g web | |
# Azure logout | |
- name: logout | |
run: | | |
az logout | |
if: always() | |
notify-success: | |
name: Send success Slack notification | |
needs: [initial-setup, run-cms, production-publish] | |
if: ${{ success() }} | |
uses: engagementlab/el-next/.github/workflows/slack.yml@main | |
with: | |
apexUrl: ${{ github.event.client_payload.apexUrl }} | |
note: ${{ github.event.client_payload.note }} | |
userName: ${{ github.event.client_payload.userName }} | |
success: true | |
secrets: inherit | |
notify-failure: | |
name: Send failure Slack notification | |
needs: [initial-setup, run-cms, production-publish] | |
if: ${{ failure() }} | |
uses: engagementlab/el-next/.github/workflows/slack.yml@main | |
with: | |
apexUrl: ${{ github.event.client_payload.apexUrl }} | |
note: ${{ github.event.client_payload.note }} | |
userName: ${{ github.event.client_payload.userName }} | |
success: false | |
secrets: inherit |