-
Notifications
You must be signed in to change notification settings - Fork 13
169 lines (142 loc) · 5.13 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
name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'Release version'
required: true
env:
GODIRS_NOVENDOR: '`go list ./... | grep -v /vendor/`'
PACKAGE_COMMONS: 'github.com/reportportal/commons-go'
RELEASE_DIR: 'release'
LINUX_ARTIFACT_NAME: 'service-index_linux_amd64'
WINDOWS_ARTIFACT_NAME: 'service-index_win_amd64.exe'
VERSION_PLACEHOLDER: '{{.version}}'
DOCKER_TEMPLATE_FILE: 'DockerfileTmpl'
DOCKER_BUILD_FILE: 'Dockerfile'
BUILD_INFO_LDFLAGS: >-
-ldflags "-extldflags '"-static"'
-X ${PACKAGE_COMMONS}/commons.repo=${GITHUB_REPOSITORY}
-X ${PACKAGE_COMMONS}/commons.branch=${GITHUB_SHA}
-X ${PACKAGE_COMMONS}/commons.buildDate=${BUILD_DATE}
-X ${PACKAGE_COMMONS}/commons.version=${VERSION}"
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
RELEASE_URL: ${{ steps.releaseUrl.outputs.RELEASE_URL }}
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.22.1'
- name: Go Linter
uses: golangci/golangci-lint-action@v4
with:
version: v1.56.0
args: '--deadline 10m'
- name: Go Tests
run: 'go test ${{ env.GODIRS_NOVENDOR }}'
- name: Go Dependencies
run: 'go mod download'
- name: Setup git credentials
uses: oleksiyrudenko/gha-git-credentials@v2.1.1
with:
name: 'reportportal.io'
email: 'support@reportportal.io'
token: ${{ secrets.GITHUB_TOKEN }}
- name: Tag release
id: tagRelease
run: |
git tag -a v${{ github.event.inputs.version }} -m 'Release ${{ github.event.inputs.version }}'
git push --tags
- name: Create Release
id: createRelease
uses: ncipollo/release-action@v1
with:
tag: v${{ github.event.inputs.version }}
name: Release ${{ github.event.inputs.version }}
- name: Export release URL
id: releaseUrl
run: 'echo "RELEASE_URL=${{ steps.createRelease.outputs.upload_url }}" >> $GITHUB_OUTPUT'
build:
runs-on: ubuntu-latest
needs: 'prepare'
strategy:
matrix:
os: [ 'windows', 'linux' ]
arch: [ 'amd64', 'arm64' ]
exclude:
- os: 'windows'
arch: 'arm64'
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.22.1'
- name: Get Date
run: 'echo "BUILD_DATE=`date +%FT%T%z`" >> $GITHUB_ENV'
- name: Generate name
run: |
if [ "${{ matrix.os }}" = "windows" ]; then
ARTIFACT_NAME_POSTFIX=".exe"
fi
echo "ARTIFACT_NAME=service-index_${{ matrix.os }}_${{ matrix.arch }}${ARTIFACT_NAME_POSTFIX}" >> $GITHUB_ENV
- name: Go Build
env:
CGO_ENABLED: 0
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
VERSION: ${{ github.event.inputs.version }}
run: |
if [ "${{ matrix.os }}" = "windows" ]; then
export CGO_ENABLED=0
fi
go build ${{ env.BUILD_INFO_LDFLAGS }} -o ${{ env.RELEASE_DIR }}/${{ env.ARTIFACT_NAME }} ./
file ${{ env.RELEASE_DIR }}/${{ env.ARTIFACT_NAME }}
- name: Upload Binary Asset
id: upload-binary-asset
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
RELEASE_URL=`echo '${{ needs.prepare.outputs.RELEASE_URL }}' | sed -E 's/\{[^}]*\}//'`
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Content-Type: application/octet-stream" \
"${RELEASE_URL}?name=${{ env.ARTIFACT_NAME }}" \
--data-binary "@${{ env.RELEASE_DIR }}/${{ env.ARTIFACT_NAME }}"
finish:
runs-on: ubuntu-latest
needs: 'build'
steps:
- uses: actions/checkout@v4
- name: Setup git credentials
uses: oleksiyrudenko/gha-git-credentials@v2.1.1
with:
name: 'reportportal.io'
email: 'support@reportportal.io'
token: ${{ secrets.GITHUB_TOKEN }}
- name: Update Dockerfile
id: dockerfileUpdate
run: |
sed 's/${{ env.VERSION_PLACEHOLDER }}/${{ github.event.inputs.version }}/g' ${{ env.DOCKER_TEMPLATE_FILE }} > ${{ env.DOCKER_BUILD_FILE }}
git add ${{ env.DOCKER_BUILD_FILE }}
export CHANGED=`git status | grep ${{ env.DOCKER_BUILD_FILE }} | xargs`
[ -z "${CHANGED}" ] || git commit -m "Dockerfile update"
- name: Bump version
uses: HardNorth/github-version-generate@v1
with:
version: ${{ github.event.inputs.version }}-SNAPSHOT
next-version-increment-patch: true
- name: Commit version
run: |
echo ${{ env.NEXT_VERSION }} > ${{ github.workspace }}/VERSION
git add ${{ github.workspace }}/VERSION
export CHANGED=`git status | grep VERSION | xargs`
[ -z "${CHANGED}" ] || git commit -m 'Bump new snapshot version'
git push