Skip to content
This repository was archived by the owner on Aug 20, 2025. It is now read-only.

Merge pull request #69 from statisticsnorway/public_images_publish #53

Merge pull request #69 from statisticsnorway/public_images_publish

Merge pull request #69 from statisticsnorway/public_images_publish #53

name: Build
on:
push:
branches:
- main
workflow_dispatch:
env:
REGISTRY: europe-north1-docker.pkg.dev/${{ secrets.GAR_PROJECT_ID }}/microdata-docker
IMAGE: metadata-service
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.13"
- name: Install dependencies
run: |
curl -sSL https://install.python-poetry.org | python -
poetry install
- name: Run tests
run: poetry run pytest --cov=metadata_service
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'
})
revoke:
runs-on: ubuntu-latest
needs: build
permissions:
actions: write
steps:
- uses: actions/checkout@v4
- name: Mark older approvals as unnecessary
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Find previous workflow runs for the same workflow
runs=$(gh run list --workflow=87753572 --json databaseId,status --jq '.[] | select(.status == "waiting") | .databaseId')
for run_id in $runs; do
echo "Marking workflow run $run_id as outdated"
gh run cancel $run_id
done
deploy:
name: Deploy to production
runs-on: ubuntu-latest
needs: [build, revoke]
environment: prod
permissions:
contents: read
id-token: write
steps:
- name: Call workflow
uses: actions/github-script@v7
with:
github-token: ${{ secrets.DEPLOY_PAT }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: 'statisticsnorway',
repo: '${{ secrets.DEPLOY_REPO }}',
workflow_id: '${{ secrets.DEPLOY_WORKFLOW }}.yaml',
ref: 'master',
inputs: {
environment: "PROD",
service: "metadata-service"
}
})