Skip to content

Commit 3322d48

Browse files
committed
feat(ci): push binaries to release
1 parent 86e1da6 commit 3322d48

File tree

1 file changed

+69
-2
lines changed

1 file changed

+69
-2
lines changed

.github/workflows/rust.yml

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: Rust
33
on:
44
push:
55
branches: [ master ]
6+
tags:
7+
- 'v*'
68
pull_request:
79
branches: [ master ]
810

@@ -12,15 +14,80 @@ defaults:
1214

1315
env:
1416
CARGO_TERM_COLOR: always
17+
BINARY_NAME: control
1518

1619
jobs:
1720
build:
18-
1921
runs-on: ubuntu-latest
20-
2122
steps:
2223
- uses: actions/checkout@v2
2324
- name: Build
2425
run: cargo build --verbose
2526
- name: Run tests
2627
run: cargo test --verbose
28+
29+
release:
30+
name: Build Release
31+
runs-on: ubuntu-latest
32+
if: startsWith(github.ref, 'refs/tags/')
33+
needs: build
34+
strategy:
35+
matrix:
36+
target:
37+
- x86_64-linux-gnu # amd64
38+
- aarch64-linux-gnu # arm64
39+
steps:
40+
- uses: actions/checkout@v2
41+
42+
- name: Install Rust toolchain
43+
uses: actions-rs/toolchain@v1
44+
with:
45+
profile: minimal
46+
toolchain: stable
47+
target: ${{ matrix.target }}
48+
override: true
49+
50+
- name: Install cross-compilation tools
51+
uses: taiki-e/setup-cross-toolchain-action@v1
52+
with:
53+
target: ${{ matrix.target }}
54+
55+
- name: Build binary
56+
run: |
57+
cargo build --release --target ${{ matrix.target }}
58+
59+
- name: Prepare binary
60+
run: |
61+
mkdir -p release
62+
cp target/${{ matrix.target }}/release/$BINARY_NAME release/$BINARY_NAME-${{ matrix.target }}
63+
cd release && tar -czf $BINARY_NAME-${{ matrix.target }}.tar.gz $BINARY_NAME-${{ matrix.target }}
64+
65+
- name: Upload artifacts
66+
uses: actions/upload-artifact@v2
67+
with:
68+
name: ${{ env.BINARY_NAME }}-${{ matrix.target }}
69+
path: control/release/${{ env.BINARY_NAME }}-${{ matrix.target }}.tar.gz
70+
71+
upload-release:
72+
name: Upload GitHub Release
73+
needs: release
74+
runs-on: ubuntu-latest
75+
if: startsWith(github.ref, 'refs/tags/')
76+
steps:
77+
- name: Download all artifacts
78+
uses: actions/download-artifact@v2
79+
80+
- name: Get the version
81+
id: get_version
82+
run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/}
83+
84+
- name: Create Release
85+
uses: softprops/action-gh-release@v1
86+
with:
87+
name: Release ${{ steps.get_version.outputs.VERSION }}
88+
draft: false
89+
prerelease: false
90+
files: |
91+
*/*.tar.gz
92+
env:
93+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)