7
7
types :
8
8
- closed
9
9
10
+
11
+
10
12
jobs :
11
- merge_and_publish_prod :
13
+ metadata :
12
14
runs-on : ubuntu-latest
13
15
if : github.event.pull_request.merged == true &&
14
16
(startsWith(github.event.pull_request.head.ref, 'release/') || startsWith(github.event.pull_request.head.ref, 'hotfix/'))
15
- permissions :
16
- contents : write
17
- packages : write
18
- actions : write
19
- pull-requests : write
17
+ outputs :
18
+ version : ${{ env.RELEASE_VERSION }}
19
+ branch : ${{ env.BRANCH }}
20
+ app_token : ${{ steps.app-token.outputs.token }}
21
+ app_username : ' ${{ steps.app-token.outputs.app-slug }}[bot]'
22
+ app_email : ' ${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com'
20
23
steps :
24
+ - name : Get Green Ecolution App Token
25
+ uses : actions/create-github-app-token@v2
26
+ id : app-token
27
+ with :
28
+ app-id : ${{ vars.APP_ID }}
29
+ private-key : ${{ secrets.APP_PRIVATE_KEY }}
30
+ permission-contents : write
31
+ permission-pull-request : write
32
+
33
+ - name : Get Green Ecolution App User ID
34
+ id : get-user-id
35
+ env :
36
+ GH_TOKEN : ${{ steps.app-token.outputs.token }}
37
+ run : echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
38
+
21
39
- name : Extract version from branch name (for release branches)
22
40
if : startsWith(github.event.pull_request.head.ref, 'release/')
23
41
run : |
24
42
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
25
43
VERSION=${BRANCH_NAME#release/}
26
-
27
44
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
45
+ echo "BRANCH=$BRANCH_NAME" >> $GITHUB_ENV
28
46
29
47
- name : Extract version from branch name (for hotfix branches)
30
48
if : startsWith(github.event.pull_request.head.ref, 'hotfix/')
31
49
run : |
32
50
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
33
51
VERSION=${BRANCH_NAME#hotfix/}
34
-
35
52
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
53
+ echo "BRANCH=$BRANCH_NAME" >> $GITHUB_ENV
36
54
55
+ release :
56
+ runs-on : ubuntu-latest
57
+ needs : metadata
58
+ env :
59
+ version : ${{ needs.metadata.outputs.version }}
60
+ app_token : ${{ needs.metadata.outputs.app_token }}
61
+ steps :
37
62
- name : Create Release
38
63
uses : thomaseizinger/create-release@2.0.0
39
64
env :
40
65
GITHUB_TOKEN : ${{ secrets.GREEN_ECOLUTION_PAT }}
41
66
with :
42
67
target_commitish : ${{ github.event.pull_request.merge_commit_sha }}
43
- tag_name : ${{ env.RELEASE_VERSION }}
44
- name : ${{ env.RELEASE_VERSION }}
68
+ tag_name : ${{ env.version }}
69
+ name : ${{ env.version }}
45
70
draft : false
46
71
prerelease : false
47
72
48
73
- name : Merge main into develop branch
49
74
uses : thomaseizinger/create-pull-request@1.4.0
50
75
env :
51
- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
76
+ GITHUB_TOKEN : ${{ env.app_token }}
52
77
with :
53
78
head : main
54
79
base : develop
57
82
This PR merges the main branch back into develop.
58
83
This happens to ensure that the updates that happend on the release branch, i.e. CHANGELOG and manifest updates are also present on the develop branch.
59
84
85
+ build_and_push_docker :
86
+ runs-on : ubuntu-latest
87
+ needs : metadata
88
+ permissions :
89
+ packages : write
90
+ env :
91
+ version : ${{ needs.metadata.outputs.version }}
92
+ steps :
60
93
- name : Checkout code
61
94
uses : actions/checkout@v4
62
95
@@ -70,20 +103,31 @@ jobs:
70
103
username : ${{ github.actor }}
71
104
password : ${{ secrets.GITHUB_TOKEN }}
72
105
73
- - name : set lower case owner name
74
- run : |
75
- echo "REPO_LC=${REPO,,}" >>${GITHUB_ENV}
76
- env :
77
- REPO : ' ${{ github.repository }}'
78
-
79
106
- name : Build and push
80
107
uses : docker/build-push-action@v6
81
108
with :
82
109
context : .
83
110
file : ./.docker/Dockerfile.prod
84
111
platforms : linux/amd64
85
112
push : true
86
- tags : ghcr.io/${{ env.REPO_LC }}:${{ env.RELEASE_VERSION }}, ghcr.io/${{ env.REPO_LC }}:latest
113
+ tags : ghcr.io/${{ github.repository }}:${{ env.version }}, ghcr.io/${{ github.repository }}:latest
114
+
115
+ update_deployment :
116
+ runs-on : ubuntu-latest
117
+ needs : [build_and_push_docker, metadata]
118
+ permissions :
119
+ contents : write
120
+ env :
121
+ version : ${{ needs.metadata.outputs.version }}
122
+ branch : ${{ needs.metadata.outputs.branch }}
123
+ app_token : ${{ needs.metadata.outputs.app_token }}
124
+ app_username : ${{ needs.metadata.outputs.app_username }}
125
+ app_email : ${{ needs.metadata.outputs.app_email }}
126
+ steps :
127
+ - name : Checkout code
128
+ uses : actions/checkout@v4
129
+ with :
130
+ token : ${{ env.app_token }}
87
131
88
132
- name : ' Setup yq'
89
133
uses : dcarbone/install-yq-action@v1.3.1
@@ -93,31 +137,15 @@ jobs:
93
137
94
138
- name : Initialize mandatory git config
95
139
run : |
96
- git config --global user.name 'GitHub Actions'
97
- git config --global user.email 'noreply@github.com'
98
-
99
- - name : Bump version in values/develop.yaml
100
- run : yq -i '.deployment.image.tag=strenv(RELEASE_VERSION)' ./k8s/values/prod.yaml
101
-
102
- - name : Commit k8s values files
103
- id : make-commit
104
- run : |
105
- git add ./k8s/values/prod.yaml
106
- git commit --message "chore: update prod image to version ${{ env.RELEASE_VERSION }}"
107
-
108
- echo "::set-output name=commit::$(git rev-parse HEAD)"
140
+ git config --global user.name ${{ env.app_username }}
141
+ git config --global user.email ${{ env.app_email }}
109
142
110
- - name : Commit k8s values files
111
- id : make-commit
143
+ - name : Bump version in values/stage.yaml
112
144
run : |
113
- git add ./k8s/values/prod.yaml
114
- git commit --message "chore: update prod image to version ${{ env.RELEASE_VERSION }}"
145
+ yq -i '.deployment.image.tag=strenv(version)' ./k8s/values/stage.yaml
146
+ git add ./k8s/values/stage.yaml
147
+ git commit --message "chore: update stage image to version ${{ env.version }} [skip ci]"
115
148
116
- - name : Commit k8s values and push changes
117
- env :
118
- GITHUB_TOKEN : ${{ secrets.GREEN_ECOLUTION_PAT }}
149
+ - name : Push k8s changes
119
150
run : |
120
- git add ./k8s/values/stage.yaml
121
- git commit --message "chore: update stage image to version ${{ env.RELEASE_VERSION }}" \
122
- && git push origin ${{ steps.extract_branch.outputs.branch }} \
123
- || echo "No changes to commit"
151
+ git push origin ${{ env.branch }} || echo "No changes to commit"
0 commit comments