diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7b7dfed..488f4a0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,32 @@ on: - add-ci-tests jobs: + export_variables: + runs-on: ubuntu-latest + + outputs: + primary_image: ${{ steps.compute_container_registry_name.outputs.CR_NAME }}/${{ steps.calculate_primary_sha.outputs.PRIMARY_SHA }} + replica_image: ${{ steps.compute_container_registry_name.outputs.CR_NAME }}/${{ steps.calculate_replica_sha.outputs.REPLICA_SHA }} + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Compute container registry name + id: compute_container_registry_name + run: echo "CR_NAME=$(echo ghcr.io/${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT + + - name: Calculate SHA256 for postgres_primary.dockerfile + id: calculate_primary_sha + run: echo "PRIMARY_SHA=$(sha256sum postgres_primary.dockerfile | awk '{ print substr($1, 1, 12) }')" >> $GITHUB_OUTPUT + + - name: Calculate SHA256 for postgres_replica.dockerfile + id: calculate_replica_sha + run: echo "REPLICA_SHA=$(sha256sum postgres_replica.dockerfile | awk '{ print substr($1, 1, 12) }')" >> $GITHUB_OUTPUT + + prebuild: + needs: export_variables runs-on: ubuntu-latest steps: @@ -24,31 +49,23 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Calculate SHA256 for postgres_primary.dockerfile - run: echo "PRIMARY_SHA=$(sha256sum postgres_primary.dockerfile | awk '{ print substr($1, 1, 12) }')" >> $GITHUB_ENV - - - name: Calculate SHA256 for postgres_replica.dockerfile - run: echo "REPLICA_SHA=$(sha256sum postgres_replica.dockerfile | awk '{ print substr($1, 1, 12) }')" >> $GITHUB_ENV - - - name: Compute container registry name - run: echo "CR_NAME=$(echo ghcr.io/${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV - - name: Build and tag primary Docker image - run: docker build -f postgres_primary.dockerfile -t $CR_NAME/postgres_primary:${{ env.PRIMARY_SHA }} . + run: docker build -f postgres_primary.dockerfile -t ${{ needs.export_variables.outputs.primary_image }} . - name: Build and tag replica Docker image - run: docker build -f postgres_replica.dockerfile -t $CR_NAME/postgres_replica:${{ env.REPLICA_SHA }} . + run: docker build -f postgres_replica.dockerfile -t ${{ needs.export_variables.outputs.replica_image }} . - name: Push primary Docker image - run: docker push $CR_NAME/postgres_primary:${{ env.PRIMARY_SHA }} + run: docker push ${{ needs.export_variables.outputs.primary_image }} - name: Push replica Docker image - run: docker push $CR_NAME/postgres_replica:${{ env.REPLICA_SHA }} + run: docker push ${{ needs.export_variables.outputs.replica_image }} rspec: - needs: prebuild + needs: [export_variables, prebuild] runs-on: ubuntu-latest + strategy: matrix: ruby: [3.1.6, 3.2.5, 3.3.5] @@ -56,7 +73,7 @@ jobs: name: Ruby ${{ matrix.ruby }} / ActiveRecord ${{ matrix.rails }} services: postgres_primary: - image: $CR_NAME/postgres_primary:${{ env.PRIMARY_SHA }} + image: ${{ needs.export_variables.outputs.primary_image }} ports: - 5432:5432 env: @@ -67,7 +84,7 @@ jobs: POSTGRES_INITDB_ARGS: "--auth-host=scram-sha-256" postgres_replica: - image: $CR_NAME/postgres_replica:${{ env.REPLICA_SHA }} + image: ${{ needs.export_variables.outputs.replica_image }} ports: - 5433:5432 env: