Skip to content

Commit 27f721e

Browse files
committed
build(release): add release ci/cd
* github workflow * cargo.toml improvment
1 parent 17db512 commit 27f721e

File tree

2 files changed

+228
-0
lines changed

2 files changed

+228
-0
lines changed

.github/workflows/release.yml

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