Skip to content

Commit 777a2ea

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 777a2ea

File tree

2 files changed

+227
-0
lines changed

2 files changed

+227
-0
lines changed

.github/workflows/release.yml

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
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: Checkout sources
69+
uses: actions/checkout@v2
70+
with:
71+
submodules: true
72+
73+
- name: Install ${{ matrix.rust }} toolchain
74+
uses: actions-rs/toolchain@v1
75+
with:
76+
profile: minimal
77+
toolchain: ${{ matrix.rust }}
78+
target: ${{ matrix.target }}
79+
override: true
80+
81+
- name: Run cargo test
82+
uses: actions-rs/cargo@v1
83+
with:
84+
use-cross: ${{ matrix.cross }}
85+
command: test
86+
args: --release --locked --target ${{ matrix.target }}
87+
88+
- name: Build release binary
89+
uses: actions-rs/cargo@v1
90+
with:
91+
use-cross: ${{ matrix.cross }}
92+
command: build
93+
args: --release --locked --target ${{ matrix.target }}
94+
95+
- name: Strip release binary (linux and macos)
96+
if: matrix.build == 'x86_64-linux' || matrix.build == 'x86_64-macos'
97+
run: strip "target/${{ matrix.target }}/release/$BIN_NAME"
98+
99+
- name: Strip release binary (arm)
100+
if: matrix.build == 'aarch64-linux'
101+
run: |
102+
docker run --rm -v \
103+
"$PWD/target:/target:Z" \
104+
rustembedded/cross:${{ matrix.target }} \
105+
aarch64-linux-gnu-strip \
106+
/target/${{ matrix.target }}/release/$BIN_NAME
107+
- name: Build archive
108+
shell: bash
109+
run: |
110+
mkdir dist
111+
if [ "${{ matrix.os }}" = "windows-2019" ]; then
112+
cp "target/${{ matrix.target }}/release/$BIN_NAME.exe" "dist/"
113+
else
114+
cp "target/${{ matrix.target }}/release/$BIN_NAME" "dist/"
115+
fi
116+
- uses: actions/upload-artifact@v2.2.4
117+
with:
118+
name: bins-${{ matrix.build }}
119+
path: dist
120+
121+
publish:
122+
name: Publish
123+
needs: [dist]
124+
if: contains(fromJson('["push", "schedule"]'), github.event_name) && startsWith(github.ref, 'refs/tags/')
125+
runs-on: ubuntu-latest
126+
steps:
127+
- name: Checkout sources
128+
uses: actions/checkout@v2
129+
with:
130+
submodules: false
131+
132+
- uses: actions/download-artifact@v2
133+
# with:
134+
# path: dist
135+
# - run: ls -al ./dist
136+
- run: ls -al bins-*
137+
138+
- name: Calculate tag name
139+
run: |
140+
name=dev
141+
if [[ $GITHUB_REF == refs/tags/v* ]]; then
142+
name=${GITHUB_REF:10}
143+
fi
144+
echo ::set-output name=val::$name
145+
echo TAG=$name >> $GITHUB_ENV
146+
id: tagname
147+
148+
- name: Build archive
149+
shell: bash
150+
run: |
151+
set -ex
152+
rm -rf tmp
153+
mkdir tmp
154+
mkdir dist
155+
for dir in bins-* ; do
156+
platform=${dir#"bins-"}
157+
unset exe
158+
if [[ $platform =~ "windows" ]]; then
159+
exe=".exe"
160+
fi
161+
pkgname=$PROJECT_NAME-$TAG-$platform
162+
mkdir tmp/$pkgname
163+
# cp LICENSE README.md tmp/$pkgname
164+
mv bins-$platform/$BIN_NAME$exe tmp/$pkgname
165+
chmod +x tmp/$pkgname/$BIN_NAME$exe
166+
if [ "$exe" = "" ]; then
167+
tar cJf dist/$pkgname.tar.xz -C tmp $pkgname
168+
else
169+
(cd tmp && 7z a -r ../dist/$pkgname.zip $pkgname)
170+
fi
171+
done
172+
- name: Upload binaries to release
173+
uses: svenstaro/upload-release-action@v2
174+
with:
175+
repo_token: ${{ secrets.GITHUB_TOKEN }}
176+
file: dist/*
177+
file_glob: true
178+
tag: ${{ steps.tagname.outputs.val }}
179+
overwrite: true
180+
181+
- name: Extract version
182+
id: extract-version
183+
run: |
184+
printf "::set-output name=%s::%s\n" tag-name "${GITHUB_REF#refs/tags/}"
185+
- uses: mislav/bump-homebrew-formula-action@v1
186+
with:
187+
formula-path: ${{env.PROJECT_NAME}}.rb
188+
homebrew-tap: ${{ env.BREW_TAP }}
189+
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'
190+
commit-message: updating formula for ${{ env.PROJECT_NAME }}
191+
env:
192+
COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
193+
#
194+
# you can use this initial file in your homebrew-tap if you don't have an initial formula:
195+
# <projectname>.rb
196+
#
197+
# class <Projectname capitalized> < Formula
198+
# desc "A test formula"
199+
# homepage "http://www.example.com"
200+
# url "-----"
201+
# version "-----"
202+
# sha256 "-----"
203+
204+
# def install
205+
# bin.install "<bin-name>"
206+
# end
207+
# end
208+
209+
# Uncomment this section if you want to release your package to crates.io
210+
# Before publishing, make sure you have filled out the following fields:
211+
# license or license-file, description, homepage, documentation, repository, readme.
212+
# Read more: https://doc.rust-lang.org/cargo/reference/publishing.html
213+
214+
- name: Install ${{ matrix.rust }} toolchain
215+
uses: actions-rs/toolchain@v1
216+
with:
217+
profile: minimal
218+
toolchain: ${{ matrix.rust }}
219+
target: ${{ matrix.target }}
220+
- run: cargo publish --token ${CRATES_TOKEN}
221+
env:
222+
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)