Skip to content

Commit be1e441

Browse files
committed
add release CI and cleanup useless files
1 parent 03691fc commit be1e441

File tree

5 files changed

+250
-7
lines changed

5 files changed

+250
-7
lines changed

.github/workflows/release.yml

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
name: Release
2+
3+
env:
4+
# The name of the project
5+
PROJECT_NAME: dfu-discovery
6+
DIST_DIR: dist
7+
ARTIFACT_NAME: dist
8+
# The project's folder on Arduino's download server for uploading builds
9+
AWS_PLUGIN_TARGET: /discovery/dfu-discovery/
10+
11+
on:
12+
push:
13+
tags:
14+
- "[0-9]+.[0-9]+.[0-9]+*"
15+
16+
jobs:
17+
create-release-artifacts:
18+
runs-on: ubuntu-latest
19+
20+
strategy:
21+
matrix:
22+
config:
23+
- os: Linux
24+
arch: 64bit
25+
platform_dir: linux_amd64
26+
cross_compile: x86_64-ubuntu16.04-linux-gnu
27+
- os: Linux
28+
arch: 32bit
29+
platform_dir: linux_amd32
30+
cross_compile: i686-ubuntu16.04-linux-gnu
31+
- os: Linux
32+
arch: ARMv6
33+
platform_dir: linux_arm_6
34+
cross_compile: arm-linux-gnueabihf
35+
- os: Linux
36+
arch: ARM64
37+
platform_dir: linux_arm_64
38+
cross_compile: aarch64-linux-gnu
39+
- os: macOS
40+
arch: 64bit
41+
platform_dir: osx_darwin_amd64
42+
cross_compile: x86_64-apple-darwin13
43+
cross_compiler: o64-clang++
44+
additional_flags: -framework IOKit -framework CoreFoundation -framework Security
45+
# ar: /opt/osxcross/target/bin/x86_64-apple-darwin13-ar # we have to manually specify the full path otherwise it's not found for some reason
46+
# ld: /opt/osxcross/target/bin/x86_64-apple-darwin13-ld
47+
- os: Windows
48+
arch: 32bit
49+
platform_dir: windows_386
50+
cross_compile: i686-w64-mingw32
51+
cross_compiler: i686-w64-mingw32-g++-posix
52+
additional_flags: --static
53+
ext: .exe
54+
# - Windows_64bit
55+
# - Linux_ARMv7
56+
# - macOS_ARM64
57+
58+
container:
59+
image: ghcr.io/arduino/crossbuild:0.2.2
60+
61+
steps:
62+
- name: Checkout repository
63+
uses: actions/checkout@v3
64+
with:
65+
fetch-depth: 0
66+
67+
- name: Create changelog
68+
# Avoid creating the same changelog for each os
69+
if: matrix.config.os == 'Windows'
70+
uses: arduino/create-changelog@v1
71+
with:
72+
tag-regex: '^v[0-9]+\.[0-9]+\.[0-9]+.*$'
73+
filter-regex: '^\[(skip|changelog)[ ,-](skip|changelog)\].*'
74+
case-insensitive-regex: true
75+
changelog-file-path: "${{ env.DIST_DIR }}/CHANGELOG.md"
76+
77+
# TODO check if this is required
78+
# - name: replace system ranlib with darwin one
79+
# # for some reason is not possible to override ranlib with env vars, so this is ugly but it's the only way I found
80+
# if: matrix.config.os == 'macOS'
81+
# run: |
82+
# mv /usr/bin/ranlib /usr/bin/ranlib.bk
83+
# ln -s /opt/osxcross/target/bin/${{ matrix.config.cross_compile }}-ranlib /usr/bin/ranlib
84+
85+
- name: Build MacOS or Windows
86+
# For macOS we disable the static flags and we use frameworks, for Windows the opposite
87+
if: matrix.config.os != 'Linux'
88+
run: |
89+
${{ matrix.config.cross_compiler }} \
90+
main.cpp \
91+
-I/opt/lib/${{ matrix.config.cross_compile }}/include/libusb-1.0/ \
92+
-L/opt/lib/${{ matrix.config.cross_compile }}/lib \
93+
-lusb-1.0 -pthread -fpermissive \
94+
${{ matrix.config.additional_flags }} \
95+
-o dfu-discovery${{ matrix.config.ext }}
96+
97+
- name: Build Linux
98+
if: matrix.config.os == 'Linux'
99+
run: |
100+
${{ matrix.config.cross_compile }}-g++ \
101+
main.cpp \
102+
-I/opt/lib/${{ matrix.config.cross_compile }}/include/libusb-1.0/ \
103+
-L/opt/lib/${{ matrix.config.cross_compile }}/lib \
104+
-lusb-1.0 -pthread -fpermissive \
105+
--static \
106+
-o dfu-discovery
107+
108+
- name: Package
109+
run: | # we need to create the subdir where to place binaries
110+
mkdir -p ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_${{ matrix.config.platform_dir }}/
111+
mv -v ${{ env.PROJECT_NAME }}${{ matrix.config.ext }} ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_${{ matrix.config.platform_dir }}/
112+
# mv -v LICENSE.txt ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_${{ matrix.config.platform_dir }}/LICENSE.txt #TODO add license
113+
tar -czv ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_${{ matrix.config.platform_dir }} -f ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_${GITHUB_REF##*/}_${{ matrix.config.os }}_${{ matrix.config.arch }}.tar.gz
114+
115+
- name: Upload artifacts
116+
uses: actions/upload-artifact@v3
117+
with:
118+
if-no-files-found: error
119+
name: ${{ env.ARTIFACT_NAME }}
120+
path: ${{ env.DIST_DIR }}
121+
122+
create-release:
123+
runs-on: ubuntu-latest
124+
needs: create-release-artifacts
125+
126+
steps:
127+
- name: Checkout repository
128+
uses: actions/checkout@v3
129+
130+
- name: Download artifact
131+
uses: actions/download-artifact@v3
132+
with:
133+
name: ${{ env.ARTIFACT_NAME }}
134+
path: ${{ env.DIST_DIR }}
135+
136+
- name: Create checksum file
137+
working-directory: ${{ env.DIST_DIR}}
138+
run: |
139+
TAG="${GITHUB_REF/refs\/tags\//}"
140+
sha256sum ${{ env.PROJECT_NAME }}_${TAG}* > ${TAG}-checksums.txt
141+
142+
- name: Identify Prerelease
143+
# This is a workaround while waiting for create-release action
144+
# to implement auto pre-release based on tag
145+
id: prerelease
146+
run: |
147+
wget -q -P /tmp https://github.com/fsaintjacques/semver-tool/archive/3.2.0.zip
148+
unzip -p /tmp/3.2.0.zip semver-tool-3.2.0/src/semver >/tmp/semver && chmod +x /tmp/semver
149+
if [[ \
150+
"$(
151+
/tmp/semver get prerel \
152+
"${GITHUB_REF/refs\/tags\//}"
153+
)" != \
154+
"" \
155+
]]; then
156+
echo "IS_PRE=true" >> $GITHUB_OUTPUT
157+
fi
158+
159+
- name: Generate package index entry
160+
run: |
161+
TAG=${GITHUB_REF/refs\/tags\//}
162+
package_index=`cat package_index.template | sed s/%%VERSION%%/${TAG}/`
163+
declare -a target_folders=("Windows_32bit" "Linux_64bit" "macOS_64bit" "Linux_32bit" "Linux_ARMv6" "Linux_ARM64")
164+
cd dist
165+
for folder in "${target_folders[@]}"
166+
do
167+
ARCHIVE_NAME=${{ env.PROJECT_NAME }}_${TAG}_${folder}.tar.gz
168+
T_OS=`echo ${folder} | awk '{print toupper($0)}'`
169+
SHASUM=`sha256sum ${ARCHIVE_NAME} | cut -f1 -d" "`
170+
SIZE=`stat --printf="%s" ${ARCHIVE_NAME}`
171+
package_index=`echo "$package_index" |
172+
sed s/%%FILENAME_${T_OS}%%/${ARCHIVE_NAME}/ |
173+
sed s/%%FILENAME_${T_OS}%%/${ARCHIVE_NAME}/ |
174+
sed s/%%SIZE_${T_OS}%%/${SIZE}/ |
175+
sed s/%%SHA_${T_OS}%%/${SHASUM}/`
176+
done
177+
cd ..
178+
echo ================== CUT ME HERE =====================
179+
echo "${package_index}"
180+
echo "${package_index}" > package_index_draft.json
181+
182+
- name: Create Github Release and upload artifacts
183+
uses: ncipollo/release-action@v1
184+
with:
185+
token: ${{ secrets.GITHUB_TOKEN }}
186+
bodyFile: ${{ env.DIST_DIR }}/CHANGELOG.md
187+
draft: false
188+
prerelease: ${{ steps.prerelease.outputs.IS_PRE }}
189+
# NOTE: "Artifact is a directory" warnings are expected and don't indicate a problem
190+
# (all the files we need are in the DIST_DIR root)
191+
artifacts: ${{ env.DIST_DIR }}/*,package_index_draft.json"
192+
193+
- name: Upload release files on Arduino downloads servers
194+
uses: docker://plugins/s3
195+
env:
196+
PLUGIN_SOURCE: "${{ env.DIST_DIR }}/*"
197+
PLUGIN_TARGET: ${{ env.AWS_PLUGIN_TARGET }}
198+
PLUGIN_STRIP_PREFIX: "${{ env.DIST_DIR }}/"
199+
PLUGIN_BUCKET: ${{ secrets.DOWNLOADS_BUCKET }}
200+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
201+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
compile.sh
1+
dfu-discovery*

compile.sh

Lines changed: 0 additions & 1 deletion
This file was deleted.

compile_mac_m1.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

package_index.template

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "dfu-discovery",
3+
"version": "%%VERSION%%",
4+
"systems": [
5+
{
6+
"host": "x86_64-apple-darwin12",
7+
"url": "https://downloads.arduino.cc/discovery/dfu-discovery/%%FILENAME_MACOS_64BIT%%",
8+
"archiveFileName": "%%FILENAME_MACOS_64BIT%%",
9+
"size": "%%SIZE_MACOS_64BIT%%",
10+
"checksum": "SHA-256:%%SHA_MACOS_64BIT%%"
11+
},
12+
{
13+
"host": "arm-linux-gnueabihf",
14+
"url": "https://downloads.arduino.cc/discovery/dfu-discovery/%%FILENAME_LINUX_ARMV6%%",
15+
"archiveFileName": "%%FILENAME_LINUX_ARMV6%%",
16+
"size": "%%SIZE_LINUX_ARMV6%%",
17+
"checksum": "SHA-256:%%SHA_LINUX_ARMV6%%"
18+
},
19+
{
20+
"host": "aarch64-linux-gnu",
21+
"url": "https://downloads.arduino.cc/discovery/dfu-discovery/%%FILENAME_LINUX_ARM64%%",
22+
"archiveFileName": "%%FILENAME_LINUX_ARM64%%",
23+
"size": "%%SIZE_LINUX_ARM64%%",
24+
"checksum": "SHA-256:%%SHA_LINUX_ARM64%%"
25+
},
26+
{
27+
"host": "x86_64-linux-gnu",
28+
"url": "https://downloads.arduino.cc/discovery/dfu-discovery/%%FILENAME_LINUX_64BIT%%",
29+
"archiveFileName": "%%FILENAME_LINUX_64BIT%%",
30+
"size": "%%SIZE_LINUX_64BIT%%",
31+
"checksum": "SHA-256:%%SHA_LINUX_64BIT%%"
32+
},
33+
{
34+
"host": "i686-linux-gnu",
35+
"url": "https://downloads.arduino.cc/discovery/dfu-discovery/%%FILENAME_LINUX_32BIT%%",
36+
"archiveFileName": "%%FILENAME_LINUX_32BIT%%",
37+
"size": "%%SIZE_LINUX_32BIT%%",
38+
"checksum": "SHA-256:%%SHA_LINUX_32BIT%%"
39+
},
40+
{
41+
"host": "i686-mingw32",
42+
"url": "https://downloads.arduino.cc/discovery/dfu-discovery/%%FILENAME_WINDOWS_32BIT%%",
43+
"archiveFileName": "%%FILENAME_WINDOWS_32BIT%%",
44+
"size": "%%SIZE_WINDOWS_32BIT%%",
45+
"checksum": "SHA-256:%%SHA_WINDOWS_32BIT%%"
46+
}
47+
]
48+
}

0 commit comments

Comments
 (0)