Skip to content

Commit

Permalink
chore: Implemented running integration tests in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Fgruntjes committed Jan 23, 2023
1 parent 95ef7b4 commit ab5fd85
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 56 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,24 @@ on:
labels:
required: false
type: string
secrets:
GOOGLE_WORKLOAD_IDENTITY_PROVIDER:
required: true
GOOGLE_SERVICE_ACCOUNT:
required: true
GOOGLE_PROJECT_ID:
required: true

jobs:
project_matrix:
uses: ./.github/workflows/project_matrix.yaml

build:
runs-on: ubuntu-latest
needs: [project_matrix]
strategy:
matrix:
project: ${{fromJson(needs.project_matrix.outputs.functions)}}
project: ${{ fromJson(needs.project_matrix.outputs.functions) }}
permissions:
contents: 'read'
id-token: 'write'
Expand All @@ -43,4 +51,4 @@ jobs:
tags: gcr.io/${{ secrets.GOOGLE_PROJECT_ID }}/${{ matrix.project }}:${{inputs.tag}}
cache-from: type=gha
cache-to: type=gha,mode=max
labels: ${{inputs.labels}}
labels: ${{ inputs.labels }}
26 changes: 26 additions & 0 deletions .github/workflows/cleanup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Cleanup
on:
workflow_call:
secrets:
GOOGLE_WORKLOAD_IDENTITY_PROVIDER:
required: true
GOOGLE_SERVICE_ACCOUNT:
required: true
GOOGLE_PROJECT_ID:
required: true

jobs:
clean:
runs-on: ubuntu-latest
environment:
name: ${{inputs.environment}}
url: https://github.com
permissions:
contents: 'read'
id-token: 'write'
steps:
- uses: google-github-actions/auth@v0
with:
workload_identity_provider: ${{ secrets.GOOGLE_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GOOGLE_SERVICE_ACCOUNT }}
- run: echo "Do some cleanup"
45 changes: 19 additions & 26 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,28 @@ on:
type: string
region:
required: false
default: 'europe-central2'
type: string
default: 'europe-west1'
secrets:
GOOGLE_WORKLOAD_IDENTITY_PROVIDER:
required: true
GOOGLE_SERVICE_ACCOUNT:
required: true
GOOGLE_PROJECT_ID:
required: true
SENTRY__DSN:
required: true

jobs:
project_matrix:
uses: ./.github/workflows/project_matrix.yaml

deploy:
runs-on: ubuntu-latest
needs: [project_matrix]
environment:
name: ${{inputs.environment}}
url: https://github.com
needs:
- build
permissions:
contents: 'read'
id-token: 'write'
Expand All @@ -35,33 +44,17 @@ jobs:
with:
workload_identity_provider: ${{ secrets.GOOGLE_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GOOGLE_SERVICE_ACCOUNT }}
# Deploy cloud functions
- run: environment_input="${{ inputs.environment }}"; echo "dotnet_env=$(echo "${environment_input%%_*}" | sed -e 's/^./\U&/)" >> $GITHUB_ENV
- uses: mshick/fast-envsubst@v1
env:
SERVICE: ${{ matrix.project }}
DEPLOY_ENV: ${{inputs.environment}}
DOTNET_ENVIRONMENT: ${{ env.dotnet_env }}
IMAGE: gcr.io/${{ secrets.GOOGLE_PROJECT_ID }}/${{ matrix.project }}:${{inputs.tag}}
Database__ConnectionString: ${{ secrets.DATABASE__CONNECTIONSTRING }}
Sentry__Dsn: ${{ secrets.SENTRY__DSN }}
Database__DatabaseName: ${{inputs.environment}}
with:
in-file: ${{ matrix.project }}/service.yaml
out-file: ${{ matrix.project }}/service.deploy.yaml
- run: cat ${{ matrix.project }}/service.deploy.yaml
- uses: google-github-actions/deploy-cloudrun@v0
id: cloudrun
with:
metadata: ${{ matrix.project }}/service.deploy.yaml
region: ${{ inputs.region }}
# Deploy infra (terraform)
# Deploy (terraform)
- uses: hashicorp/setup-terraform@v2
- run: environment_input="${{ inputs.environment }}"; echo "dotnet_env=$(echo "${environment_input%%_*}" | sed -e 's/^./\U&/)" >> $GITHUB_ENV
- run: |
test -d ${{ matrix.project }}/terraform || exit 0
cd ${{ matrix.project }}/terraform
terraform init
terraform plan -out plan.tf \
-var "environment=${{ inputs.environment }}" \
-var "cloudrun_url=${{ steps.cloudrun.outputs.url }}"
-var "image=gcr.io/${{ secrets.GOOGLE_PROJECT_ID }}/${{ matrix.project }}:${{inputs.tag}}"
-var "environment=${{ inputs.environment }}"
-var "dotnet_env=${{ env.dotnet_env }}"
-var "project=${{ matrix.project }}"
-var "sentry_dsn={{ secrets.SENTRY__DSN }}"
terraform apply -auto-approve plan.tf
32 changes: 32 additions & 0 deletions .github/workflows/test_integration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Integration tests
on:
pull_request:

jobs:
build:
uses: ./.github/workflows/build.yaml
secrets: inherit
with:
tag: test
labels: integration_test=true

deploy:
needs: [build]
uses: ./.github/workflows/deploy.yaml
secrets: inherit
with:
environment: Staging_test
tag: test

test:
runs-on: ubuntu-latest
needs: [deploy]
steps:
- run: "deploy build / clean tests"

clean:
needs: [ test ]
uses: ./.github/workflows/cleanup.yaml
secrets: inherit
if: ${{ always() }}

2 changes: 1 addition & 1 deletion .github/workflows/test_quality.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test Quality
name: Code quality
on:
pull_request:

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_unit.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test
name: Unit test
on:
pull_request:

Expand All @@ -14,7 +14,7 @@ jobs:
needs: [project_matrix]
strategy:
matrix:
project: ${{fromJson(needs.project_matrix.outputs.typescript)}}
project: ${{ fromJson(needs.project_matrix.outputs.typescript) }}
steps:
- uses: actions/checkout@v3
- run: cd ${{ matrix.project }} && ./ensure_tests.sh
Expand Down
25 changes: 0 additions & 25 deletions App.Function.Banktransaction.Import/service.yaml

This file was deleted.

0 comments on commit ab5fd85

Please sign in to comment.