Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: refactor build test and publish #328

Merged
merged 16 commits into from
Jan 10, 2024
25 changes: 25 additions & 0 deletions .github/workflows/BuildAndTest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: BuildAndTest

on:
workflow_dispatch:
workflow_call:

jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.x"

- name: Restore
run: dotnet restore

- name: Build
run: dotnet build --no-restore --configuration Release

- name: Test
run: dotnet test --no-build --configuration Release
6 changes: 1 addition & 5 deletions .github/workflows/Deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ jobs:
id-token: write
contents: read
steps:
- name: Download bicep artifacts
uses: actions/download-artifact@v4
with:
name: azure-artifacts
path: .azure
- uses: actions/checkout@v4

- name: OIDC Login to Azure Public Cloud with AzPowershell
uses: azure/login@v1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,49 +1,21 @@
name: BuildTestPublish
name: Publish

on:
workflow_dispatch:
workflow_call:
secrets:
GCR_PASSWORD:
description: "Password for Github Container Registry"
oskogstad marked this conversation as resolved.
Show resolved Hide resolved
required: true
inputs:
publishArtifacts:
required: false
type: boolean
default: false

dockerImageBaseName:
description: "Base image name for docker images"
required: true
type: string
jobs:
build-test-publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.x"

- name: Restore
run: dotnet restore

- name: Build
run: dotnet build --no-restore --configuration Release

- name: Test
run: dotnet test --no-build --configuration Release

- name: Upload azure bicep artifacts for IaC deployment
if: ${{inputs.publishArtifacts}}
uses: actions/upload-artifact@v4
with:
name: azure-artifacts
path: .azure

publish-docker-images:
env:
DOCKER_IMAGE_BASE: ghcr.io/digdir/dialogporten-
needs: build-test-publish
if: ${{inputs.publishArtifacts}}
DOCKER_IMAGE_BASE_NAME: ${{ inputs.dockerImageBaseName }}
runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
Expand Down Expand Up @@ -73,13 +45,13 @@ jobs:
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
password: ${{ secrets.GCR_PASSWORD }}

- name: Extract metadata (tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_IMAGE_BASE }}${{ matrix.imageName }}
images: ${{ env.DOCKER_IMAGE_BASE_NAME }}${{ matrix.imageName }}
- uses: docker/setup-buildx-action@v3
- name: Build and push docker image
uses: docker/build-push-action@v5
Expand All @@ -89,7 +61,7 @@ jobs:
push: true
tags: |
${{ steps.meta.outputs.tags }},
${{ env.DOCKER_IMAGE_BASE }}${{ matrix.imageName }}:${{ github.sha }}
${{ env.DOCKER_IMAGE_BASE_NAME }}${{ matrix.imageName }}:${{ github.sha }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
6 changes: 2 additions & 4 deletions .github/workflows/PullRequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ on:
- "tests/k6/**"

jobs:
publish:
uses: ./.github/workflows/BuildTestPublish.yml
with:
publishArtifacts: false
build:
uses: ./.github/workflows/BuildAndTest.yml
28 changes: 17 additions & 11 deletions .github/workflows/Workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,27 @@ on:
- "tests/k6/**"

jobs:
build-and-test:
uses: ./.github/workflows/BuildAndTest.yml

publish:
uses: ./.github/workflows/BuildTestPublish.yml
needs: [build-and-test]
uses: ./.github/workflows/Publish.yml
secrets:
GCR_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
with:
publishArtifacts: true
dockerImageBaseName: ghcr.io/digdir/dialogporten-

deployTest:
deploy-test:
needs: [publish]
uses: ./.github/workflows/Deploy.yml
secrets: inherit
secrets:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
AZURE_SOURCE_KEY_VAULT_NAME: ${{ secrets.AZURE_SOURCE_KEY_VAULT_NAME }}
AZURE_SOURCE_KEY_VAULT_SUBSCRIPTION_ID: ${{ secrets.AZURE_SOURCE_KEY_VAULT_SUBSCRIPTION_ID }}
AZURE_SOURCE_KEY_VAULT_RESOURCE_GROUP: ${{ secrets.AZURE_SOURCE_KEY_VAULT_RESOURCE_GROUP }}
APIM_DIGDIR_EMAIL: ${{ secrets.APIM_DIGDIR_EMAIL }}
with:
environment: test
#
# deployTest:
# needs: [ publish ]
# uses: ./.github/workflows/Deploy.yml
# secrets: inherit
# with:
# environment: test