Skip to content

Commit

Permalink
ci: 使用docker进行交叉编译
Browse files Browse the repository at this point in the history
  • Loading branch information
itsusinn committed Jan 19, 2022
1 parent b2b973e commit f67290d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 45 deletions.
6 changes: 0 additions & 6 deletions .github/before-build-linux.sh

This file was deleted.

11 changes: 11 additions & 0 deletions .github/compress.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apt-get install zip
cd packages
for files in $(ls)
do
zip $files.zip $files
rm $files
done
for files in $(ls *.exe.zip)
do
mv $files ${files%%.*}.zip
done
71 changes: 32 additions & 39 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,37 @@ on:

env:
SHORT_NAME: tg
RUST_BACKTRACE: 1

jobs:
build-x86_64:
name: Build binaries for x86_64
compile:
name: Compile
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
file: ./target/x86_64-unknown-linux-musl/release/${{ github.event.repository.name }}
strip: true
before_build: true
before_build_script: ./.github/before-build-linux.sh
build_args: --release --target x86_64-unknown-linux-musl
target: x86_64-unknown-linux-musl
release_name: linux-x86_64

- os: macos-latest
file: ./target/release/${{ github.event.repository.name }}
strip: true
before_build: false
build_args: --release
release_name: mac-x86_64
cross: true

- os: windows-latest
file: ./target/release/${{ github.event.repository.name }}.exe
strip: false
before_build: false
build_args: --release
file: ./target/x86_64-pc-windows-msvc/release/${{ github.event.repository.name }}.exe
target: x86_64-pc-windows-msvc
release_name: windows-x86_64.exe
cross: false

- os: macos-latest
file: ./target/x86_64-apple-darwin/release/${{ github.event.repository.name }}
target: x86_64-apple-darwin
release_name: mac-x86_64
cross: false

- os: ubuntu-latest
file: ./target/aarch64-unknown-linux-gnu/release/${{ github.event.repository.name }}
target: aarch64-unknown-linux-gnu
release_name: linux-aarch64
cross: true
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -50,44 +50,34 @@ jobs:
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-x86_64-release-${{ hashFiles('**/Cargo.toml') }}
key: ${{ matrix.target }}-release-${{ hashFiles('**/Cargo.toml') }}
restore-keys: |
${{ runner.os }}-x86_64-release
${{ matrix.target }}-release
- name: Install Toolchain
uses: actions-rs/toolchain@v1
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
target: ${{ matrix.target }}
override: true

- name: Before Build
if: ${{ matrix.before_build }}
run: bash ${{ matrix.before_build_script }}
shell: bash

- name: Build
run: cargo build ${{ matrix.build_args }}

- name: Compress binaries
uses: svenstaro/upx-action@v2
- uses: actions-rs/cargo@v1
with:
file: ${{ matrix.file }}
strip: ${{ matrix.strip }}
args: --best
use-cross: ${{ matrix.cross }}
command: build
args: --release --target ${{ matrix.target }}

- name: Rename binary
run: mv ${{ matrix.file }} ${{ env.SHORT_NAME }}-${{ matrix.release_name }}

- name: Upload binaries
uses: actions/upload-artifact@v2
with:
name: x86_64
name: compile
path: ${{ env.SHORT_NAME }}-${{ matrix.release_name }}

release:
name: Release
needs: [build-x86_64]
needs: [compile]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -97,9 +87,12 @@ jobs:
- name: Download binaries
uses: actions/download-artifact@v2
with:
name: x86_64
name: compile
path: ./packages

- name: Compress
run: bash ./.github/compress.sh

- name: Github release
uses: "marvinpinto/action-automatic-releases@latest"
with:
Expand Down

0 comments on commit f67290d

Please sign in to comment.