Skip to content

Commit 60b5523

Browse files
committed
[cargo-nextest] attempt to publish binaries
1 parent 04a0ac0 commit 60b5523

File tree

2 files changed

+163
-0
lines changed

2 files changed

+163
-0
lines changed

.github/workflows/release.yml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,129 @@ jobs:
7171
branch: main
7272
env:
7373
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74+
- name: Get version number
75+
id: get-version-number
76+
# TODO: replace this step with https://github.com/taiki-e/create-gh-release-action/pull/12 once that lands
77+
run: |
78+
TAG_NAME=${{ github.ref_name }}
79+
VERSION=${TAG_NAME#"cargo-nextest-"}
80+
echo "The version number is $VERSION"
81+
echo "::set-output name=version::$VERSION"
82+
outputs:
83+
version: ${{ steps.get-version-number.outputs.version }}
84+
85+
build-cargo-nextest-binaries:
86+
name: Build cargo-nextest binaries for ${{ matrix.target }}
87+
if: github.repository_owner == 'nextest-rs' && startsWith(github.ref_name, 'cargo-nextest-')
88+
needs:
89+
- cargo-nextest-release
90+
strategy:
91+
matrix:
92+
include:
93+
- target: x86_64-unknown-linux-gnu
94+
os: ubuntu-18.04
95+
- target: x86_64-pc-windows-msvc
96+
os: windows-latest
97+
runs-on: ${{ matrix.os }}
98+
steps:
99+
- uses: actions/checkout@v2
100+
- name: Install Rust
101+
uses: actions-rs/toolchain@v1
102+
with:
103+
toolchain: stable
104+
profile: minimal
105+
override: true
106+
- uses: taiki-e/upload-rust-binary-action@v1
107+
with:
108+
bin: cargo-nextest
109+
# The tag name contains the binary name so just use that.
110+
archive: $tag-$target
111+
target: ${{ matrix.target }}
112+
tar: all
113+
zip: windows
114+
env:
115+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
116+
CARGO_PROFILE_RELEASE_LTO: true
117+
- name: Set archive output variable
118+
id: archive-output
119+
shell: bash
120+
run: |
121+
if [[ ${{ matrix.target }} == windows ]]; then
122+
echo "::set-output name=${{ matrix.target }}::${{ github.ref_name }}-${{ matrix.target }}".zip
123+
else
124+
echo "::set-output name=${{ matrix.target }}::${{ github.ref_name }}-${{ matrix.target }}".tar.gz
125+
fi
126+
outputs:
127+
linux-tar: ${{ steps.archive-output.outputs.x86_64-unknown-linux-gnu }}
128+
windows-zip: ${{ steps.archive-output.outputs.x86_64-pc-windows-msvc }}
129+
130+
build-cargo-nextest-binaries-mac:
131+
name: Build universal cargo-nextest binary for Mac
132+
if: github.repository_owner == 'nextest-rs'
133+
needs:
134+
- cargo-nextest-release
135+
runs-on: macos-latest
136+
steps:
137+
- uses: actions/checkout@v2
138+
- name: Install Rust
139+
uses: actions-rs/toolchain@v1
140+
with:
141+
toolchain: stable
142+
profile: minimal
143+
override: true
144+
- name: Build release for Mac
145+
id: build-release
146+
run: |
147+
./scripts/release-mac-build.sh cargo-nextest "${{ github.ref_name }}"
148+
- uses: svenstaro/upload-release-action@2.2.1
149+
with:
150+
repo_token: ${{ secrets.GITHUB_TOKEN }}
151+
file: ${{ steps.build-release.outputs.archive-name }}
152+
tag: ${{ github.ref }}
153+
outputs:
154+
mac-tar: ${{ steps.build-release.outputs.archive-name }}
155+
156+
update-release-meta:
157+
name: Update release-meta branch
158+
if: github.repository_owner == 'nextest-rs'
159+
needs:
160+
- cargo-nextest-release
161+
- build-cargo-nextest-binaries
162+
- build-cargo-nextest-binaries-mac
163+
runs-on: ubuntu-latest
164+
steps:
165+
- uses: actions/checkout@v2
166+
- name: Download mukti
167+
run: |
168+
mkdir -p ~/bin
169+
curl -LsSf "https://github.com/sunshowers/mukti/releases/download/mukti-bin-0.1.0/mukti-bin-0.1.0-x86_64-unknown-linux-gnu.tar.gz" \
170+
| tar xzf - -C ~/bin
171+
- name: Add release metadata
172+
run: |
173+
~/bin/mukti-bin add-release --version ${{ needs.cargo-nextest-release.outputs.version }} \
174+
--url-prefix "https://github.com/nextest-rs/nextest/releases/download/${{ github.ref_name }}" \
175+
--archive x86_64-unknown-linux-gnu=${{ needs.build-cargo-nextest-binaries.outputs.linux-tar }} \
176+
--archive x86_64-pc-windows-msvc=${{ needs.build-cargo-nextest-binaries.outputs.windows-zip }} \
177+
--archive universal-apple-darwin=${{ needs.build-cargo-nextest-binaries-mac.outputs.mac-tar }}
178+
- name: Generate netlify redirects
179+
run: |
180+
mkdir out-dir
181+
~/bin/mukti-bin generate-netlify out-dir --alias linux=x86_64-unknown-linux-gnu \
182+
--alias windows=x86_64-pc-windows-msvc --alias mac=universal-apple-darwin
183+
- name: Update releases.json on main branch
184+
uses: EndBug/add-and-commit@v8
185+
with:
186+
add: .releases.json
187+
message: "Update release metadata for ${{ github.ref_name }}"
188+
default_author: github_actions
189+
# Need to specify pull and push arguments because we're checked out to a tag here (i.e. not on a branch)
190+
pull: '--rebase --autostash origin main'
191+
push: 'origin HEAD:main'
192+
- name: Copy releases.json to output dir
193+
run: |
194+
cp .releases.json out-dir/releases.json
195+
- name: Deploy release metadata
196+
uses: JamesIves/github-pages-deploy-action@v4
197+
with:
198+
branch: release-meta
199+
folder: out-dir

scripts/release-mac-build.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
# Build a universal release for publishing on Mac. Only works on Macs.
4+
# Assumes that TAG_NAME is in the forma "$BINARY_NAME-version",
5+
# e.g. sunshowers-test-binary-release-0.1.0.
6+
# Outputs an archive under the output parameter "archive-name"
7+
8+
set -e -x -o pipefail
9+
10+
BINARY_NAME="$1"
11+
TAG_NAME="$2"
12+
13+
VERSION=${TAG_NAME#"$BINARY_NAME-"}
14+
15+
export CARGO_PROFILE_RELEASE_LTO=true
16+
17+
targets="aarch64-apple-darwin x86_64-apple-darwin"
18+
for target in $targets; do
19+
rustup target add $target
20+
# From: https://stackoverflow.com/a/66875783/473672
21+
SDKROOT=$(xcrun --show-sdk-path) \
22+
MACOSX_DEPLOYMENT_TARGET=$(xcrun --show-sdk-platform-version) \
23+
cargo build --release "--target=$target"
24+
done
25+
26+
# From: https://developer.apple.com/documentation/apple-silicon/building-a-universal-macos-binary#Update-the-Architecture-List-of-Custom-Makefiles
27+
lipo -create \
28+
-output "target/$BINARY_NAME" \
29+
"target/aarch64-apple-darwin/release/$BINARY_NAME" \
30+
"target/x86_64-apple-darwin/release/$BINARY_NAME"
31+
32+
ARCHIVE_NAME="$BINARY_NAME-$VERSION-universal-apple-darwin.tar.gz"
33+
# Use gtar on Mac because Mac's tar is broken: https://github.com/actions/cache/issues/403
34+
pushd target
35+
gtar acf "../$ARCHIVE_NAME" "$BINARY_NAME"
36+
37+
echo "::set-output name=archive-name::$ARCHIVE_NAME"

0 commit comments

Comments
 (0)