Last active 1 month ago

GitHub Action 构建二进制文件并发布

jetsung revised this gist 4 months ago. Go to revision

1 file changed, 3 insertions, 3 deletions

build-rust-matrix.yml

@@ -57,7 +57,7 @@ jobs:
57 57 - name: Create release tarball
58 58 run: |
59 59 mkdir -p ${{ env.RELEASE_DIR }}
60 - tar -cJf "${{ env.RELEASE_DIR }}/ai-translator-${{ github.event.release.tag_name || github.run_id }}-${{ matrix.arch }}-unknown-linux-musl.tar.xz" -C target/${{ matrix.target }}/release aitr
60 + tar -cJf "${{ env.RELEASE_DIR }}/ai-translator-${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || github.run_id }}-${{ matrix.arch }}-unknown-linux-musl.tar.xz" -C target/${{ matrix.target }}/release aitr
61 61 - name: Upload release assets
62 62 if: startsWith(github.ref, 'refs/tags/')
63 63 uses: softprops/action-gh-release@v2
@@ -99,7 +99,7 @@ jobs:
99 99 - name: Create release tarball
100 100 run: |
101 101 mkdir -p ${{ env.RELEASE_DIR }}
102 - tar -cJf "${{ env.RELEASE_DIR }}/ai-translator-${{ github.event.release.tag_name || github.run_id }}-${{ matrix.arch }}-apple-darwin.tar.xz" -C target/${{ matrix.target }}/release aitr
102 + tar -cJf "${{ env.RELEASE_DIR }}/ai-translator-${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || github.run_id }}-${{ matrix.arch }}-apple-darwin.tar.xz" -C target/${{ matrix.target }}/release aitr
103 103 - name: Upload release assets
104 104 if: ${{ startsWith(github.ref, 'refs/tags/') }}
105 105 uses: softprops/action-gh-release@v2
@@ -146,7 +146,7 @@ jobs:
146 146 shell: bash
147 147 run: |
148 148 mkdir -p "${{ env.RELEASE_DIR }}"
149 - zip -j "${{ env.RELEASE_DIR }}/ai-translator-${{ github.event.release.tag_name || github.run_id }}-${{ matrix.arch }}-pc-windows-msvc.zip" target/${{ matrix.target }}/release/aitr.exe
149 + zip -j "${{ env.RELEASE_DIR }}/ai-translator-${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || github.run_id }}-${{ matrix.arch }}-pc-windows-msvc.zip" target/${{ matrix.target }}/release/aitr.exe
150 150 - name: Upload release assets
151 151 if: ${{ startsWith(github.ref, 'refs/tags/') }}
152 152 uses: softprops/action-gh-release@v2

jetsung revised this gist 4 months ago. Go to revision

1 file changed, 163 insertions

build-rust-matrix.yml(file created)

@@ -0,0 +1,163 @@
1 + name: Build CLI on Release
2 +
3 + on:
4 + push:
5 + tags:
6 + - 'v*'
7 + # release:
8 + # types:
9 + # - created
10 + workflow_dispatch:
11 +
12 + permissions:
13 + contents: write
14 +
15 + env:
16 + CARGO_TERM_COLOR: always
17 + RELEASE_DIR: dist
18 +
19 + jobs:
20 + build-linux:
21 + runs-on: ubuntu-24.04
22 + strategy:
23 + matrix:
24 + include:
25 + - arch: x86_64
26 + target: x86_64-unknown-linux-musl
27 + - arch: aarch64
28 + target: aarch64-unknown-linux-musl
29 + - arch: loongarch64
30 + target: loongarch64-unknown-linux-musl
31 + steps:
32 + - uses: actions/checkout@v6
33 + with:
34 + submodules: true
35 + - name: Update Rust
36 + run: |
37 + rustup update
38 + rustc --version
39 + - uses: jetsung/setup-zig@v1
40 + with:
41 + version: "0.15.2"
42 + - name: Check zig version
43 + run: |
44 + zig version
45 + - name: Install target
46 + run: rustup target add ${{ matrix.target }}
47 + - name: Install dependencies
48 + run: |
49 + sudo apt update
50 + sudo apt install -y musl-tools musl-dev
51 + - name: Install cargo-zigbuild
52 + run: cargo install cargo-zigbuild
53 + - name: Update submodules
54 + run: git submodule update --init --recursive
55 + - name: Build cli
56 + run: cargo zigbuild -p ai-translator --release --target ${{ matrix.target }}
57 + - name: Create release tarball
58 + run: |
59 + mkdir -p ${{ env.RELEASE_DIR }}
60 + tar -cJf "${{ env.RELEASE_DIR }}/ai-translator-${{ github.event.release.tag_name || github.run_id }}-${{ matrix.arch }}-unknown-linux-musl.tar.xz" -C target/${{ matrix.target }}/release aitr
61 + - name: Upload release assets
62 + if: startsWith(github.ref, 'refs/tags/')
63 + uses: softprops/action-gh-release@v2
64 + with:
65 + tag_name: ${{ github.event.release.tag_name }}
66 + files: ${{ env.RELEASE_DIR }}/*.tar.xz
67 + env:
68 + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
69 + - name: Upload artifacts
70 + if: ${{ !startsWith(github.ref, 'refs/tags/') }}
71 + uses: actions/upload-artifact@v6
72 + with:
73 + name: ai-translator-Linux-${{ matrix.arch }}
74 + path: ${{ env.RELEASE_DIR }}/*
75 +
76 + build-macos:
77 + runs-on: macos-15
78 + strategy:
79 + matrix:
80 + include:
81 + - arch: x86_64
82 + target: x86_64-apple-darwin
83 + - arch: aarch64
84 + target: aarch64-apple-darwin
85 + steps:
86 + - uses: actions/checkout@v6
87 + with:
88 + submodules: true
89 + - name: Update Rust
90 + run: |
91 + rustup update
92 + rustc --version
93 + - name: Install target
94 + run: rustup target add ${{ matrix.target }}
95 + - name: Update submodules
96 + run: git submodule update --init --recursive
97 + - name: Build cli
98 + run: cargo build -p ai-translator --release --target ${{ matrix.target }}
99 + - name: Create release tarball
100 + run: |
101 + mkdir -p ${{ env.RELEASE_DIR }}
102 + tar -cJf "${{ env.RELEASE_DIR }}/ai-translator-${{ github.event.release.tag_name || github.run_id }}-${{ matrix.arch }}-apple-darwin.tar.xz" -C target/${{ matrix.target }}/release aitr
103 + - name: Upload release assets
104 + if: ${{ startsWith(github.ref, 'refs/tags/') }}
105 + uses: softprops/action-gh-release@v2
106 + with:
107 + tag_name: ${{ github.event.release.tag_name }}
108 + files: ${{ env.RELEASE_DIR }}/*.tar.xz
109 + env:
110 + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
111 + - name: Upload artifacts
112 + if: ${{ !startsWith(github.ref, 'refs/tags/') }}
113 + uses: actions/upload-artifact@v6
114 + with:
115 + name: ai-translator-macOS-${{ matrix.arch }}
116 + path: ${{ env.RELEASE_DIR }}/*
117 +
118 + build-windows:
119 + runs-on: windows-2025
120 + strategy:
121 + matrix:
122 + include:
123 + - arch: x86_64
124 + target: x86_64-pc-windows-msvc
125 + - arch: aarch64
126 + target: aarch64-pc-windows-msvc
127 + steps:
128 + - uses: actions/checkout@v6
129 + with:
130 + submodules: true
131 + - name: Update Rust
132 + run: |
133 + rustup update
134 + rustc --version
135 + - name: Install zip utility
136 + run: choco install zip -y
137 + shell: powershell
138 + - name: Install target
139 + shell: bash
140 + run: rustup target add ${{ matrix.target }}
141 + - name: Update submodules
142 + run: git submodule update --init --recursive
143 + - name: Build cli
144 + run: cargo build -p ai-translator --release --target ${{ matrix.target }}
145 + - name: Create release zip file
146 + shell: bash
147 + run: |
148 + mkdir -p "${{ env.RELEASE_DIR }}"
149 + zip -j "${{ env.RELEASE_DIR }}/ai-translator-${{ github.event.release.tag_name || github.run_id }}-${{ matrix.arch }}-pc-windows-msvc.zip" target/${{ matrix.target }}/release/aitr.exe
150 + - name: Upload release assets
151 + if: ${{ startsWith(github.ref, 'refs/tags/') }}
152 + uses: softprops/action-gh-release@v2
153 + with:
154 + tag_name: ${{ github.event.release.tag_name }}
155 + files: ${{ env.RELEASE_DIR }}/*.zip
156 + env:
157 + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
158 + - name: Upload artifacts
159 + if: ${{ !startsWith(github.ref, 'refs/tags/') }}
160 + uses: actions/upload-artifact@v6
161 + with:
162 + name: ai-translator-Windows-${{ matrix.arch }}
163 + path: ${{ env.RELEASE_DIR }}/*

jetsung revised this gist 4 months ago. Go to revision

1 file changed, 162 insertions

build-rust.yml(file created)

@@ -0,0 +1,162 @@
1 + name: Build CLI on Release
2 +
3 + on:
4 + push:
5 + tags:
6 + - 'ai-translator-v*'
7 + # release:
8 + # types:
9 + # - created
10 + workflow_dispatch:
11 +
12 + permissions:
13 + contents: write
14 +
15 + env:
16 + CARGO_TERM_COLOR: always
17 + RELEASE_DIR: dist
18 +
19 + jobs:
20 + build-linux:
21 + runs-on: ubuntu-24.04
22 + steps:
23 + - uses: actions/checkout@v6
24 + with:
25 + submodules: true
26 + - name: Update Rust
27 + run: |
28 + rustup update
29 + rustc --version
30 + - uses: jetsung/setup-zig@v1
31 + with:
32 + version: "0.15.2"
33 + - name: Check zig version
34 + run: |
35 + zig version
36 + - name: Install target for Linux
37 + run: |
38 + for arch in x86_64 aarch64 loongarch64; do
39 + rustup target add $arch-unknown-linux-musl
40 + done
41 + - name: Install dependencies
42 + run: |
43 + sudo apt update
44 + sudo apt install -y musl-tools musl-dev
45 + - name: Install cargo-zigbuild
46 + run: cargo install cargo-zigbuild
47 + - name: Update submodules
48 + run: git submodule update --init --recursive
49 + - name: Build cli for Linux
50 + run: |
51 + cargo zigbuild -p ai-translator --release --target x86_64-unknown-linux-musl
52 + cargo zigbuild -p ai-translator --release --target aarch64-unknown-linux-musl
53 + cargo zigbuild -p ai-translator --release --target loongarch64-unknown-linux-musl
54 + - name: Create release tarballs
55 + run: |
56 + mkdir ${{ env.RELEASE_DIR }}
57 + for arch in x86_64 aarch64 loongarch64; do
58 + tar -cJf "${{ env.RELEASE_DIR }}/ai-translator-${{ github.event.release.tag_name }}-$arch-unknown-linux-musl.tar.xz" -C target/$arch-unknown-linux-musl/release aitr
59 + done
60 + - name: Upload release assets
61 + if: startsWith(github.ref, 'refs/tags/')
62 + uses: softprops/action-gh-release@v2
63 + with:
64 + tag_name: ${{ github.event.release.tag_name }}
65 + files: ${{ env.RELEASE_DIR }}/*.tar.xz
66 + env:
67 + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68 + - name: Upload artifacts
69 + if: ${{ !startsWith(github.ref, 'refs/tags/') }}
70 + uses: actions/upload-artifact@v4
71 + with:
72 + name: ai-translator-Linux
73 + path: ${{ env.RELEASE_DIR }}/*
74 +
75 + build-macos:
76 + runs-on: macos-15
77 + steps:
78 + - uses: actions/checkout@v6
79 + with:
80 + submodules: true
81 + - name: Update Rust
82 + run: |
83 + rustup update
84 + rustc --version
85 + - name: Install target for MacOS
86 + run: |
87 + for arch in x86_64 aarch64; do
88 + rustup target add $arch-apple-darwin
89 + done
90 + - name: Update submodules
91 + run: git submodule update --init --recursive
92 + - name: Build server and cli for MacOS
93 + run: |
94 + cargo build -p ai-translator --release --target x86_64-apple-darwin
95 + cargo build -p ai-translator --release --target aarch64-apple-darwin
96 + - name: Create release tarballs
97 + run: |
98 + mkdir ${{ env.RELEASE_DIR }}
99 + for arch in x86_64 aarch64; do
100 + tar -cJf "${{ env.RELEASE_DIR }}/ai-translator-${{ github.event.release.tag_name }}-$arch-apple-darwin.tar.xz" -C target/$arch-apple-darwin/release aitr
101 + done
102 + - name: Upload release assets
103 + if: ${{ startsWith(github.ref, 'refs/tags/') }}
104 + uses: softprops/action-gh-release@v2
105 + with:
106 + tag_name: ${{ github.event.release.tag_name }}
107 + files: ${{ env.RELEASE_DIR }}/*.tar.xz
108 + env:
109 + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
110 + - name: Upload artifacts
111 + if: ${{ !startsWith(github.ref, 'refs/tags/') }}
112 + uses: actions/upload-artifact@v4
113 + with:
114 + name: ai-translator-macOS
115 + path: ${{ env.RELEASE_DIR }}/*
116 +
117 + build-windows:
118 + runs-on: windows-2025
119 + steps:
120 + - uses: actions/checkout@v6
121 + with:
122 + submodules: true
123 + - name: Update Rust
124 + run: |
125 + rustup update
126 + rustc --version
127 + - name: Install zip utility
128 + run: choco install zip -y
129 + shell: powershell
130 + - name: Install target for Windows
131 + shell: bash
132 + run: |
133 + for arch in x86_64 aarch64; do
134 + rustup target add $arch-pc-windows-msvc
135 + done
136 + - name: Update submodules
137 + run: git submodule update --init --recursive
138 + - name: Build server and cli for Windows
139 + run: |
140 + cargo build -p ai-translator --release --target x86_64-pc-windows-msvc
141 + cargo build -p ai-translator --release --target aarch64-pc-windows-msvc
142 + - name: Create release zip files
143 + shell: bash
144 + run: |
145 + mkdir "${{ env.RELEASE_DIR }}"
146 + for arch in x86_64 aarch64; do
147 + zip -j "${{ env.RELEASE_DIR }}/ai-translator-${{ github.event.release.tag_name }}-$arch-pc-windows-msvc.zip" target/$arch-pc-windows-msvc/release/aitr.exe
148 + done
149 + - name: Upload release assets
150 + if: ${{ startsWith(github.ref, 'refs/tags/') }}
151 + uses: softprops/action-gh-release@v2
152 + with:
153 + tag_name: ${{ github.event.release.tag_name }}
154 + files: ${{ env.RELEASE_DIR }}/*.zip
155 + env:
156 + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
157 + - name: Upload artifacts
158 + if: ${{ !startsWith(github.ref, 'refs/tags/') }}
159 + uses: actions/upload-artifact@v4
160 + with:
161 + name: ai-translator-Windows
162 + path: ${{ env.RELEASE_DIR }}/*
Newer Older