Aam-Digital/ndb-core

View on GitHub
.github/workflows/pull-request-update.yml

Summary

Maintainability
Test Coverage
name: Pipeline
on: pull_request

jobs:
  run-tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v2
      - name: Get time of commit
        run: echo "TIME=$(git log -1 --pretty=format:%ct)" >> $GITHUB_ENV
      - name: Run tests in Docker image
        uses: docker/build-push-action@v3
        with:
          context: ./
          file: ./build/Dockerfile
          builder: ${{ steps.buildx.outputs.name }}
          target: builder
          tags: test-image
          build-args: |
            UPLOAD_COVERAGE=${{ true }}
            GIT_COMMIT_SHA=${{ github.event.pull_request.head.sha }}
            GIT_BRANCH=${{ github.head_ref }}
            GIT_COMMITTED_AT=${{ env.TIME }}
            CC_TEST_REPORTER_ID=${{ secrets.CODE_CLIMATE_ID }}
            BUILD=${{ false }}
          cache-from: type=gha
          cache-to: type=gha,mode=max
      - name: Run tests with timezone
        uses: docker/build-push-action@v3
        with:
          context: ./
          file: ./build/Dockerfile
          builder: ${{ steps.buildx.outputs.name }}
          target: builder
          build-args: |
            RUN_TESTS=${{ true }}
            TZ=America/Detroit
            BUILD=${{ false }}
          cache-from: type=gha
          cache-to: type=gha,mode=max
  deploy-prod-image:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Login to DockerHub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v2
      - name: Build and push PR image
        uses: docker/build-push-action@v3
        with:
          context: ./
          file: ./build/Dockerfile
          builder: ${{ steps.buildx.outputs.name }}
          push: true
          tags: aamdigital/ndb-server:pr-${{ github.event.number }}
          cache-from: type=gha
          cache-to: type=gha,mode=max
      - name: Deploy updated image
        uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.SSH_HOST }}
          username: ${{ secrets.SSH_USERNAME }}
          key: ${{ secrets.SSH_KEY }}
          script: |
            cd /var/docker/pr-${{ github.event.number }}
            docker compose pull
            docker compose up -d