Changes for presidential election, switch order of preferred candidate and email collection pages #1826
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: "Frontend: build, test, lint & deploy" | |
on: | |
push: | |
branches: [main, aws] | |
paths: | |
- frontend/** | |
pull_request: | |
paths: | |
- frontend/** | |
workflow_dispatch: | |
jobs: | |
build: | |
name: Build, test & lint | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: frontend | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
- name: Get NPM cache folder path | |
id: npm-cache-folder | |
run: | | |
echo "::set-output name=path::$(npm config get cache)" | |
- name: Set up NPM cache | |
uses: actions/cache@v3 | |
id: npm-cache | |
env: | |
cache-name: frontend-node-modules | |
with: | |
path: ${{ steps.npm-cache-folder.outputs.path }} | |
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-${{ env.cache-name }}- | |
- name: Install dependencies | |
run: | | |
npm ci | |
- name: Lint | |
run: | | |
npm run lint | |
- name: Check formatting | |
run: | | |
npx prettier --check . | |
- name: Build | |
run: | | |
npm run build | |
- name: Run unit tests | |
run: | | |
npm run test:unit | |
- if: false | |
name: Run end-to-end tests | |
run: | | |
npm run test:e2e:ci | |
- if: github.ref == 'refs/heads/aws' | |
name: Upload build | |
uses: actions/upload-artifact@v3 | |
with: | |
name: frontend-${{ github.sha }} | |
path: frontend/dist | |
retention-days: 1 | |
deploy: | |
if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/aws' | |
name: Deploy | |
runs-on: ubuntu-latest | |
needs: build | |
env: | |
BUCKET: ${{ secrets.FRONTEND_BUCKET_NAME }} | |
CLOUDFRONT_DEPLOYMENT_ID: ${{ secrets.CLOUDFRONT_DEPLOYMENT_ID }} | |
steps: | |
- name: Download build | |
uses: actions/download-artifact@v3 | |
with: | |
name: frontend-${{ github.sha }} | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: eu-central-1 | |
- name: Deploy to S3 | |
run: | | |
aws s3 sync --sse --delete . s3://${{ env.BUCKET }} | |
- name: Invalidate CloudFront cache | |
run: | | |
aws cloudfront create-invalidation --distribution-id ${{ env.CLOUDFRONT_DEPLOYMENT_ID }} --paths "/*" |