-
Notifications
You must be signed in to change notification settings - Fork 0
128 lines (110 loc) · 3.65 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
name: Build and Deploy
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
env:
CONTAINER_REGISTRY: ghcr.io
jobs:
build:
name: Build & test
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
outputs:
image_tag: ${{ steps.image.outputs.tag }}
services:
postgres:
image: postgres
env:
POSTGRES_DB: trn_generator
POSTGRES_PASSWORD: trn_generator
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v3
- uses: actions/setup-dotnet@v3
with:
dotnet-version: "7.0.x"
- name: Build
run: dotnet build --configuration Release
working-directory: TrnGeneratorApi
- name: Tests
uses: ./.github/workflows/actions/test
with:
test_project_path: TrnGeneratorApi/tests/TrnGeneratorApi.IntegrationTests
report_name: "Test results"
dotnet_test_args: '-e ConnectionStrings__DefaultConnection="Host=localhost;Username=postgres;Password=trn_generator;Database=trn_generator" -e ApiKeys__0="12345"'
- name: Publish
run: dotnet publish --configuration Release --no-build src/TrnGeneratorApi/TrnGeneratorApi.csproj
working-directory: TrnGeneratorApi
- name: Docker image tag
id: image
run: |
echo "tag=$CONTAINER_REGISTRY/$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]'):$GITHUB_SHA" >> $GITHUB_OUTPUT
- name: Login to GitHub Cotainer Registry
uses: docker/login-action@v1
with:
registry: ${{ env.CONTAINER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker build & push
uses: docker/build-push-action@v2
with:
context: TrnGeneratorApi/src/TrnGeneratorApi
push: true
tags: ${{ steps.image.outputs.tag }}
build-args: |
GIT_SHA=${{ github.sha }}
deploy_to_dev:
name: Deploy to dev environment
runs-on: ubuntu-latest
if: (github.event_name == 'pull_request' && github.event.pull_request.draft == false) || github.event_name == 'workflow_dispatch'
concurrency: deploy_dev
needs: [build]
environment:
name: dev
url: ${{ steps.deploy.outputs.environment_url }}
outputs:
environment_url: ${{ steps.deploy.outputs.environment_url }}
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/deploy-environment
id: deploy
with:
azure_credentials: ${{ secrets.AZURE_CREDENTIALS }}
environment_name: dev
image_tag: ${{ needs.build.outputs.image_tag }}
deploy:
name: Deploy to ${{ matrix.environment }} environment
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
concurrency: deploy_${{ matrix.environment }}
needs: [build]
strategy:
max-parallel: 1
matrix:
environment: [test, preprod, production]
environment:
name: ${{ matrix.environment }}
url: ${{ steps.deploy.outputs.environment_url }}
outputs:
environment_url: ${{ steps.deploy.outputs.environment_url }}
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/deploy-environment
id: deploy
with:
azure_credentials: ${{ secrets.AZURE_CREDENTIALS }}
environment_name: ${{ matrix.environment }}
image_tag: ${{ needs.build.outputs.image_tag }}