-
Notifications
You must be signed in to change notification settings - Fork 10
154 lines (131 loc) · 4.62 KB
/
Copy pathrelease.yml
File metadata and controls
154 lines (131 loc) · 4.62 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
name: Release
on:
push:
tags:
- 'v*' # 当推送以 v 开头的 tag 时触发,例如 v0.1.0
workflow_dispatch: # 允许手动触发
env:
CARGO_TERM_COLOR: always
jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-22.04
artifact_name: piri-x86_64-unknown-linux-gnu
strip: true
- target: aarch64-unknown-linux-gnu
os: ubuntu-22.04
artifact_name: piri-aarch64-unknown-linux-gnu
strip: true
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-${{ matrix.target }}-
- name: Install cross-compilation dependencies
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
sudo apt-get install -y libc6-dev-arm64-cross
sudo apt-get install -y binutils-aarch64-linux-gnu
- name: Set up cross-compilation
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
echo "CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
echo "CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++" >> $GITHUB_ENV
- name: Build release binary
run: |
cargo build --release --target ${{ matrix.target }}
- name: Strip binary
if: matrix.strip
run: |
if [ "${{ matrix.target }}" == "aarch64-unknown-linux-gnu" ]; then
aarch64-linux-gnu-strip target/${{ matrix.target }}/release/piri
else
strip target/${{ matrix.target }}/release/piri
fi
- name: Create archive
working-directory: ${{ github.workspace }}
run: |
BINARY_PATH="target/${{ matrix.target }}/release/piri"
ARCHIVE_NAME="${{ matrix.artifact_name }}.tar.gz"
# 检查二进制文件是否存在
if [ ! -f "$BINARY_PATH" ]; then
echo "错误: 二进制文件不存在: $BINARY_PATH"
ls -la "target/${{ matrix.target }}/release/" || true
exit 1
fi
# 创建归档(在项目根目录)
tar czf "$ARCHIVE_NAME" -C "target/${{ matrix.target }}/release" piri
# 验证归档是否创建成功
if [ ! -f "$ARCHIVE_NAME" ]; then
echo "错误: 归档文件创建失败: $ARCHIVE_NAME"
echo "当前工作目录: $(pwd)"
echo "文件列表:"
ls -la || true
exit 1
fi
# 显示归档信息
ls -lh "$ARCHIVE_NAME"
echo "归档文件已创建: $ARCHIVE_NAME"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact_name }}
path: ${{ matrix.artifact_name }}.tar.gz
retention-days: 30
release:
name: Create Release
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get tag name
id: tag
run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Create checksums
run: |
cd artifacts
find . -type f -name "*.tar.gz" | while read file; do
sha256sum "$file" > "$file.sha256"
done
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.tag.outputs.TAG_NAME }}
name: Release ${{ steps.tag.outputs.TAG_NAME }}
files: |
artifacts/**/*.tar.gz
artifacts/**/*.sha256
generate_release_notes: true
draft: false
prerelease: ${{ contains(steps.tag.outputs.TAG_NAME, '-') }}