-
Notifications
You must be signed in to change notification settings - Fork 0
200 lines (183 loc) · 5.94 KB
/
release.yaml
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
name: Release
on:
push:
branches:
- release
jobs:
setup:
name: Setup
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
next-version: ${{ steps.get-release-version.outputs.version }}
next-version-name: ${{ steps.get-release-version.outputs.version-name }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: wemogy/get-release-version-action@v4.3.2
id: get-release-version
with:
prefix: v
create-tag: 'true'
git-username: bennetrr
git-email: bennet@bennetr.me
mode: semantic
build-frontend:
name: Build frontend containers
needs: [ setup ]
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
strategy:
matrix:
platform:
- { docker: linux/amd64 }
- { docker: linux/arm64 }
- { docker: linux/arm64/v8 }
steps:
- uses: actions/checkout@v4
- name: Build container
uses: ./.github/actions/containers/build
with:
registry-server: ghcr.io
registry-user: ${{ github.actor }}
registry-password: ${{ secrets.GITHUB_TOKEN }}
name: bennetrr/brickinv-frontend
version: ${{ needs.setup.outputs.next-version-name }}
context: src/frontend
push: 'true'
docker-platform: ${{ matrix.platform.docker }}
build-backend:
name: Build backend containers
needs: [ setup ]
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
strategy:
matrix:
platform:
- { docker: linux/amd64, dotnet: amd64, dotnet-ef: linux-x64 }
- { docker: linux/arm64, dotnet: arm64, dotnet-ef: linux-arm64 }
- { docker: linux/arm64/v8, dotnet: arm64, dotnet-ef: linux-arm64 }
steps:
- uses: actions/checkout@v4
- name: Build container
uses: ./.github/actions/containers/build
with:
registry-server: ghcr.io
registry-user: ${{ github.actor }}
registry-password: ${{ secrets.GITHUB_TOKEN }}
name: bennetrr/brickinv-backend
version: ${{ needs.setup.outputs.next-version-name }}
context: src/backend/Bennetr.BrickInv.Api/
push: 'true'
docker-platform: ${{ matrix.platform.docker }}
dotnet-platform: ${{ matrix.platform.dotnet }}
dotnet-ef-platform: ${{ matrix.platform.dotnet-ef }}
merge-frontend:
name: Merge frontend containers
needs: [ setup, build-frontend ]
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v4
- name: Merge and push containers
uses: ./.github/actions/containers/merge
with:
registry-server: ghcr.io
registry-user: ${{ github.actor }}
registry-password: ${{ secrets.GITHUB_TOKEN }}
name: bennetrr/brickinv-frontend
version: ${{ needs.setup.outputs.next-version-name }}
merge-backend:
name: Merge backend containers
needs: [ setup, build-backend ]
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v4
- name: Merge and push container
uses: ./.github/actions/containers/merge
with:
registry-server: ghcr.io
registry-user: ${{ github.actor }}
registry-password: ${{ secrets.GITHUB_TOKEN }}
name: bennetrr/brickinv-backend
version: ${{ needs.setup.outputs.next-version-name }}
docker-compose:
name: Update versions in docker-compose.yml
needs:
- setup
- merge-frontend
- merge-backend
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Update versions in docker-compose.yml
run: |
sed -i -E 's/ghcr\.io\/bennetrr\/brickinv-(frontend|backend):v[0-9]+\.[0-9]+\.[0-9]+/ghcr.io\/bennetrr\/brickinv-\1:${{ needs.setup.outputs.next-version-name }}/g' docker-compose.yml
- name: Save docker-compose.yml
id: save-docker-compose
run: |
{
echo 'docker-compose<<EOF'
cat docker-compose.yml
echo EOF
} >> "$GITHUB_OUTPUT"
- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
add: docker-compose.yml
push: true
github-release:
name: Create GitHub release
needs:
- setup
- merge-frontend
- merge-backend
- docker-compose
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Create GitHub release
uses: ncipollo/release-action@v1
with:
name: Version ${{ needs.setup.outputs.next-version }}
tag: ${{ needs.setup.outputs.next-version-name }}
prerelease: ${{ github.event.inputs.pre-release || false }}
generateReleaseNotes: true
commit: ${{ github.head_ref || github.ref_name }}
deploy:
# Thanks to https://www.programonaut.com/how-to-deploy-a-git-repository-to-a-server-using-github-actions/
name: Deploy to production
needs:
- setup
- merge-frontend
- merge-backend
- docker-compose
runs-on: ubuntu-latest
steps:
- name: Install ssh keys
run: |
install -m 600 -D /dev/null ~/.ssh/id_rsa
echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.DEPLOY_SSH_HOST }} > ~/.ssh/known_hosts
- name: Pull
run: |
ssh ${{ secrets.DEPLOY_SSH_USER }}@${{ secrets.DEPLOY_SSH_HOST }} "
cd ${{ secrets.DEPLOY_WORKDIR }}
sed -i -E 's/ghcr\.io\/bennetrr\/brickinv-(frontend|backend):v[0-9]+\.[0-9]+\.[0-9]+/ghcr.io\/bennetrr\/brickinv-\1:${{ needs.setup.outputs.next-version-name }}/g' docker-compose.yml
docker compose up -d
exit
"