-
Notifications
You must be signed in to change notification settings - Fork 1
129 lines (114 loc) · 4.26 KB
/
build.yml
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
name: Build
on:
push:
branches:
- master
- main
env:
# The project name specified in your Cargo.toml
PROJECT_NAME: cargotom
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
jobs:
build:
# Set the job to run on the platform specified by the matrix below
runs-on: ${{ matrix.runner }}
# Define the build matrix for cross-compilation
strategy:
matrix:
include:
- name: x86_64-unknown-linux-gnu # linux-amd64
runner: ubuntu-latest
target: x86_64-unknown-linux-gnu
- name: x86_64-pc-windows-msvc # win-amd64
runner: windows-latest
target: x86_64-pc-windows-msvc
- name: x86_64-apple-darwin # macos-amd64
runner: macos-latest
target: x86_64-apple-darwin
- name: aarch64-apple-darwin # macos-arm64
runner: macos-latest
target: aarch64-apple-darwin
# The steps to run for each matrix item
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: "${{ matrix.target }}"
- name: Setup Cache
uses: Swatinem/rust-cache@v2
- name: Install libssl-dev on Linux
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y libssl-dev
- name: Install openssl on macOS
if: runner.os == 'macOS'
run: |
brew install openssl@3
echo 'export OPENSSL_DIR="$(brew --prefix openssl@3)"' >> $GITHUB_ENV
echo 'export PKG_CONFIG_PATH="$(brew --prefix openssl@3)/lib/pkgconfig"' >> $GITHUB_ENV
echo 'export PATH="$(brew --prefix openssl@3)/bin:$PATH"' >> $GITHUB_ENV
- name: Build Binary
run: cargo build --verbose --locked --release --target ${{ matrix.target }}
- name: Move Files
id: move
shell: bash
run: |
BIN_SUFFIX=""
if [[ "${{ matrix.runner }}" == "windows-latest" ]]; then
BIN_SUFFIX=".exe"
fi
# The built binary output location
BIN_OUTPUT="target/${{ matrix.target }}/release/${PROJECT_NAME}${BIN_SUFFIX}"
# Define a better name for the final binary
BIN_RELEASE="${PROJECT_NAME}-${{ matrix.name }}${BIN_SUFFIX}"
BIN_RELEASE_VERSIONED="${PROJECT_NAME}-${{ github.ref_name }}-${{ matrix.name }}${BIN_SUFFIX}"
mkdir ./builds
mv "${BIN_OUTPUT}" "./builds/${BIN_RELEASE}"
echo "file_name=${BIN_RELEASE}" >> $GITHUB_ENV
# Move the built binary where you want it
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.file_name }}
path: ./builds/${{ env.file_name }}
release:
permissions:
contents: write
needs:
- build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get version from Cargo.toml
id: get_version
run: echo "version=$(awk -F'"' '/\[package\]/ {p=1} p && /version/ {print $2; exit}' Cargo.toml)" >> $GITHUB_ENV
- name: Get latest release tag
id: get_latest_release
run: echo "latest_tag=$(curl -s https://api.github.com/repos/${{ github.repository }}/tags | jq -r '.[0].name // "0.0.0"')" >> $GITHUB_ENV
- name: Compare versions
id: compare_versions
run: |
IFS='.' read -ra v1 <<< "${{ env.version }}"
IFS='.' read -ra v2 <<< "${{ env.latest_tag }}"
if [ "${v1[0]}" -gt "${v2[0]}" ] || ([ "${v1[0]}" -eq "${v2[0]}" ] && [ "${v1[1]}" -gt "${v2[1]}" ]) || ([ "${v1[0]}" -eq "${v2[0]}" ] && [ "${v1[1]}" -eq "${v2[1]}" ] && [ "${v1[2]}" -gt "${v2[2]}" ]); then
mkdir ./builds
echo "greater=1" >> $GITHUB_ENV
else
echo "greater=0" >> $GITHUB_ENV
fi
- name: Download Artifacts
if: env.greater == 1
uses: actions/download-artifact@v4
with:
merge-multiple: true
path: "./builds"
- name: Create release
if: env.greater == 1
uses: ncipollo/release-action@v1
with:
tag: ${{ env.version }}
name: ${{ env.version }}
artifacts: "./builds/*"