-
Notifications
You must be signed in to change notification settings - Fork 0
228 lines (200 loc) · 7.04 KB
/
release.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# SPDX-FileCopyrightText: 2021 - 2024 Robin Vobruba <[email protected]>
#
# SPDX-License-Identifier: Unlicense
# The create-release job runs purely to initialize the GitHub release itself
# and to output upload_url for the following job.
#
# The build-release job runs only once create-release is finished. It gets the
# release upload URL from create-release job outputs, then builds the release
# executables for each supported platform and attaches them as release assets
# to the previously created release.
#
# The key here is that we create the release only once.
#
# Reference:
# https://eugene-babichenko.github.io/blog/2020/05/09/github-actions-cross-platform-auto-releases/
# This file was copied from the ripgrep project, and then adjusted
name: release
permissions:
# This is required by softprops/action-gh-release to create a release,
# see: <https://github.com/softprops/action-gh-release/issues/236#issuecomment-1150530128>
contents: write
on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+"
jobs:
create-release:
name: create-release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.release.outputs.upload_url }}
our_version: ${{ env.OUR_VERSION }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
if: env.OUR_VERSION == ''
with:
# This makes sure we also get tags,
# so we get the correct version; see bug:
# https://github.com/actions/checkout/issues/701
fetch-depth: 0
submodules: true
- name: "Check out the build scripts"
uses: actions/checkout@v4
with:
repository: 'hoijui/rust-project-scripts'
path: 'run/rp'
submodules: true
- name: "Mark the build scripts as Git-ignored, locally"
run: if ! grep -q -r "^/run/rp/\$" .git/info/exclude; then echo '/run/rp/' >> .git/info/exclude; fi
- name: "Install STOML (BASH TOML parser)"
run: run/rp/install_stoml
- name: Set the environment variables (including OUR_VERSION)
shell: bash
if: env.OUR_VERSION == ''
run: run/rp/env
- name: Create GitHub release
id: release
uses: softprops/action-gh-release@v1
with:
name: ${{ env.OUR_VERSION }}
build-release:
name: build-release
needs: ['create-release']
runs-on: ${{ matrix.os }}
env:
TARGET: ${{ matrix.target }}
OS: ${{ matrix.os }}
# For some builds, we use cross to test on 32-bit and big-endian
# systems.
CARGO: cargo
# When CARGO is set to CROSS, this is set to `--target matrix.target`.
strategy:
matrix:
# build: [linux, linux-arm, macos, win-msvc, win-gnu, win32-msvc]
build: [linux]
include:
- build: linux
os: ubuntu-latest
rust: nightly
target: x86_64-unknown-linux-musl
# - build: linux-arm
# os: ubuntu-18.04
# rust: nightly
# target: arm-unknown-linux-gnueabihf
# - build: macos
# os: macos-latest
# rust: nightly
# target: x86_64-apple-darwin
# - build: win-msvc
# os: windows-2019
# rust: nightly
# target: x86_64-pc-windows-msvc
# - build: win-gnu
# os: windows-2019
# rust: nightly-x86_64-gnu
# target: x86_64-pc-windows-gnu
# - build: win32-msvc
# os: windows-2019
# rust: nightly
# target: i686-pc-windows-msvc
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- name: "Check out the build scripts"
uses: actions/checkout@v4
with:
repository: 'hoijui/rust-project-scripts'
path: 'run/rp'
submodules: true
- name: "Mark the build scripts as Git-ignored, locally"
run: if ! grep -q -r "^/run/rp/\$" .git/info/exclude; then echo '/run/rp/' >> .git/info/exclude; fi
- name: "Install STOML (BASH TOML parser)"
run: |
run/rp/install_stoml
- name: Set the environment variables (including OUR_VERSION)
shell: bash
if: env.OUR_VERSION == ''
run: run/rp/env
- name: Install packages (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
run/rp/install_deps_ubuntu
# - name: Install packages (macOS)
# if: matrix.os == 'macos-latest'
# run: |
# ci/macos-install-packages
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
# - name: Use Cross
# shell: bash
# run: |
# cargo install cross
# echo "CARGO=cross" >> $GITHUB_ENV
# echo "TARGET_FLAG=--target ${{ matrix.target }}" >> $GITHUB_ENV
# echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV
- name: Show command used for Cargo
run: |
echo "cargo command is: ${{ env.CARGO }}"
echo "target flag is: ${{ matrix.target }}"
echo "target dir is: ${{ env.TARGET_DIR }}"
- name: Build and strip release binary
run: run/rp/build --skip-strip
# - name: Strip release binary (linux and macos)
# if: matrix.build == 'linux' || matrix.build == 'macos'
# run: strip "${{ env.BINARY_PATH }}"
# - name: Strip release binary (arm)
# if: matrix.build == 'linux-arm'
# run: |
# docker run --rm -v \
# "$PWD/target:/target:Z" \
# rustembedded/cross:arm-unknown-linux-gnueabihf \
# arm-linux-gnueabihf-strip \
# /target/arm-unknown-linux-gnueabihf/release/${{ env.BINARY }}
- name: Test Release Version (if binary)
shell: bash
run: |
export ENV_FILE="proj_build_envs.txt"
# This writes "BINARY=bla" to ENV_FILE
run/rp/env
source "$ENV_FILE"
BIN="target/release/$BINARY"
if [ -f "$BIN" ]
then
VER_TOOL="$("$BIN" --version --quiet)"
VER_TAG="${GITHUB_REF#refs/*/}"
(
echo "VER_TOOL: $VER_TOOL"
echo "VER_TAG: $VER_TAG"
) | tee /dev/stderr
if ! [ "$VER_TOOL" == "$VER_TAG" ]
then
>&2 echo "ERROR: Version reported by tool ('$VER_TOOL') should equal the release tag ('$VER_TAG')!"
exit 1
fi
if ! [[ $VER_TOOL =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]
then
>&2 echo "ERROR: Version reported by tool ('$VER_TOOL') should be a semver compatible string, i.e. of the form: "'^[0-9]+\.[0-9]+\.[0-9]+$'
exit 2
fi
fi
- name: Build archive
shell: bash
run: |
run/rp/package
- name: Upload release archive
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: ${{ env.TARGET_DIR }}/${{ env.PACKAGE_ARCHIVE }}
asset_name: ${{ env.PACKAGE_ARCHIVE }}
asset_content_type: application/octet-stream