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 02d55cb
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 66 deletions.
28 changes: 20 additions & 8 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,54 @@ on:
tag:
required: true
type: string
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'
steps:
- uses: actions/checkout@v3
- uses: google-github-actions/auth@v0
- uses: google-github-actions/auth@v1
id: google_auth
with:
token_format: 'access_token'
workload_identity_provider: ${{ secrets.GOOGLE_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GOOGLE_SERVICE_ACCOUNT }}
access_token_lifetime: 300s
- uses: docker/login-action@v2
with:
registry: gcr.io
registry: europe-west1-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.google_auth.outputs.access_token }}
- uses: docker/setup-buildx-action@v2
- uses: docker/metadata-action@v4
id: meta
with:
images: europe-west1-docker.pkg.dev/${{ secrets.GOOGLE_PROJECT_ID }}/docker/${{ matrix.project }}
tags: ${{inputs.tag}}
- uses: docker/build-push-action@v3
with:
context: .
file: '${{ matrix.project }}/Dockerfile'
push: true
tags: gcr.io/${{ secrets.GOOGLE_PROJECT_ID }}/${{ matrix.project }}:${{inputs.tag}}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
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@v1
with:
workload_identity_provider: ${{ secrets.GOOGLE_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GOOGLE_SERVICE_ACCOUNT }}
- run: echo "Do some cleanup"
84 changes: 55 additions & 29 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Deploy

on:
workflow_call:
inputs:
Expand All @@ -10,58 +11,83 @@ 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
CLOUDFLARE_API_TOKEN:
required: true
CLOUDFLARE_ACCOUNT_ID:
required: true

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

deploy:
deploy_functions:
runs-on: ubuntu-latest
needs: [project_matrix]
environment:
name: ${{inputs.environment}}
url: https://github.com
needs:
- build
permissions:
contents: 'read'
id-token: 'write'
contents: read
id-token: write
strategy:
matrix:
project: ${{fromJson(needs.project_matrix.outputs.functions)}}
steps:
- uses: actions/checkout@v3
- uses: google-github-actions/auth@v0
- uses: google-github-actions/auth@v1
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}}
# Deploy (terraform)
- uses: docker/metadata-action@v4
id: meta
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)
images: europe-west1-docker.pkg.dev/${{ secrets.GOOGLE_PROJECT_ID }}/docker/${{ matrix.project }}
tags: ${{inputs.tag}}
- 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=${{ steps.meta.outputs.tags }}"
-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
deploy_frontend:
runs-on: ubuntu-latest
environment:
name: ${{inputs.environment}}
url: https://github.com
permissions:
contents: read
deployments: write
steps:
- uses: actions/checkout@v3
- run: |
cd frontend-web
npm ci
./generate_api_types.sh
npm run build
- uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: serverless-personal-finance
directory: "frontend-web/build"
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
31 changes: 31 additions & 0 deletions .github/workflows/test_integration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Integration tests
on:
pull_request:

jobs:
build:
uses: ./.github/workflows/build.yaml
secrets: inherit
with:
tag: test

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() }}

4 changes: 2 additions & 2 deletions .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 Expand Up @@ -34,7 +34,7 @@ jobs:
terraform validate
- uses: reviewdog/action-tflint@master
with:
github_token: ${{ secrets.github_token }}
github_token: ${{ secrets.GITHUB_TOKEN }}
working_directory: ${{ matrix.project }}/terraform
reporter: github-pr-review

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.

2 changes: 2 additions & 0 deletions frontend-web/src/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ describe("bootstrap.index", () => {
expect(true).toBeTruthy();
});
});

export {};

0 comments on commit 02d55cb

Please sign in to comment.