newtheatre/history-project

View on GitHub
.github/workflows/api.yml

Summary

Maintainability
Test Coverage
name: api

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    name: Build and deploy content
    runs-on: ubuntu-22.04
    permissions:
      deployments: write

    steps:
      - name: Checkout repo
        uses: actions/checkout@v3
      - name: Set up a python environment
        uses: actions/setup-python@v4
        with:
          python-version: '3.11'
      - name: Cache python dependencies
        uses: actions/cache@v3
        with:
          path: ~/.cache/pip
          key: pip-cache-1
      - name: Install dependencies
        run: |
          python -m pip install -U nthp_api
      - name: Print version of nthp-api
        run: nthp version

      - name: Download SmugMug db cache
        uses: actions/cache@v3
        with:
          path: nthp.smug.db
          key: smugmug-1
      - name: Fetch prebuilt SmugMug db if not cached
        run: wget -nc https://nthp-seed.s3.eu-west-2.amazonaws.com/nthp.smug.db

      - name: Run build job
        run: nthp build .
        env:
          SMUGMUG_API_KEY: ${{ secrets.SMUGMUG_API_KEY }}

      - name: Get deploy name
        id: deploy_vars
        run: source _bin/deploy_vars.sh
        env:
          REF_NAME: ${{ github.ref_name }}

      - uses: chrnorm/deployment-action@v2
        name: Create GitHub deployment
        id: create_deployment
        with:
          token: '${{ github.token }}'
          environment: ${{ steps.deploy_vars.outputs.ENVIRONMENT }}
          environment-url: https://nthp-web.pages.dev/?pr=${{ steps.deploy_vars.outputs.DEPLOY_NAME }}
          state: in_progress

      - name: Deploy to S3
        run: _bin/deploy.sh
        env:
          DEPLOY_NAME: ${{ steps.deploy_vars.outputs.DEPLOY_NAME }}
          AWS_REGION: ${{ secrets.AWS_REGION }}
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}

      - uses: chrnorm/deployment-status@v2
        if: success()
        name: Update deployment status (success)
        id: update_deployment_success
        with:
          token: '${{ github.token }}'
          deployment-id: ${{ steps.create_deployment.outputs.deployment_id }}
          environment-url: https://nthp-web.pages.dev/?pr=${{ steps.deploy_vars.outputs.DEPLOY_NAME }}
          state: success

      - uses: chrnorm/deployment-status@v2
        if: failure()
        name: Update deployment status (failure)
        id: update_deployment_failure
        with:
          token: '${{ github.token }}'
          deployment-id: ${{ steps.create_deployment.outputs.deployment_id }}
          state: failure