forked from cloudflare/binary-install
-
Notifications
You must be signed in to change notification settings - Fork 14
205 lines (178 loc) · 6.94 KB
/
release_rust.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
on:
push:
tags:
- "rust_v*" # Run when tag matches rust_v*, i.e. rust_v1.0, rust_v20.15.10
name: Release Rust Binary
env:
RELEASE_BIN: binary-install-example
RELEASE_DIR: artifacts
WORKING_DIR: ./example-binary
GITHUB_REF: "${{ github.ref }}"
WINDOWS_TARGET: x86_64-pc-windows-msvc
MACOS_TARGET: x86_64-apple-darwin
LINUX_TARGET: x86_64-unknown-linux-musl
jobs:
build:
name: Build artifacts
runs-on: ${{ matrix.os }}
strategy:
matrix:
build: [linux, macos, windows]
include:
- build: linux
os: ubuntu-latest
rust: stable
- build: macos
os: macos-latest
rust: stable
- build: windows
os: windows-latest
rust: stable
steps:
- uses: actions/checkout@v1
- name: Cache Cargo registry
uses: actions/cache@v1
if: matrix.rust
with:
path: ~/.cargo/registry
key: ${{ matrix.build }}-stable-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ matrix.build }}-stable-cargo-registry-
- name: Cache Cargo index
uses: actions/cache@v1
if: matrix.rust
with:
path: ~/.cargo/git
key: ${{ matrix.build }}-stable-cargo-index-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ matrix.build }}-stable-cargo-index-
- name: Cache Cargo build
uses: actions/cache@v1
if: matrix.rust
with:
path: target/release
key: ${{ matrix.build }}-stable-release-target-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ matrix.build }}-stable-release-target-
- name: Query version number
id: get_version
shell: bash
run: |
echo "using version tag ${GITHUB_REF:15}"
echo ::set-output name=version::"${GITHUB_REF:15}"
- name: Install Rust
if: matrix.rust
run: |
rustup update ${{ matrix.rust }} --no-self-update
rustup default ${{ matrix.rust }}
- name: Install musl-tools (Linux)
if: matrix.build == 'linux'
run: |
sudo apt-get update -y
sudo apt-get install musl-tools -y
- name: Install p7zip (MacOS)
if: matrix.build == 'macos'
run: brew install p7zip
- name: Build (Linux)
if: matrix.build == 'linux'
working-directory: ${{ env.WORKING_DIR }}
run: |
rustup target add ${{ env.LINUX_TARGET }}
cargo build --release --target ${{ env.LINUX_TARGET }}
- name: Build (MacOS)
if: matrix.build == 'macos'
working-directory: ${{ env.WORKING_DIR }}
run: cargo build --release
- name: Build (Windows)
if: matrix.build == 'windows'
working-directory: ${{ env.WORKING_DIR }}
run: cargo build --release
env:
RUSTFLAGS: -Ctarget-feature=+crt-static
- name: Create artifact directory
working-directory: ${{ env.WORKING_DIR }}
run: |
mkdir ${{ env.RELEASE_DIR }}
mkdir dist
- name: Create tarball (Linux)
if: matrix.build == 'linux'
working-directory: ${{ env.WORKING_DIR }}
run: |
mv ./target/${{ env.LINUX_TARGET }}/release/${{ env.RELEASE_BIN }} ./dist/${{ env.RELEASE_BIN }}
7z a -ttar -so -an ./dist | 7z a -si ./${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ env.LINUX_TARGET }}.tar.gz
- name: Create tarball (Windows)
if: matrix.build == 'windows'
working-directory: ${{ env.WORKING_DIR }}
shell: bash
run: |
mv ./target/release/${{ env.RELEASE_BIN }}.exe ./dist/${{ env.RELEASE_BIN }}.exe
7z a -ttar -so -an ./dist | 7z a -si ./${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ env.WINDOWS_TARGET }}.tar.gz
- name: Create tarball (MacOS)
if: matrix.build == 'macos'
working-directory: ${{ env.WORKING_DIR }}
run: |
mv ./target/release/${{ env.RELEASE_BIN }} ./dist/${{ env.RELEASE_BIN }}
7z a -ttar -so -an ./dist | 7z a -si ./${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ env.MACOS_TARGET }}.tar.gz
- name: Upload Zip
uses: actions/upload-artifact@v1
with:
name: ${{ matrix.build }}
path: ./${{ env.WORKING_DIR }}/${{ env.RELEASE_DIR }}
release:
name: Github Release
needs: build
runs-on: ubuntu-latest
steps:
- name: Query version number
id: get_version
shell: bash
run: |
echo "using version tag ${GITHUB_REF:15}"
echo ::set-output name=version::"${GITHUB_REF:15}"
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: rust_${{ steps.get_version.outputs.VERSION }}
release_name: ${{ steps.get_version.outputs.VERSION }}
- name: Download Linux tarball
uses: actions/download-artifact@v1
with:
name: linux
- name: Download MacOS tarball
uses: actions/download-artifact@v1
with:
name: windows
- name: Download MacOS tarball
uses: actions/download-artifact@v1
with:
name: macos
- name: Release Linux tarball
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./linux/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ env.LINUX_TARGET }}.tar.gz
asset_content_type: application/gzip
asset_name: ${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ env.LINUX_TARGET }}.tar.gz
- name: Release Windows tarball
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./windows/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ env.WINDOWS_TARGET }}.tar.gz
asset_content_type: application/gzip
asset_name: ${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ env.WINDOWS_TARGET }}.tar.gz
- name: Release MacOS tarball
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./macos/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ env.MACOS_TARGET }}.tar.gz
asset_content_type: application/gzip
asset_name: ${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ env.MACOS_TARGET }}.tar.gz