1
+ #
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ # SPDX-FileCopyrightText: Huawei Inc.
4
+ #
5
+
6
+ name : release
7
+ on :
8
+ workflow_dispatch :
9
+ inputs :
10
+ ReleaseType :
11
+ type : choice
12
+ description : Select the version to released
13
+ options :
14
+ - Major Version
15
+ - Minor Version
16
+ - Patch Version
17
+
18
+ env :
19
+ BOT_USER_NAME : eclipse-xpanse-bot
20
+
21
+ REGISTRY : ghcr.io
22
+ IMAGE_NAME : ${{ github.repository }}
23
+
24
+ jobs :
25
+ pre-release :
26
+ runs-on : ubuntu-latest
27
+ permissions :
28
+ contents : write
29
+ steps :
30
+ - name : Checkout
31
+ uses : actions/checkout@v4
32
+ with :
33
+ token : ${{ secrets.BOT_GITHUB_TOKEN }}
34
+ - name : Set current version env variable
35
+ id : version
36
+ run : |
37
+ echo "CurrentVersion=$(sed -n 's/^.*version.*= *"\([a-z0-9.]*\)"/\1/pg' version.go)" >> $GITHUB_OUTPUT
38
+ if [ "${{github.event.inputs.ReleaseType}}" = "Major Version" ]; then
39
+ echo "VersionFragment=major" >> $GITHUB_ENV
40
+ elif [ "${{github.event.inputs.ReleaseType}}" = "Minor Version" ]; then
41
+ echo "VersionFragment=feature" >> $GITHUB_ENV
42
+ elif [ "${{github.event.inputs.ReleaseType}}" = "Patch Version" ]; then
43
+ echo "VersionFragment=bug" >> $GITHUB_ENV
44
+ else
45
+ echo "No matching feature type found"
46
+ fi
47
+ - name : Set next development version environment variable
48
+ id : new_version
49
+ uses :
christian-draeger/[email protected]
50
+ with :
51
+ current-version : ${{ steps.version.outputs.CurrentVersion }}
52
+ version-fragment : ${{ env.VersionFragment }}
53
+ - name : Update version
54
+ run : |
55
+ sed -i 's/\(^.*version.*= *"\)\([a-z0-9.]*\)"/\1${{ steps.new_version.outputs.next-version }}"/g' version/version.go
56
+ - uses : EndBug/add-and-commit@v9
57
+ with :
58
+ message : Release v${{ steps.new_version.outputs.next-version }}
59
+ committer_name : ${{ env.BOT_USER_NAME }}
60
+ committer_email : ${{ env.BOT_EMAIL_ID }}
61
+ - name : Create a GitHub tag
62
+ # This action here is only target for creating a tag, but it also created a simple github release which will be rewritten by the following goreleaser job.
63
+ # That may gain a little benefit in case the goreleaser job failed. Anyway, it should be replaced by some other actions which creating tags only.
64
+ uses : ncipollo/release-action@v1
65
+ with :
66
+ tag : v${{ steps.new_version.outputs.next-version }}
67
+ name : v${{ steps.new_version.outputs.next-version }}
68
+ outputs :
69
+ current_version : ${{ steps.version.outputs.CurrentVersion }}
70
+ release_version : v${{ steps.new_version.outputs.next-version }}
71
+ docker-releaser :
72
+ needs : pre-release
73
+ runs-on : ubuntu-latest
74
+ steps :
75
+ - name : Checkout
76
+ uses : actions/checkout@v4
77
+ with :
78
+ fetch-depth : 0
79
+ ref : ${{ needs.pre-release.outputs.release_version }}
80
+ - name : Set up Go
81
+ uses : actions/setup-go@v5
82
+ with :
83
+ go-version : " >=1.21"
84
+ - name : Build policy-man
85
+ run : make build
86
+ - name : Set up Docker Buildx
87
+ uses : docker/setup-buildx-action@v3
88
+ - name : Login to Github Packages
89
+ uses : docker/login-action@v3
90
+ with :
91
+ registry : ghcr.io
92
+ username : ${{ env.BOT_USER_NAME }}
93
+ password : ${{ secrets.BOT_GITHUB_DOCKER_TOKEN }}
94
+ - name : Extract Docker metadata
95
+ id : meta
96
+
97
+ with :
98
+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
99
+ - name : Build Docker Image and Push
100
+
101
+ with :
102
+ context : .
103
+ push : true
104
+ tags : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.pre-release.outputs.release_version }}
105
+ labels : ${{ steps.meta.outputs.labels }}
106
+ provenance : false
107
+ goreleaser :
108
+ runs-on : ubuntu-latest
109
+ needs : pre-release
110
+ permissions :
111
+ contents : write
112
+ steps :
113
+ - name : Checkout
114
+ uses : actions/checkout@v4
115
+ with :
116
+ fetch-depth : 0
117
+ ref : ${{ needs.pre-release.outputs.release_version }}
118
+ - name : Set up Go
119
+ uses : actions/setup-go@v5
120
+ with :
121
+ go-version : " >=1.21"
122
+ - name : Import GPG key
123
+ id : import_gpg
124
+ uses : crazy-max/ghaction-import-gpg@v6
125
+ with :
126
+ gpg_private_key : ${{ secrets.ORG_GPG_PRIVATE_KEY }}
127
+ passphrase : ${{ secrets.ORG_GPG_PASSPHRASE }}
128
+ - name : Run GoReleaser
129
+ uses : goreleaser/goreleaser-action@v6
130
+ with :
131
+ version : latest
132
+ args : release --rm-dist
133
+ env :
134
+ GPG_FINGERPRINT : ${{ steps.import_gpg.outputs.fingerprint }}
135
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments