Merge pull request #143 from statisticsnorway/update-backstage-tags #40
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: Build | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| env: | |
| REGISTRY: europe-north1-docker.pkg.dev/${{ secrets.GAR_PROJECT_ID }}/microdata-docker | |
| IMAGE: job-executor | |
| jobs: | |
| test: | |
| name: Test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install dependencies | |
| run: | | |
| curl -sSL https://install.python-poetry.org | python - | |
| poetry install | |
| - name: Run tests | |
| run: poetry run pytest --cov=job_executor | |
| build: | |
| runs-on: ubuntu-latest | |
| needs: test | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Authenticate to Google Cloud | |
| id: auth | |
| uses: google-github-actions/auth@v1.1.1 | |
| with: | |
| workload_identity_provider: "projects/${{ secrets.GAR_PROJECT_NUMBER }}/locations/global/workloadIdentityPools/gh-actions/providers/gh-actions" | |
| service_account: "gh-actions-microdata@${{ secrets.GAR_PROJECT_ID }}.iam.gserviceaccount.com" | |
| token_format: access_token | |
| - name: Set up Docker Buildx | |
| id: buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Login to Artifact Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: "oauth2accesstoken" | |
| password: "${{ steps.auth.outputs.access_token }}" | |
| - name: Extract build metadata for Docker | |
| id: build_metadata | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE }} | |
| tags: | | |
| type=raw,value=main-{{sha}} | |
| type=raw,value=latest | |
| - name: Build and push docker image to Artifact Registry | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: . | |
| provenance: false | |
| file: Dockerfile | |
| push: true | |
| tags: ${{ steps.build_metadata.outputs.tags }} | |
| labels: ${{ steps.build_metadata.outputs.labels }} | |
| build-args: | | |
| COMMIT_ID=${{ github.sha }} | |
| integration-test: | |
| name: Run Integration test | |
| runs-on: ubuntu-latest | |
| needs: build | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - name: Call workflow | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.INTEGRATION_TEST_PAT }} | |
| script: | | |
| await github.rest.actions.createWorkflowDispatch({ | |
| owner: 'statisticsnorway', | |
| repo: '${{ secrets.INTEGRATION_TEST_REPO }}', | |
| workflow_id: '${{ secrets.INTEGRATION_TEST_WORKFLOW }}.yaml', | |
| ref: 'main' | |
| }) |