add SHA environment variable and build step for analysis in CI workflow #9
This file contains hidden or 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: CI | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| # Publish semver tags as releases. | |
| tags: [ 'v*.*.*' ] | |
| pull_request: | |
| branches: [ "main" ] | |
| env: | |
| REGISTRY: docker.io | |
| DOCKER_USERNAME: argentinaluiz | |
| IMAGE_NAME: argentinaluiz/docker-prod-test | |
| SHA: ${{ github.event.pull_request.head.sha || github.event.after }} | |
| jobs: | |
| ci: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log into registry ${{ env.REGISTRY }} | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ env.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_TOKEN }} | |
| - name: Build for CI | |
| id: build-ci | |
| uses: docker/[email protected] | |
| with: | |
| context: ./src/ci/nestjs-project | |
| file: ./src/ci/nestjs-project/Dockerfile.prod | |
| push: false | |
| load: true # driver docker-container | |
| target: ci | |
| tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:ci | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| secrets: | | |
| github_token=${{ secrets.MY_GITHUB_TOKEN }} | |
| - name: Up containers | |
| run: docker compose -f ./src/ci/nestjs-project/compose.ci.yaml up -d --wait-timeout 10 | |
| - name: Run tests | |
| run: echo "Running tests..." | |
| - name: Build for analysis | |
| id: build-for-analysis | |
| uses: docker/[email protected] | |
| with: | |
| context: ./src/ci/nestjs-project | |
| file: ./src/ci/nestjs-project/Dockerfile.prod | |
| push: false | |
| load: true | |
| tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.SHA }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| secrets: | | |
| github_token=${{ secrets.MY_GITHUB_TOKEN }} | |