Skip to content

Commit 1ae0e65

Browse files
committed
build(release): add release ci/cd
* github workflow * cargo.toml improvment Signed-off-by: leofvo <leofvo@proton.me>
1 parent 59b67f3 commit 1ae0e65

File tree

2 files changed

+241
-0
lines changed

2 files changed

+241
-0
lines changed

.github/workflows/release.yml

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
name: Release
2+
on:
3+
# schedule:
4+
# - cron: '0 0 * * *' # midnight UTC
5+
6+
push:
7+
tags:
8+
- 'v[0-9]+.[0-9]+.[0-9]+'
9+
## - release
10+
11+
pull_request:
12+
branches:
13+
- master
14+
paths:
15+
- 'package.json'
16+
- 'package-lock.json'
17+
- 'CHANGELOG.md'
18+
- '.github/workflows/release.yml'
19+
20+
env:
21+
BIN_NAME: rustscan
22+
PROJECT_NAME: rustscan
23+
REPO_NAME: RustScan/RustScan
24+
# BREW_TAP: RustScan/homebrew-tap
25+
26+
jobs:
27+
dist:
28+
name: Dist
29+
runs-on: ${{ matrix.os }}
30+
strategy:
31+
fail-fast: false # don't fail other jobs if one fails
32+
matrix:
33+
build: [x86_64-linux, x86_64-macos, x86_64-windows] #, x86_64-win-gnu, win32-msvc
34+
include:
35+
- build: x86_64-linux
36+
os: ubuntu-20.04
37+
rust: stable
38+
target: x86_64-unknown-linux-gnu
39+
cross: false
40+
- build: x86_64-macos
41+
os: macos-latest
42+
rust: stable
43+
target: x86_64-apple-darwin
44+
cross: false
45+
- build: x86_64-windows
46+
os: windows-2019
47+
rust: stable
48+
target: x86_64-pc-windows-msvc
49+
cross: false
50+
# - build: aarch64-linux
51+
# os: ubuntu-20.04
52+
# rust: stable
53+
# target: aarch64-unknown-linux-gnu
54+
# - build: aarch64-macos
55+
# os: macos-latest
56+
# rust: stable
57+
# target: aarch64-apple-darwin
58+
# - build: x86_64-win-gnu
59+
# os: windows-2019
60+
# rust: stable-x86_64-gnu
61+
# target: x86_64-pc-windows-gnu
62+
# - build: win32-msvc
63+
# os: windows-2019
64+
# rust: stable
65+
# target: i686-pc-windows-msvc
66+
67+
steps:
68+
- name: Strip release binary (linux and macos)
69+
if: matrix.build == 'x86_64-windows' # Windows is missing some dependencies
70+
run: |
71+
git config --global pack.windowMemory "100m"
72+
git config --global pack.packSizeLimit "100m"
73+
git config --global pack.threads "1"
74+
git config --global pack.deltaCacheSize "512m"
75+
76+
- name: Install python 3.10 for windows
77+
if: matrix.build == 'x86_64-windows' # Windows is missing some dependencies
78+
uses: actions/setup-python@v4
79+
with:
80+
python-version: '3.10'
81+
82+
- name: Checkout sources
83+
uses: actions/checkout@v2
84+
with:
85+
submodules: true
86+
87+
- name: Install ${{ matrix.rust }} toolchain
88+
uses: actions-rs/toolchain@v1
89+
with:
90+
profile: minimal
91+
toolchain: ${{ matrix.rust }}
92+
target: ${{ matrix.target }}
93+
override: true
94+
95+
- name: Run cargo test
96+
uses: actions-rs/cargo@v1
97+
with:
98+
use-cross: ${{ matrix.cross }}
99+
command: test
100+
args: --release --locked --target ${{ matrix.target }}
101+
102+
- name: Build release binary
103+
uses: actions-rs/cargo@v1
104+
with:
105+
use-cross: ${{ matrix.cross }}
106+
command: build
107+
args: --release --locked --target ${{ matrix.target }}
108+
109+
- name: Strip release binary (linux and macos)
110+
if: matrix.build == 'x86_64-linux' || matrix.build == 'x86_64-macos'
111+
run: strip "target/${{ matrix.target }}/release/$BIN_NAME"
112+
113+
- name: Strip release binary (arm)
114+
if: matrix.build == 'aarch64-linux'
115+
run: |
116+
docker run --rm -v \
117+
"$PWD/target:/target:Z" \
118+
rustembedded/cross:${{ matrix.target }} \
119+
aarch64-linux-gnu-strip \
120+
/target/${{ matrix.target }}/release/$BIN_NAME
121+
- name: Build archive
122+
shell: bash
123+
run: |
124+
mkdir dist
125+
if [ "${{ matrix.os }}" = "windows-2019" ]; then
126+
cp "target/${{ matrix.target }}/release/$BIN_NAME.exe" "dist/"
127+
else
128+
cp "target/${{ matrix.target }}/release/$BIN_NAME" "dist/"
129+
fi
130+
- uses: actions/upload-artifact@v2.2.4
131+
with:
132+
name: bins-${{ matrix.build }}
133+
path: dist
134+
135+
publish:
136+
name: Publish
137+
needs: [dist]
138+
if: contains(fromJson('["push", "schedule"]'), github.event_name) && startsWith(github.ref, 'refs/tags/')
139+
runs-on: ubuntu-latest
140+
steps:
141+
- name: Checkout sources
142+
uses: actions/checkout@v2
143+
with:
144+
submodules: false
145+
146+
- uses: actions/download-artifact@v2
147+
# with:
148+
# path: dist
149+
# - run: ls -al ./dist
150+
- run: ls -al bins-*
151+
152+
- name: Calculate tag name
153+
run: |
154+
name=dev
155+
if [[ $GITHUB_REF == refs/tags/v* ]]; then
156+
name=${GITHUB_REF:10}
157+
fi
158+
echo ::set-output name=val::$name
159+
echo TAG=$name >> $GITHUB_ENV
160+
id: tagname
161+
162+
- name: Build archive
163+
shell: bash
164+
run: |
165+
set -ex
166+
rm -rf tmp
167+
mkdir tmp
168+
mkdir dist
169+
for dir in bins-* ; do
170+
platform=${dir#"bins-"}
171+
unset exe
172+
if [[ $platform =~ "windows" ]]; then
173+
exe=".exe"
174+
fi
175+
pkgname=$PROJECT_NAME-$TAG-$platform
176+
mkdir tmp/$pkgname
177+
# cp LICENSE README.md tmp/$pkgname
178+
mv bins-$platform/$BIN_NAME$exe tmp/$pkgname
179+
chmod +x tmp/$pkgname/$BIN_NAME$exe
180+
if [ "$exe" = "" ]; then
181+
tar cJf dist/$pkgname.tar.xz -C tmp $pkgname
182+
else
183+
(cd tmp && 7z a -r ../dist/$pkgname.zip $pkgname)
184+
fi
185+
done
186+
- name: Upload binaries to release
187+
uses: svenstaro/upload-release-action@v2
188+
with:
189+
repo_token: ${{ secrets.GITHUB_TOKEN }}
190+
file: dist/*
191+
file_glob: true
192+
tag: ${{ steps.tagname.outputs.val }}
193+
overwrite: true
194+
195+
- name: Extract version
196+
id: extract-version
197+
run: |
198+
printf "::set-output name=%s::%s\n" tag-name "${GITHUB_REF#refs/tags/}"
199+
- uses: mislav/bump-homebrew-formula-action@v1
200+
with:
201+
formula-path: ${{env.PROJECT_NAME}}.rb
202+
homebrew-tap: ${{ env.BREW_TAP }}
203+
download-url: 'https://github.com/${{ env.REPO_NAME }}/releases/download/${{ steps.extract-version.outputs.tag-name }}/${{env.PROJECT_NAME}}-${{ steps.extract-version.outputs.tag-name }}-x86_64-macos.tar.xz'
204+
commit-message: updating formula for ${{ env.PROJECT_NAME }}
205+
env:
206+
COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
207+
#
208+
# you can use this initial file in your homebrew-tap if you don't have an initial formula:
209+
# <projectname>.rb
210+
#
211+
# class <Projectname capitalized> < Formula
212+
# desc "A test formula"
213+
# homepage "http://www.example.com"
214+
# url "-----"
215+
# version "-----"
216+
# sha256 "-----"
217+
218+
# def install
219+
# bin.install "<bin-name>"
220+
# end
221+
# end
222+
223+
# Uncomment this section if you want to release your package to crates.io
224+
# Before publishing, make sure you have filled out the following fields:
225+
# license or license-file, description, homepage, documentation, repository, readme.
226+
# Read more: https://doc.rust-lang.org/cargo/reference/publishing.html
227+
228+
- name: Install ${{ matrix.rust }} toolchain
229+
uses: actions-rs/toolchain@v1
230+
with:
231+
profile: minimal
232+
toolchain: ${{ matrix.rust }}
233+
target: ${{ matrix.target }}
234+
- run: cargo publish --token ${CRATES_TOKEN}
235+
env:
236+
CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }}

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,8 @@ section = "rust"
5050
[profile.release]
5151
lto = true
5252
panic = 'abort'
53+
54+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
55+
[[bin]]
56+
name = "rustscan"
57+
path = "src/main.rs"

0 commit comments

Comments
 (0)