-
Notifications
You must be signed in to change notification settings - Fork 0
103 lines (91 loc) · 3.03 KB
/
release.yml
File metadata and controls
103 lines (91 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: Release
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
jobs:
build:
name: build ${{ matrix.file }} on ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- windows-latest
- ubuntu-latest # target: x86_64-unknown-linux-musl
- macos-latest
file:
- ${{ github.event.repository.name }}
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
env:
# 不同构建目标对应的 release 目录
TARGET: ${{ matrix.os == 'ubuntu-latest' && 'target/x86_64-unknown-linux-musl/release' || 'target/release' }}
# 构建文件名, Windows 平台有 .exe 后缀
NAME: ${{ format('{0}{1}', matrix.file, startsWith(matrix.os, 'windows') && '.exe' || '') }}
# 上传制品文件名
ARTIFACT_NAME: Binary-${{ matrix.file }}-${{ matrix.os }}
steps:
- uses: actions/checkout@master
with:
submodules: recursive # 递归检出git子模块(submodules)
- name: Cache
id: cache
uses: actions/cache@v3
with:
path: |
~/.cargo
~/.rustup
./target
key: ${{ runner.os }}-${{ matrix.file }}-cache
- name: musl-tools
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt install -y musl-tools
- name: Rustup
if: steps.cache.outputs.cache-hit != 'true' && matrix.os == 'ubuntu-latest'
run: |
rustup target add x86_64-unknown-linux-musl
- name: Build
env:
CARGO_TERM_COLOR: always
run: |
cargo build --release --verbose \
${{ matrix.os == 'ubuntu-latest' && '--target x86_64-unknown-linux-musl' || '--' }}
- name: Naming ${{ env.NAMING }}
id: naming
env:
NAMING: >-
${{
format('{0}-{1}-{2}-{3}{4}',
matrix.file, github.ref_name, runner.os, runner.arch,
startsWith(matrix.os, 'windows') && '.exe' || ''
)
}}
run: |
export NAMING="$( echo ${{ env.NAMING }} | tr [:upper:] [:lower:] )"
echo "FILEPATH=$TARGET/$NAMING" >> $GITHUB_OUTPUT
- name: Rename file
run: |
mv "$TARGET/$NAME" ${{ steps.naming.outputs.FILEPATH }}
- name: Upload
uses: actions/upload-artifact@master
id: artifact-upload-step
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ steps.naming.outputs.FILEPATH }}
- name: GH Release on ${{ matrix.os }}
uses: softprops/action-gh-release@v2.0.2
if: startsWith(github.ref, 'refs/tags/')
with:
token: ${{ secrets.GITHUB_TOKEN }}
files: ${{ steps.naming.outputs.FILEPATH }}
- name: Done
if: startsWith(github.ref, 'refs/tags/')
run: |
echo "### [${{ github.ref_name }}](https://github.com/$GITHUB_REPOSITORY/releases/tag/${{ github.ref_name }}) Released! :rocket:" \
>> $GITHUB_STEP_SUMMARY
permissions:
contents: write