From ec1808887bf4597ee16fa69e96166eaf71cf54b0 Mon Sep 17 00:00:00 2001 From: Mark Calvert Date: Fri, 2 Feb 2024 18:07:28 +1300 Subject: [PATCH] Added rules-as-code workflow test job Migrated deploy job into rules-as-code workflow and only deploy if the test job is successful --- .github/workflows/deploy.yml | 39 +------------------- .github/workflows/rules-as-code.yml | 55 ++++++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 43 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0eea21f..0bb7a0f 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,43 +3,6 @@ name: Deploy images on: - push -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }}/rules-as-code - jobs: - delploy: + deploy: runs-on: ubuntu-latest - permissions: - contents: read - packages: write - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Log in to the Container registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Extract metadata (tags, labels) for Docker image - id: meta_openfisca - uses: docker/metadata-action@v5 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - - name: Build and push Docker image - uses: docker/build-push-action@v5 - with: - context: ./images/rules-as-code - platforms: linux/amd64,linux/arm64 - push: true - tags: ${{ steps.meta_openfisca.outputs.tags }} diff --git a/.github/workflows/rules-as-code.yml b/.github/workflows/rules-as-code.yml index b9cd4cc..0898c28 100644 --- a/.github/workflows/rules-as-code.yml +++ b/.github/workflows/rules-as-code.yml @@ -1,15 +1,60 @@ name: Rules As Code build on: - - workflow_call + - push + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }}/rules-as-code + jobs: test: - name: Test the docker images runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 + + - name: Build the Docker image + run: docker build -f images/rules-as-code/Dockerfile -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} images/rules-as-code + + - name: Run OpenFisca tests + run: | + docker run --rm -d --name rules-as-code ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + docker exec rules-as-code sh -c 'openfisca test --country-package openfisca_rules openfisca-rules/openfisca_rules/tests' + docker stop rules-as-code deploy: - name: Build the docker images + needs: test runs-on: ubuntu-latest + permissions: + contents: read + packages: write steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker image + id: meta_openfisca + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: ./images/rules-as-code + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta_openfisca.outputs.tags }}