-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.onedev-buildspec.yml
135 lines (119 loc) · 4.9 KB
/
.onedev-buildspec.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
version: 30
jobs:
- name: Release
jobExecutor: internal
steps:
- !CheckoutStep
name: checkout code
cloneCredential: !HttpCredential
accessTokenSecret: onedev-token
withLfs: false
withSubmodules: false
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !CommandStep
name: detect version
runInContainer: true
image: ubuntu
interpreter: !DefaultInterpreter
commands: |
cat main.go|grep 'const version' | cut -d'"' -f 2 > buildVersion
useTTY: false
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !SetBuildVersionStep
name: set version
buildVersion: '@file:buildVersion@'
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !UseTemplateStep
name: build binaries
templateName: build binaries
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !PublishArtifactStep
name: publish artifacts
artifacts: '**/tod* -tod.gif'
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !CommandStep
name: publish GH release
runInContainer: true
image: '@property:buildEnvironment@'
interpreter: !DefaultInterpreter
commands: |
set -e
set -o pipefail
buildVersion=@build_version@
projectDir=`pwd`
echo "Creating release tag..."
git config --global user.name "Robin Shen"
git config --global user.email "robin@@onedev.io"
git config --global --add safe.directory /onedev-build/workspace
git tag v$buildVersion -m "Release tag"
git push -f origin v$buildVersion:v$buildVersion
git config --global --unset http.extraHeader
git push -f https://robin:@secrets:github-token@@@github.com/theonedev/tod v$buildVersion:v$buildVersion
echo "Creating release in GitHub..."
releaseId=$(curl -u robinshine:@secrets:github-token@ https://api.github.com/repos/theonedev/tod/releases/tags/v$buildVersion | jq '.id')
releaseJson="{\"name\":\"$buildVersion\",\"tag_name\":\"v$buildVersion\",\"body\":\"## Downloads\n\nhttps://code.onedev.io/onedev/tod/~builds/@build_number@/artifacts\n\n## Change Log\n\nhttps://code.onedev.io/onedev/tod/~builds/@build_number@/fixed-issues?query=%22State%22+is+%22Released%22+order+by+%22Type%22+asc+and+%22Priority%22+desc\"}"
acceptHeader="Accept: application/vnd.github.v3+json"
if [ "$releaseId" == "null" ]; then
curl -u robinshine:@secrets:github-token@ -X POST -H "$acceptHeader" -d "$releaseJson" https://api.github.com/repos/theonedev/tod/releases
else
curl -u robinshine:@secrets:github-token@ -X PATCH -H "$acceptHeader" -d "$releaseJson" https://api.github.com/repos/theonedev/tod/releases/$releaseId
fi
useTTY: false
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
retryCondition: never
maxRetries: 3
retryDelay: 30
timeout: 3600
- name: Sync with GitHub
steps:
- !CheckoutStep
name: checkout
cloneCredential: !DefaultCredential {}
withLfs: false
withSubmodules: true
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !CommandStep
name: sync
runInContainer: true
image: alpine/git:1.0.7
interpreter: !DefaultInterpreter
commands: |
git config --global --unset http.extraHeader
git push -f https://robinshine:@secrets:github-token@@@github.com/theonedev/tod HEAD:main
useTTY: false
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
triggers:
- !BranchUpdateTrigger
branches: main
projects: onedev/tod
retryCondition: never
maxRetries: 3
retryDelay: 30
timeout: 3600
stepTemplates:
- name: build binaries
steps:
- !CommandStep
name: build binaries
runInContainer: true
image: golang:1.22.1
interpreter: !DefaultInterpreter
commands: |
GOOS=windows GOARCH=amd64 go build -o windows-amd64/tod.exe
sha256sum windows-amd64/tod.exe | awk '{ print $1 }' > windows-amd64/tod.exe.sha256
GOOS=windows GOARCH=arm64 go build -o windows-arm64/tod.exe
sha256sum windows-arm64/tod.exe | awk '{ print $1 }' > windows-arm64/tod.exe.sha256
GOOS=linux GOARCH=amd64 go build -o linux-amd64/tod
sha256sum linux-amd64/tod | awk '{ print $1 }' > linux-amd64/tod.sha256
GOOS=linux GOARCH=arm64 go build -o linux-arm64/tod
sha256sum linux-arm64/tod | awk '{ print $1 }' > linux-arm64/tod.sha256
GOOS=darwin GOARCH=amd64 go build -o mac-amd64/tod
sha256sum mac-amd64/tod | awk '{ print $1 }' > mac-amd64/tod.sha256
GOOS=darwin GOARCH=arm64 go build -o mac-arm64/tod
sha256sum mac-arm64/tod | awk '{ print $1 }' > mac-arm64/tod.sha256
GOOS=freebsd GOARCH=amd64 go build -o freebsd-amd64/tod
sha256sum freebsd-amd64/tod | awk '{ print $1 }' > freebsd-amd64/tod.sha256
GOOS=freebsd GOARCH=arm64 go build -o freebsd-arm64/tod
sha256sum freebsd-arm64/tod | awk '{ print $1 }' > freebsd-arm64/tod.sha256
useTTY: false
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL