Skip to content
This repository was archived by the owner on Aug 20, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .github/workflows/build_and_test_rust.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Build

on:
push:
branches:
- rust
workflow_dispatch:

env:
REGISTRY: europe-north1-docker.pkg.dev/${{ secrets.GAR_PROJECT_ID }}/microdata-docker
IMAGE: metadata-service

jobs:
test:
name: cargo test
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
with:
ref: rust
- name: Set up Rust (Minimal)
run: rustup toolchain install stable --profile minimal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

- run: cargo test --all-features

build:
runs-on: ubuntu-latest
needs: test
permissions:
contents: read
id-token: write

steps:
- uses: actions/checkout@v4
with:
ref: rust

- 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=rust-{{sha}}
type=raw,value=rust-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'
})