forked from Seeed-Studio/reCamera-OS
-
Notifications
You must be signed in to change notification settings - Fork 0
276 lines (248 loc) · 11.7 KB
/
main.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
name: Build and Create Release on Tag
on:
create:
tags:
- '**' # match all tags
workflow_dispatch:
inputs:
tag_name:
description: 'Tag name for the release'
required: true
type: string
jobs:
build-and-release:
runs-on: ubuntu-20.04
strategy:
matrix:
target:
- sg2002_recamera_emmc
- sg2002_recamera_sd
steps:
- name: Determine tag name
id: tag-name
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "Tag name provided through workflow_dispatch: ${{ github.event.inputs.tag_name }}"
echo "tag_name=${{ github.event.inputs.tag_name }}" >> "$GITHUB_OUTPUT"
elif [ "${{ github.event_name }}" == "create" ]; then
echo "Tag name provided through create event: ${GITHUB_REF#refs/tags/}"
echo "tag_name=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"
else
echo "Unknown event type"
exit 1
fi
- name: Checkout code
uses: actions/[email protected]
with:
fetch-depth: 1
- name: Get CHANGELOG.md entry
id: changelog
env:
CURRENT_TARGET: ${{ matrix.target }}
run: |
TAG=${{ steps.tag-name.outputs.tag_name }}
echo TAG=$TAG
# Get the title and content of CHANGELOG.md entry
TITLE=$(grep "^## ${TAG}" CHANGELOG.md | awk '{print $2" "$3}' | tr -d '\n')
echo $TITLE
echo "changelog_title=$TITLE" >> $GITHUB_OUTPUT
CONTENT=$(mktemp)
awk 'BEGIN {flag=0} /^## '${TAG}'/ {flag=1} flag {if (NF && !/^## /) {print}} /^## / && !/^## '${TAG}'/ {flag=0}' CHANGELOG.md > "$CONTENT"
echo "changelog_content="$CONTENT"" >> $GITHUB_OUTPUT
cat $CONTENT
# Check if title and content are not empty
if [ -z "$TITLE" ]; then echo "Title is empty. Exiting with status 1."; exit 1; fi
if [ ! -s "$CONTENT" ]; then echo "Content is empty. Exiting with status 1."; exit 1; fi
# Check if target is in the $CONTENT
if grep -q "### ${CURRENT_TARGET}" "$CONTENT"; then
echo "Found target in CONTENT: ${CURRENT_TARGET}"
echo "skip_workflow=false" >> $GITHUB_OUTPUT
else
echo "Target not found in CONTENT: ${CURRENT_TARGET}"
echo "skip_workflow=true" >> $GITHUB_OUTPUT
fi
# Watch log
echo GITHUB_OUTPUT=$GITHUB_OUTPUT
cat $GITHUB_OUTPUT
- name: Install dependencies
if: steps.changelog.outputs.skip_workflow == 'false'
run: |
sudo apt-get remove aria2 ansible shellcheck rpm xorriso zsync \
clang-6.0 lldb-6.0 lld-6.0 clang-format-6.0 clang-8 lldb-8 lld-8 clang-format-8 \
clang-9 lldb-9 lld-9 clangd-9 clang-format-9 \
esl-erlang gfortran-8 gfortran-9 \
cabal-install-2.0 cabal-install-2.2 \
cabal-install-2.4 cabal-install-3.0 cabal-install-3.2 heroku imagemagick \
libmagickcore-dev libmagickwand-dev libmagic-dev ant ant-optional kubectl \
mercurial apt-transport-https mono-complete mysql-client libmysqlclient-dev \
mysql-server mssql-tools unixodbc-dev yarn bazel chrpath libssl-dev libxft-dev \
libfreetype6 libfreetype6-dev libfontconfig1 libfontconfig1-dev \
php-zmq snmp pollinate libpq-dev postgresql-client ruby-full \
azure-cli google-cloud-sdk hhvm google-chrome-stable firefox powershell \
sphinxsearch subversion mongodb-org -yq >/dev/null 2>&1 \
|| echo "failed main apt-get remove"
echo "Removing large packages"
sudo apt-get remove -y '^dotnet-.*'
sudo apt-get remove -y '^llvm-.*'
sudo apt-get remove -y 'php.*'
sudo apt-get autoremove -y >/dev/null 2>&1
sudo apt-get clean
sudo apt-get autoremove -y >/dev/null 2>&1
sudo apt-get autoclean -y >/dev/null 2>&1
#echo "https://github.com/actions/virtual-environments/issues/709"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
echo "remove big /usr/local"
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf /usr/local/lib/android >/dev/null 2>&1
sudo rm -rf /usr/share/dotnet/sdk > /dev/null 2>&1
sudo rm -rf /usr/share/dotnet/shared > /dev/null 2>&1
sudo rm -rf /usr/share/swift > /dev/null 2>&1
sudo -E apt-get -qq update
sudo -E apt-get -y install git
sudo -E apt-get -qq autoremove --purge
sudo -E apt-get -qq clean
sudo apt-get update
sudo apt-get install -y build-essential ninja-build automake autoconf libtool wget curl git gcc libssl-dev bc slib squashfs-tools android-sdk-libsparse-utils \
android-sdk-ext4-utils jq cmake python3-distutils tclsh scons parallel ssh-client tree python3-dev python3-pip device-tree-compiler libssl-dev ssh cpio \
squashfs-tools fakeroot libncurses5 flex bison mtools
sudo apt-get clean
df -h
- name: Build ${{ matrix.target }}
id: build
if: steps.changelog.outputs.skip_workflow == 'false'
run: |
echo `pwd`
git submodule update --init --recursive --depth 1
make ${{ matrix.target }}
DIR=output/${{ matrix.target }}/install/soc_${{ matrix.target }}
echo "output_dir=./$DIR" >> $GITHUB_OUTPUT
du -h -d1
- name: Check if release exists
id: check_release
if: steps.changelog.outputs.skip_workflow == 'false'
run: |
# Todo: avoid confilict
sleep $((RANDOM % 30))
TAG=${{ steps.tag-name.outputs.tag_name }}
RELEASE_URL="https://api.github.com/repos/${{ github.repository }}/releases/tags/$TAG"
RESPONSE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" $RELEASE_URL)
RELEASE_EXISTS=$(echo $RESPONSE | jq -r '.message // empty')
if [[ -n "$RELEASE_EXISTS" && "$RELEASE_EXISTS" == "Not Found" ]]; then
echo "Release for tag $TAG does not exist."
echo "tag_exist=false" >> $GITHUB_OUTPUT
else
echo "Release for tag $TAG already exists."
echo "tag_exist=true" >> $GITHUB_OUTPUT
UPLOAD_URL=$(echo "$RESPONSE" | jq -r '.upload_url // empty')
echo "upload_url=$UPLOAD_URL" >> $GITHUB_OUTPUT
fi
- name: Create release ${{ steps.changelog.outputs.changelog_title }}
id: create_release
if: steps.changelog.outputs.skip_workflow == 'false' && steps.check_release.outputs.tag_exist == 'false'
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.tag-name.outputs.tag_name }}
release_name: ${{ steps.changelog.outputs.changelog_title }}
body_path: ${{ steps.changelog.outputs.changelog_content }}
draft: false
prerelease: true
- name: Preparing upload
id: uploader
if: steps.changelog.outputs.skip_workflow == 'false'
run: |
URL=${{ steps.create_release.outputs.upload_url }}
if [ -z "$URL" ]; then
echo "upload_url=${{ steps.check_release.outputs.upload_url }}" >> $GITHUB_OUTPUT
else
echo "upload_url=${URL}" >> $GITHUB_OUTPUT
fi
# Preparing files to upload
OUTPUT=${{ steps.build.outputs.output_dir }}
file_suffixes=("md5sum.txt" "emmc.zip" "ota.zip" "recovery.zip" "sd.zip" "emmc_sd_compat.zip" "swu.zip")
for suffix in "${file_suffixes[@]}"; do
file_path=$(find $OUTPUT/ -maxdepth 1 -name "*${suffix}")
if [ -n "$file_path" ]; then
file_name=$(basename "$file_path")
variable_name="${suffix%.*}_path"
echo "${variable_name}=${file_path}" >> "$GITHUB_OUTPUT"
variable_name="${suffix%.*}_name"
echo "${variable_name}=${file_name}" >> "$GITHUB_OUTPUT"
else
echo "No ${suffix} file found in $OUTPUT"
fi
done
# watch log
echo GITHUB_OUTPUT=$GITHUB_OUTPUT
cat $GITHUB_OUTPUT
- name: Upload md5sum file
uses: actions/[email protected]
if: steps.changelog.outputs.skip_workflow == 'false' && steps.uploader.outputs.md5sum_path != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.uploader.outputs.upload_url }}
asset_path: ${{ steps.uploader.outputs.md5sum_path }}
asset_name: ${{ steps.uploader.outputs.md5sum_name }}
asset_content_type: text/plain
- name: Upload emmc package
uses: actions/[email protected]
if: steps.changelog.outputs.skip_workflow == 'false' && steps.uploader.outputs.emmc_path != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.uploader.outputs.upload_url }}
asset_path: ${{ steps.uploader.outputs.emmc_path }}
asset_name: ${{ steps.uploader.outputs.emmc_name }}
asset_content_type: application/zip
- name: Upload ota package
uses: actions/[email protected]
if: steps.changelog.outputs.skip_workflow == 'false' && steps.uploader.outputs.ota_path != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.uploader.outputs.upload_url }}
asset_path: ${{ steps.uploader.outputs.ota_path }}
asset_name: ${{ steps.uploader.outputs.ota_name }}
asset_content_type: application/zip
- name: Upload recovery package
uses: actions/[email protected]
if: steps.changelog.outputs.skip_workflow == 'false' && steps.uploader.outputs.recovery_path != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.uploader.outputs.upload_url }}
asset_path: ${{ steps.uploader.outputs.recovery_path }}
asset_name: ${{ steps.uploader.outputs.recovery_name }}
asset_content_type: application/zip
- name: Upload sd package
uses: actions/[email protected]
if: steps.changelog.outputs.skip_workflow == 'false' && steps.uploader.outputs.sd_path != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.uploader.outputs.upload_url }}
asset_path: ${{ steps.uploader.outputs.sd_path }}
asset_name: ${{ steps.uploader.outputs.sd_name }}
asset_content_type: application/zip
- name: Upload emmc_sd_compat package
uses: actions/[email protected]
if: steps.changelog.outputs.skip_workflow == 'false' && steps.uploader.outputs.emmc_sd_compat_path != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.uploader.outputs.upload_url }}
asset_path: ${{ steps.uploader.outputs.emmc_sd_compat_path }}
asset_name: ${{ steps.uploader.outputs.emmc_sd_compat_name }}
asset_content_type: application/zip
- name: Upload swu package
uses: actions/[email protected]
if: steps.changelog.outputs.skip_workflow == 'false' && steps.uploader.outputs.swu_path != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.uploader.outputs.upload_url }}
asset_path: ${{ steps.uploader.outputs.swu_path }}
asset_name: ${{ steps.uploader.outputs.swu_name }}
asset_content_type: application/zip