|
| 1 | +name: Build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - rust |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +env: |
| 10 | + REGISTRY: europe-north1-docker.pkg.dev/${{ secrets.GAR_PROJECT_ID }}/microdata-docker |
| 11 | + IMAGE: metadata-service |
| 12 | + |
| 13 | +jobs: |
| 14 | + test: |
| 15 | + name: cargo test |
| 16 | + runs-on: ubuntu-latest |
| 17 | + if: github.event_name == 'pull_request' |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + ref: rust |
| 22 | + - name: Set up Rust (Minimal) |
| 23 | + run: rustup toolchain install stable --profile minimal |
| 24 | + - run: cargo test --all-features |
| 25 | + |
| 26 | + build: |
| 27 | + runs-on: ubuntu-latest |
| 28 | + needs: test |
| 29 | + permissions: |
| 30 | + contents: read |
| 31 | + id-token: write |
| 32 | + |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v4 |
| 35 | + with: |
| 36 | + ref: rust |
| 37 | + |
| 38 | + - name: Authenticate to Google Cloud |
| 39 | + id: auth |
| 40 | + uses: google-github-actions/auth@v1.1.1 |
| 41 | + with: |
| 42 | + workload_identity_provider: "projects/${{ secrets.GAR_PROJECT_NUMBER }}/locations/global/workloadIdentityPools/gh-actions/providers/gh-actions" |
| 43 | + service_account: "gh-actions-microdata@${{ secrets.GAR_PROJECT_ID }}.iam.gserviceaccount.com" |
| 44 | + token_format: access_token |
| 45 | + |
| 46 | + - name: Set up Docker Buildx |
| 47 | + id: buildx |
| 48 | + uses: docker/setup-buildx-action@v2 |
| 49 | + |
| 50 | + - name: Login to Artifact Registry |
| 51 | + uses: docker/login-action@v3 |
| 52 | + with: |
| 53 | + registry: ${{ env.REGISTRY }} |
| 54 | + username: "oauth2accesstoken" |
| 55 | + password: "${{ steps.auth.outputs.access_token }}" |
| 56 | + |
| 57 | + - name: Extract build metadata for Docker |
| 58 | + id: build_metadata |
| 59 | + uses: docker/metadata-action@v5 |
| 60 | + with: |
| 61 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE }} |
| 62 | + tags: | |
| 63 | + type=raw,value=rust-{{sha}} |
| 64 | + type=raw,value=rust-latest |
| 65 | +
|
| 66 | + - name: Build and push docker image to Artifact Registry |
| 67 | + uses: docker/build-push-action@v4 |
| 68 | + with: |
| 69 | + context: . |
| 70 | + provenance: false |
| 71 | + file: Dockerfile |
| 72 | + push: true |
| 73 | + tags: ${{ steps.build_metadata.outputs.tags }} |
| 74 | + labels: ${{ steps.build_metadata.outputs.labels }} |
| 75 | + build-args: | |
| 76 | + COMMIT_ID=${{ github.sha }} |
| 77 | +
|
| 78 | + integration-test: |
| 79 | + name: Run Integration test |
| 80 | + runs-on: ubuntu-latest |
| 81 | + needs: build |
| 82 | + permissions: |
| 83 | + contents: read |
| 84 | + id-token: write |
| 85 | + |
| 86 | + steps: |
| 87 | + - name: Call workflow |
| 88 | + uses: actions/github-script@v7 |
| 89 | + with: |
| 90 | + github-token: ${{ secrets.INTEGRATION_TEST_PAT }} |
| 91 | + script: | |
| 92 | + await github.rest.actions.createWorkflowDispatch({ |
| 93 | + owner: 'statisticsnorway', |
| 94 | + repo: '${{ secrets.INTEGRATION_TEST_REPO }}', |
| 95 | + workflow_id: '${{ secrets.INTEGRATION_TEST_WORKFLOW }}.yaml', |
| 96 | + ref: 'main' |
| 97 | + }) |
0 commit comments