diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 15e9ca36..6eda2479 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,5 +1,4 @@ ---- -name: 🧪 Test +name: Run tests on: pull_request: @@ -10,18 +9,12 @@ permissions: {} jobs: test: - name: Test runs-on: [self-hosted, management-ecr] - permissions: - contents: read + env: + LOGS_BUCKET_NAME: moj-analytics-s3-logs steps: - name: Checkout - id: checkout - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - # - name: Set Up Container Structure Test - # id: setup_container_structure_test - # uses: ministryofjustice/github-actions/setup-container-structure-test@ccf9e3a4a828df1ec741f6c8e6ed9d0acaef3490 # v18.5.0 + uses: actions/checkout@v2 - name: Set up Docker Context for Buildx id: buildx-context @@ -34,24 +27,45 @@ jobs: version: latest endpoint: builders - - name: Build with Docker Compose - id: build - shell: bash - env: - IMAGE_TAG: ${{ github.sha }} - run: | - make build - - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 with: aws-region: eu-west-1 role-to-assume: arn:aws:iam::593291632749:role/github-actions-management-ecr role-duration-seconds: 1200 - - - name: Run tests - env: - IMAGE_TAG: ${{ github.sha }} - NETWORK: default + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + with: + registries: 593291632749 + + - name: Prep Tags + id: prep run: | - make test-python \ No newline at end of file + TAG=noop + if [[ $GITHUB_REF == refs/tags/* ]]; then + TAG=${GITHUB_REF#refs/tags/} + elif [[ $GITHUB_REF == refs/pull/* ]]; then + TAG="sha-${GITHUB_SHA::8}" + elif [ "${{ github.event_name }}" = "push" ]; then + TAG="sha-${GITHUB_SHA::8}" + fi + echo ::set-output name=tag::${TAG} + echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') + - name: Build image + run: make build + env: + NETWORK: host + IMAGE_TAG: ${{ steps.prep.outputs.tag }} + + - name: Run Python tests (docker-compose) + run: make clean && make test + env: + NETWORK: default + IMAGE_TAG: ${{ steps.prep.outputs.tag }} + + - name: Push image + run: make push + env: + IMAGE_TAG: ${{ steps.prep.outputs.tag }} \ No newline at end of file