-
Notifications
You must be signed in to change notification settings - Fork 1
230 lines (207 loc) · 7.38 KB
/
release.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
name: Release
on:
workflow_dispatch:
inputs:
version_increment:
description: 'La version a incrémenter (major, minor, patch)'
required: true
default: 'patch'
type: choice
options:
- 'major'
- 'minor'
- 'patch'
# build_docker_image:
# description: "Construire l'image docker ?"
# required: true
# default: true
# type: boolean
latest:
description: "Tagger l'image docker avec le tag 'latest' ?"
required: true
default: true
type: boolean
jobs:
release:
runs-on: ubuntu-latest
outputs:
NEW_VERSION: ${{ steps.output_version.outputs.NEW_VERSION }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
repository: ${{ github.repository }}
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Git
shell: bash
run: |
git config user.email "github@action.com"
git config user.name "Github Action"
echo ${{ secrets.GITHUB_TOKEN }} > token.txt
git config credential.helper "store --file=token.txt"
- name: Update version
shell: bash
run: |
echo NEW_VERSION=$(yarn version --${{ inputs.version_increment }} --json | jq -r '.data | select(contains("New version")) | split(":")[1] | gsub(" ";"")') >> $GITHUB_ENV
env:
REF: ${{ github.ref }}
- name: Push to protected branch
uses: CasperWA/push-protected@v2
with:
token: ${{ secrets.ACTION_TOKEN }}
branch: main
unprotect_reviews: true
tags: true
- name: Publish release
uses: ncipollo/release-action@v1
with:
name: Release ${{ env.NEW_VERSION }}
commit: ${{ env.REF }}
draft: false
prerelease: false
generateReleaseNotes: true
token: ${{ secrets.GITHUB_TOKEN }}
makeLatest: ${{ inputs.latest }}
tag: ${{ env.NEW_VERSION }}
- name: Output new version
id: output_version
run: |
echo NEW_VERSION=${{ env.NEW_VERSION }} >> $GITHUB_OUTPUT
define_envs:
runs-on: ubuntu-latest
outputs:
REPO_NAME: ${{ steps.get_repo_name.outputs.REPO_NAME }}
REPO_FULL_NAME: ${{ steps.get_repo_full_name.outputs.REPO_FULL_NAME }}
CURRENT_DATE_TIME: ${{ steps.get_current_date_time.outputs.CURRENT_DATE_TIME }}
steps:
- name: Get repo name
shell: bash
id: get_repo_name
run: |
echo "REPO_NAME=$(basename "${{ github.repository }}")" >> $GITHUB_OUTPUT
- name: Get repo full name
shell: bash
id: get_repo_full_name
run: |
FULL_NAME=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
echo "REPO_FULL_NAME=$FULL_NAME" >> $GITHUB_OUTPUT
- name: Get current date and time
shell: bash
id: get_current_date_time
run: |
echo "CURRENT_DATE_TIME=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
build-service:
runs-on: ubuntu-latest
needs: [release, define_envs]
steps:
- name: Define service tags
run: |
if [ "${{ inputs.latest }}" = "true" ]; then
echo "SERVICE_TAGS=ghcr.io/${{ needs.define_envs.outputs.repo_full_name }}/service:${{ needs.release.outputs.NEW_VERSION }},ghcr.io/${{ needs.define_envs.outputs.repo_full_name }}/service:latest" >> $GITHUB_ENV
else
echo "SERVICE_TAGS=ghcr.io/${{ needs.define_envs.outputs.repo_full_name }}/service:${{ needs.release.outputs.NEW_VERSION }}" >> $GITHUB_ENV
fi
env:
NEW_VERSION: ${{ env.NEW_VERSION }}
- name: Checkout repository
uses: actions/checkout@v2
with:
repository: ${{ github.repository }}
- name: Checkout code
uses: actions/checkout@v2
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: 'ghcr.io'
username: ${{ github.actor }}
password: ${{ secrets.ACTION_TOKEN }}
env:
REGISTRY: 'ghcr.io'
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: '.'
file: './service/Dockerfile'
push: true
tags: ${{ env.SERVICE_TAGS }}
env:
TAGS: ${{ env.SERVICE_TAGS }}
build-app:
runs-on: ubuntu-latest
needs: [release, define_envs]
steps:
- name: Define app tags
run: |
if [ "${{ inputs.latest }}" = "true" ]; then
echo "APP_TAGS=ghcr.io/${{ needs.define_envs.outputs.repo_full_name }}/app:${{ needs.release.outputs.NEW_VERSION }},ghcr.io/${{ needs.define_envs.outputs.repo_full_name }}/app:latest" >> $GITHUB_ENV
else
echo "APP_TAGS=ghcr.io/${{ needs.define_envs.outputs.repo_full_name }}/app:${{ needs.release.outputs.NEW_VERSION }}" >> $GITHUB_ENV
fi
env:
NEW_VERSION: ${{ env.NEW_VERSION }}
- name: Checkout repository
uses: actions/checkout@v2
with:
repository: ${{ github.repository }}
- name: Checkout code
uses: actions/checkout@v2
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: 'ghcr.io'
username: ${{ github.actor }}
password: ${{ secrets.ACTION_TOKEN }}
env:
REGISTRY: 'ghcr.io'
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: '.'
file: './app/Dockerfile'
push: true
tags: ${{ env.APP_TAGS }}
env:
tags: ${{ env.APP_TAGS }}
# runs-on: ubuntu-latest
# permissions:
# contents: write
# packages: write
# actions: write
# pull-requests: write
# checks: write
# steps:
# - name: Build docker
# uses: Libertech-FR/lt-actions/release@main
# with:
# version_increment: ${{ github.event.inputs.version_increment }}
# build_docker_image: ${{ github.event.inputs.build_docker_image }}
# latest: ${{ github.event.inputs.latest }}
# repository: ${{ github.repository }}
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
# github_token: ${{ secrets.ACTION_TOKEN }}
# # Optional parameters, thoses are default values :
# registry: 'ghcr.io'
# context: ./service/
# is_branch_protected: true
# build-app:
# runs-on: ubuntu-latest
# permissions:
# contents: write
# packages: write
# steps:
# - name: Build docker
# uses: Libertech-FR/lt-actions/release@main
# with:
# version_increment: ${{ github.event.inputs.version_increment }}
# build_docker_image: ${{ github.event.inputs.build_docker_image }}
# latest: ${{ github.event.inputs.latest }}
# repository: ${{ github.repository }}
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
# github_token: ${{ secrets.ACTION_TOKEN }}
# # Optional parameters, thoses are default values :
# registry: 'ghcr.io'
# context: ./app/
# is_branch_protected: true