-
Notifications
You must be signed in to change notification settings - Fork 44
209 lines (195 loc) · 8.75 KB
/
02-build-obs.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
name: build on obs
on:
workflow_call:
inputs:
repo:
required: true
type: string
tag:
type: string
tagsha:
type: string
topic:
required: true
type: string
component:
type: string
default: "main"
gitaddr:
type: string
workflow_dispatch:
inputs:
repo:
required: true
type: string
tag:
type: string
tagsha:
type: string
topic:
required: true
type: string
component:
type: string
default: "main"
env:
TOPIC: ${{ inputs.topic }}
COMPONENT: ${{ inputs.component }}
TAG: ${{ inputs.tag }}
REPO: ${{ inputs.repo }}
TAGSHA: ${{ inputs.tagsha }}
GITHUB_TOKEN: ${{ github.token }}
OSCPASS: ${{ secrets.OSCPASS }}
GITADDR: ${{ inputs.gitaddr }}
jobs:
build:
runs-on: ubuntu-latest
outputs:
pkgname: ${{ steps.pkgname.outputs.pkgname }}
tagsha: ${{ steps.tagsha.outputs.tagsha }}
targeturl: ${{ steps.build.outputs.targeturl }}
needbuild: ${{ steps.build.outputs.needbuild }}
steps:
- name: Print Environment
run: export
- name: Install tools
run: |
sudo apt-get update && sudo apt install -y osc curl
- name: pkgname
id: pkgname
run: |
echo "pkgname=$(echo ${{ inputs.repo }} |awk -F '/' '{print $2}')" >> $GITHUB_OUTPUT
- name: obs integration topic project prepare
run: |
set +e
set -x
result=$(curl -u golf66:$OSCPASS "https://build.deepin.com/source/deepin:CI:TestingIntegration:$TOPIC/_meta"|grep "unknown_project")
if [ "$result" != "" ];then
curl -o meta.xml https://raw.githubusercontent.com/deepin-community/Repository-Integration/master/.github/workflows/obs-proj-meta.tpl
sed -i "s#TOPIC#${TOPIC}#g" meta.xml
curl -X PUT -u golf66:$OSCPASS -H "Content-type: text/xml" -d @meta.xml "https://build.deepin.com/source/deepin:CI:TestingIntegration:$TOPIC/_meta"
fi
# create obs component project
if [ "$COMPONENT" != "main" ]; then
result=$(curl -u golf66:$OSCPASS "https://build.deepin.com/source/deepin:CI:TestingIntegration:$TOPIC:$COMPONENT/_meta"|grep "unknown_project")
if [ "$result" != "" ];then
curl -o meta1.xml https://raw.githubusercontent.com/deepin-community/Repository-Integration/master/.github/workflows/obs-proj-component-meta.tpl
sed -i "s#TOPIC#${TOPIC}#g" meta1.xml
sed -i "s#COMPONENT#${COMPONENT}#g" meta1.xml
if [ "$COMPONENT" = "commercial" ]; then
echo "commercail project, disable access!!!"
sed -i '4a \ \ <sourceaccess>\n\ \ \ \ <disable/>\n\ \ </sourceaccess>' meta1.xml
fi
curl -X PUT -u golf66:$OSCPASS -H "Content-type: text/xml" -d @meta1.xml "https://build.deepin.com/source/deepin:CI:TestingIntegration:$TOPIC:$COMPONENT/_meta"
fi
fi
- name: get tag info
id: tagsha
run: |
set -x
urlencode() {
local LANG=C
local length="${#1}"
i=0
while :
do
[ $length -gt $i ]&&{
local c="${1:$i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf "$c" ;;
*) printf '%%%02X' "'$c" ;;
esac
}||break
let i++
done
}
RAWTAG=$(urlencode $TAG)
echo "get tag $TAG information"
if [ -z "$TAGSHA" -a "$TAGSHA" != "undefined" ]; then
# get sha from repository git tag
TAGSHA=$(curl -H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$REPO/git/ref/tags/$RAWTAG |grep sha|awk -F "\"" '{print $4}')
if [ -z "$TAGSHA" ]; then
echo "tag invalid"
exit 1
fi
fi
echo "tagsha=$TAGSHA" >> $GITHUB_OUTPUT
- name: Trigger build
id: build
run: |
set -x
mkdir -p ~/.config/osc
echo "${{ secrets.OSCRC }}" > ~/.config/osc/oscrc
pkgname="${{ steps.pkgname.outputs.pkgname }}"
TAGSHA="${{ steps.tagsha.outputs.tagsha}}"
curl -o meta.xml https://raw.githubusercontent.com/deepin-community/Repository-Integration/master/.github/workflows/obs-pkg-meta.tpl
sed -i "s#PKGNAME#${pkgname}#g" meta.xml
targeturl="https://build.deepin.com/project/show/deepin:CI:TestingIntegration:${TOPIC}"
uploadurl="https://build.deepin.com/source/deepin:CI:TestingIntegration:${TOPIC}"
if [ "$COMPONENT" = "main" ]; then
sed -i "s#Testing:COMPONENT#CI:TestingIntegration:${TOPIC}#g" meta.xml
curl -X PUT -u golf66:$OSCPASS -H "Content-type: text/xml" -d @meta.xml "https://build.deepin.com/source/deepin:CI:TestingIntegration:${TOPIC}/$pkgname/_meta"
# osc co deepin:CI:TestingIntegration:${TOPIC}/${pkgname} && cd $_
osc co deepin:CI:TestingIntegration:${TOPIC}/${pkgname} _branch_request || true
osc co deepin:CI:TestingIntegration:${TOPIC}/${pkgname} _service || true
targeturl="https://build.deepin.com/package/live_build_log/deepin:CI:TestingIntegration:${TOPIC}/$pkgname/testing/"
uploadurl="https://build.deepin.com/source/deepin:CI:TestingIntegration:${TOPIC}/$pkgname"
else
sed -i "s#Testing:COMPONENT#CI:TestingIntegration:${TOPIC}:${COMPONENT}#g" meta.xml
curl -X PUT -u golf66:$OSCPASS -H "Content-type: text/xml" -d @meta.xml "https://build.deepin.com/source/deepin:CI:TestingIntegration:${TOPIC}:${COMPONENT}/$pkgname/_meta"
# osc co deepin:CI:TestingIntegration:${TOPIC}:${COMPONENT}/${pkgname} && cd $_
osc co deepin:CI:TestingIntegration:${TOPIC}:${COMPONENT}/${pkgname} _branch_request || true
osc co deepin:CI:TestingIntegration:${TOPIC}:${COMPONENT}/${pkgname} _service || true
targeturl="https://build.deepin.com/package/live_build_log/deepin:CI:TestingIntegration:${TOPIC}:${COMPONENT}/$pkgname/testing/"
uploadurl="https://build.deepin.com/source/deepin:CI:TestingIntegration:${TOPIC}:${COMPONENT}/$pkgname"
fi
echo "targeturl=$targeturl" >> $GITHUB_OUTPUT
needbuild=true
if [ -f _branch_request ];then
cat _branch_request |grep "${TAGSHA}" && needbuild=false ||echo true
fi
if [ ! -f _service ];then
curl -o _service https://raw.githubusercontent.com/deepin-community/Repository-Integration/master/.github/workflows/obs-pkg.tpl && \
sed -i "s#REPO#$REPO#g" _service
if [ "$COMPONENT" = "commercial" ]; then
echo "commercial package, need use private git ssh address!!!"
new_content=" <param name=\"url\">${GITADDR}</param>"
sed -i "3c ${new_content}" _service
revision=" <param name=\"revision\">${TAGSHA}</param>"
sed -i "3a ${revision}" _service
echo "commercial package, disable build source!!!"
echo "exec dpkg-buildpackage -us -uc --build=any,all \"\$@\"" > build.script
curl -X PUT -u golf66:$OSCPASS -d @build.script -s "$uploadurl/build.script"
fi
curl -X PUT -u golf66:$OSCPASS -d @_service -s "$uploadurl/_service"
fi
if [ $needbuild = "true" -a "$COMPONENT" != "commercial" ];then
curl -o _branch_request https://raw.githubusercontent.com/deepin-community/Repository-Integration/master/.github/workflows/obs-br.tpl
sed -i "s#REPO#$REPO#g" _branch_request
sed -i "s#TAGSHA#$TAGSHA#g" _branch_request
# osc add _branch_request && osc ci -m "Update tag release: $TAGSHA"
curl -X PUT -u golf66:$OSCPASS -d @_branch_request -s "$uploadurl/_branch_request"
else
echo "$REPO source unchanged, skip!!!"
fi
echo "needbuild=$needbuild" >> $GITHUB_OUTPUT
log:
needs: build
strategy:
matrix:
arch: [aarch64, x86_64]
runs-on: ubuntu-latest
env:
ARCH: ${{ matrix.arch }}
steps:
- name: Set commit status as pending
if: ${{ needs.build.outputs.needbuild == 'true' }}
uses: myrotvorets/set-commit-status-action@master
with:
token: ${{ github.token }}
status: pending
context: "${{ needs.build.outputs.pkgname }}_${{ matrix.arch }}_testing_repository_building"
targetUrl: "${{ needs.build.outputs.targeturl }}${{ matrix.arch }}"
sha: ${{ github.event.pull_request.head.sha }}