-
Notifications
You must be signed in to change notification settings - Fork 4
178 lines (158 loc) · 6.55 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
name: Build CI
on:
push:
branches:
- main
- 'feature/**'
paths:
- 'src/**'
- 'db/**'
- 'k8s/**'
- '.github/workflows/build.yml'
- 'scripts/**'
- 'gitversion.yml'
workflow_run:
workflows: [Trigger No Op Build]
types:
- completed
env:
OCTOPUS_PROJECT_NAME: ${{ vars.OCTOPUS_PROJECT_NAME }}
OCTOPUS_FEATURE_BRANCH_CHANNEL: ${{ vars.OCTOPUS_FEATURE_BRANCH_CHANNEL }}
OCTOPUS_RELEASE_CHANNEL: ${{ vars.OCTOPUS_RELEASE_CHANNEL }}
OCTOPUS_SPACE: ${{ vars.OCTOPUS_SPACE }}
OCTOPUS_API_KEY: ${{ secrets.OCTOPUSSERVERAPIKEY }}
OCTOPUS_URL: ${{ vars.OCTOPUS_SERVER_URL }}
DOCKER_REPO: ${{ vars.DOCKER_HUB_REPO }}
jobs:
prep:
runs-on: ubuntu-latest
outputs:
website: ${{ steps.changes.outputs.website }}
database: ${{ steps.changes.outputs.database }}
pre_release: ${{ steps.determine_version.outputs.preReleaseNumber }}
sem_ver: ${{ steps.determine_version.outputs.FullSemVer }}
steps:
- uses: actions/checkout@v1
with:
fetch-depth: '0'
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v1
with:
versionSpec: 5.x
- id: determine_version
name: Determine Version
uses: gittools/actions/gitversion/execute@v1
with:
additionalArguments: /config gitversion.yml
- uses: dorny/paths-filter@v3
id: changes
with:
base: ${{ github.event.before }}
filters: |
database:
- 'src/Trident.Database.DbUp/**'
build-database:
needs: [prep]
if: ${{ needs.prep.outputs.database == 'true' || needs.prep.outputs.pre_release == '1' }}
strategy:
matrix:
dotnet-version: ['8.0.x']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Install dependencies
run: dotnet restore src/Trident.Database.DbUp/Trident.Database.DbUp.csproj
- name: Create artifacts folder
run: |
mkdir "$GITHUB_WORKSPACE/artifacts"
mkdir "$GITHUB_WORKSPACE/artifacts/Trident.Database.DbUp"
- name: Publish Database
run: dotnet publish src/Trident.Database.DbUp/Trident.Database.DbUp.csproj --configuration Release --self-contained --output "$GITHUB_WORKSPACE/artifacts/Trident.Database.DbUp" -a "x64"
- name: package database
id: "database_package"
uses: OctopusDeploy/create-zip-package-action@v3
with:
package_id: Trident.Database.DbUp
version: "${{ needs.prep.outputs.sem_Ver }}"
base_path: "artifacts/Trident.Database.DbUp"
files: "**/*"
output_folder: packaged
- name: push packages to Octopus
uses: OctopusDeploy/push-package-action@v3
with:
packages: |
packaged/**/*.zip
- name: push database build information to Octopus
uses: OctopusDeploy/push-build-information-action@v3
with:
packages: |
Trident.Database.DbUp
version: "${{ needs.prep.outputs.sem_Ver }}"
build-website:
needs: [prep]
strategy:
matrix:
dotnet-version: ['8.0.x']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Install dependencies
run: dotnet restore src/Trident.sln
- name: Run unit tests
run: dotnet test src/Trident.Web.Test/Trident.Web.Test.csproj --configuration Release --collect "Code coverage" --logger trx --results-directory /tmp/testresults
- name: Upload unit tests results
uses: actions/upload-artifact@v4
with:
name: test-results
path: /tmp/testresults
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PAT }}
- name: install buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v1
- name: build and push website container
working-directory: src
run: |
docker buildx build --push --platform linux/amd64,linux/arm64 -f "./Trident.Web/Dockerfile" --build-arg APP_VERSION=${{ needs.prep.outputs.sem_Ver }} --tag ${{ env.DOCKER_REPO }}:${{ needs.prep.outputs.sem_Ver }} --tag ${{ env.DOCKER_REPO }}:latest .
- name: push code build information to Octopus
uses: OctopusDeploy/push-build-information-action@v3
with:
packages: |
${{ env.DOCKER_REPO }}
version: "${{ needs.prep.outputs.sem_Ver }}"
deploy:
needs: [prep, build-website, build-database]
if: ${{ always() && !failure() && !cancelled() }}
runs-on: ubuntu-latest
steps:
- name: create release in Octopus
uses: OctopusDeploy/create-release-action@v3
with:
project: ${{ env.OCTOPUS_PROJECT_NAME }}
channel: ${{ github.ref == 'refs/heads/main' && env.OCTOPUS_RELEASE_CHANNEL || env.OCTOPUS_FEATURE_BRANCH_CHANNEL }}
release_number: "${{ needs.prep.outputs.sem_Ver }}"
git_ref: ${{ (github.ref_type == 'tag' && github.event.repository.default_branch ) || (github.head_ref || github.ref) }}
git_commit: ${{ github.event.after || github.event.pull_request.head.sha }}
- name: Create Release for GitHub
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: "${{ needs.prep.outputs.sem_Ver }}"
release_name: Release ${{ needs.prep.outputs.sem_Ver }}
body: |
Commit Message: ${{ github.event.head_commit.message }}
draft: false
prerelease: ${{ github.ref == 'refs/heads/main' && 'false' || 'true' }}