Skip to content

Commit 8add3b2

Browse files
author
Philip Sampaio
authored
Simplify release workflow (#29)
This is now using the new GH Action: https://github.com/philss/rustler-precompiled-action And also the a new GH Action to install Rust: https://github.com/dtolnay/rust-toolchain
1 parent 81f8218 commit 8add3b2

File tree

1 file changed

+31
-150
lines changed

1 file changed

+31
-150
lines changed

.github/workflows/release.yml

Lines changed: 31 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -1,191 +1,72 @@
11
name: Build precompiled NIFs
22

3-
env:
4-
NIF_DIRECTORY: "native/ex_tokenizers"
5-
63
on:
74
push:
85
branches:
96
- main
107
paths:
118
# Just run on main branch if "native" path changed. Tags will always run.
129
- "native/**"
10+
# Also run in case there is any changes to this file.
11+
- ".github/workflows/release.yml"
1312
tags:
1413
- "*"
1514

16-
defaults:
17-
run:
18-
# Sets the working dir for "run" scripts.
19-
# Note that this won't change the directory for actions (tasks with "uses").
20-
working-directory: "./native/ex_tokenizers"
21-
2215
jobs:
2316
build_release:
24-
name: NIF ${{ matrix.job.nif }} - ${{ matrix.job.target }} (${{ matrix.job.os }})
17+
name: NIF ${{ matrix.nif }} - ${{ matrix.job.target }} (${{ matrix.job.os }})
2518
runs-on: ${{ matrix.job.os }}
2619
strategy:
2720
fail-fast: false
2821
matrix:
22+
nif: ["2.15", "2.16", "2.14"]
2923
job:
30-
# NIF version 2.16
31-
- {
32-
target: arm-unknown-linux-gnueabihf,
33-
os: ubuntu-20.04,
34-
nif: "2.16",
35-
use-cross: true,
36-
}
37-
- { target: aarch64-unknown-linux-gnu, os: ubuntu-20.04, nif: "2.16", use-cross: true }
38-
- { target: aarch64-unknown-linux-musl, os: ubuntu-20.04, nif: "2.16", use-cross: true }
39-
- { target: aarch64-apple-darwin, os: macos-11, nif: "2.16" }
40-
- { target: riscv64gc-unknown-linux-gnu, os: ubuntu-20.04, nif: "2.16", use-cross: true }
41-
- { target: x86_64-apple-darwin, os: macos-11, nif: "2.16" }
42-
- { target: x86_64-unknown-linux-gnu, os: ubuntu-20.04, nif: "2.16" }
43-
- { target: x86_64-unknown-linux-musl, os: ubuntu-20.04, nif: "2.16", use-cross: true }
44-
- { target: x86_64-pc-windows-gnu, os: windows-2019, nif: "2.16" }
45-
- { target: x86_64-pc-windows-msvc, os: windows-2019, nif: "2.16" }
46-
# NIF version 2.15
47-
- {
48-
target: arm-unknown-linux-gnueabihf,
49-
os: ubuntu-20.04,
50-
nif: "2.15",
51-
use-cross: true,
52-
}
53-
- { target: aarch64-unknown-linux-gnu, os: ubuntu-20.04, nif: "2.15", use-cross: true }
54-
- { target: aarch64-unknown-linux-musl, os: ubuntu-20.04, nif: "2.15", use-cross: true }
55-
- { target: aarch64-apple-darwin, os: macos-11, nif: "2.15" }
56-
- { target: riscv64gc-unknown-linux-gnu, os: ubuntu-20.04, nif: "2.15", use-cross: true }
57-
- { target: x86_64-apple-darwin, os: macos-11, nif: "2.15" }
58-
- { target: x86_64-unknown-linux-gnu, os: ubuntu-20.04, nif: "2.15" }
59-
- { target: x86_64-unknown-linux-musl, os: ubuntu-20.04, nif: "2.15", use-cross: true }
60-
- { target: x86_64-pc-windows-gnu, os: windows-2019, nif: "2.15" }
61-
- { target: x86_64-pc-windows-msvc, os: windows-2019, nif: "2.15" }
62-
# NIF version 2.14
63-
- {
64-
target: arm-unknown-linux-gnueabihf,
65-
os: ubuntu-20.04,
66-
nif: "2.14",
67-
use-cross: true,
68-
}
69-
- { target: aarch64-unknown-linux-gnu, os: ubuntu-20.04, nif: "2.14", use-cross: true }
70-
- { target: aarch64-unknown-linux-musl, os: ubuntu-20.04, nif: "2.14", use-cross: true }
71-
- { target: aarch64-apple-darwin, os: macos-11, nif: "2.14" }
72-
- { target: riscv64gc-unknown-linux-gnu, os: ubuntu-20.04, nif: "2.14", use-cross: true }
73-
- { target: x86_64-apple-darwin, os: macos-11, nif: "2.14" }
74-
- { target: x86_64-unknown-linux-gnu, os: ubuntu-20.04, nif: "2.14" }
75-
- { target: x86_64-unknown-linux-musl, os: ubuntu-20.04, nif: "2.14", use-cross: true }
76-
- { target: x86_64-pc-windows-gnu, os: windows-2019, nif: "2.14" }
77-
- { target: x86_64-pc-windows-msvc, os: windows-2019, nif: "2.14" }
24+
- { target: aarch64-apple-darwin, os: macos-11 }
25+
- { target: aarch64-unknown-linux-gnu, os: ubuntu-20.04, use-cross: true }
26+
- { target: aarch64-unknown-linux-musl, os: ubuntu-20.04, use-cross: true }
27+
- { target: arm-unknown-linux-gnueabihf, os: ubuntu-20.04, use-cross: true }
28+
- { target: riscv64gc-unknown-linux-gnu, os: ubuntu-20.04, use-cross: true }
29+
- { target: x86_64-apple-darwin, os: macos-11 }
30+
- { target: x86_64-pc-windows-gnu, os: windows-2019 }
31+
- { target: x86_64-pc-windows-msvc, os: windows-2019 }
32+
- { target: x86_64-unknown-linux-gnu, os: ubuntu-20.04 }
33+
- { target: x86_64-unknown-linux-musl, os: ubuntu-20.04, use-cross: true }
7834

79-
env:
80-
RUSTLER_NIF_VERSION: ${{ matrix.job.nif }}
8135
steps:
8236
- name: Checkout source code
83-
uses: actions/checkout@v2
37+
uses: actions/checkout@v3
8438

8539
- name: Extract crate information
8640
shell: bash
8741
run: |
88-
echo "PROJECT_NAME=$(sed -n 's/^name = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV
8942
# Get the project version from mix.exs
90-
echo "PROJECT_VERSION=$(sed -n 's/^ @version "\(.*\)"/\1/p' ../../mix.exs | head -n1)" >> $GITHUB_ENV
43+
echo "PROJECT_VERSION=$(sed -n 's/^ @version "\(.*\)"/\1/p' mix.exs | head -n1)" >> $GITHUB_ENV
9144
9245
- name: Install Rust toolchain
93-
uses: actions-rs/toolchain@v1
46+
uses: dtolnay/rust-toolchain@stable
9447
with:
95-
toolchain: stable
9648
target: ${{ matrix.job.target }}
97-
override: true
98-
profile: minimal
99-
100-
- name: Show version information (Rust, cargo, GCC)
101-
shell: bash
102-
run: |
103-
gcc --version || true
104-
rustup -V
105-
rustup toolchain list
106-
rustup default
107-
cargo -V
108-
rustc -V
109-
rustc --print=cfg
11049

111-
- name: Download cross from GitHub releases
112-
uses: giantswarm/[email protected]
113-
if: ${{ matrix.job.use-cross }}
50+
- name: Build the project
51+
id: build-crate
52+
uses: philss/[email protected]
11453
with:
115-
binary: "cross"
116-
version: "v0.2.4"
117-
download_url: "https://github.com/cross-rs/cross/releases/download/${version}/cross-x86_64-unknown-linux-gnu.tar.gz"
118-
tarball_binary_path: "${binary}"
119-
smoke_test: "${binary} --version"
120-
121-
- name: Build
122-
shell: bash
123-
run: |
124-
if [ "${{ matrix.job.use-cross }}" == "true" ]; then
125-
cross build --release --target=${{ matrix.job.target }}
126-
else
127-
cargo build --release --target=${{ matrix.job.target }}
128-
fi
129-
130-
- name: Rename lib to the final name
131-
id: rename
132-
shell: bash
133-
run: |
134-
LIB_PREFIX="lib"
135-
case ${{ matrix.job.target }} in
136-
*-pc-windows-*) LIB_PREFIX="" ;;
137-
esac;
138-
139-
# Figure out suffix of lib
140-
# See: https://doc.rust-lang.org/reference/linkage.html
141-
LIB_SUFFIX=".so"
142-
case ${{ matrix.job.target }} in
143-
*-apple-darwin) LIB_SUFFIX=".dylib" ;;
144-
*-pc-windows-*) LIB_SUFFIX=".dll" ;;
145-
esac;
146-
147-
CICD_INTERMEDIATES_DIR=$(mktemp -d)
148-
149-
# Setup paths
150-
LIB_DIR="${CICD_INTERMEDIATES_DIR}/released-lib"
151-
mkdir -p "${LIB_DIR}"
152-
LIB_NAME="${LIB_PREFIX}${{ env.PROJECT_NAME }}${LIB_SUFFIX}"
153-
LIB_PATH="${LIB_DIR}/${LIB_NAME}"
154-
155-
# Copy the release build lib to the result location
156-
cp "target/${{ matrix.job.target }}/release/${LIB_NAME}" "${LIB_DIR}"
157-
158-
# Final paths
159-
# In the end we use ".so" for MacOS in the final build
160-
# See: https://www.erlang.org/doc/man/erlang.html#load_nif-2
161-
LIB_FINAL_SUFFIX="${LIB_SUFFIX}"
162-
case ${{ matrix.job.target }} in
163-
*-apple-darwin) LIB_FINAL_SUFFIX=".so" ;;
164-
esac;
165-
166-
LIB_FINAL_NAME="${LIB_PREFIX}${PROJECT_NAME}-v${PROJECT_VERSION}-nif-${RUSTLER_NIF_VERSION}-${{ matrix.job.target }}${LIB_FINAL_SUFFIX}"
167-
168-
# Copy lib to final name on this directory
169-
cp "${LIB_PATH}" "${LIB_FINAL_NAME}"
170-
171-
tar -cvzf "${LIB_FINAL_NAME}.tar.gz" "${LIB_FINAL_NAME}"
172-
173-
# Passes the path relative to the root of the project.
174-
LIB_FINAL_PATH="${NIF_DIRECTORY}/${LIB_FINAL_NAME}.tar.gz"
175-
176-
# Let subsequent steps know where to find the lib
177-
echo ::set-output name=LIB_FINAL_PATH::${LIB_FINAL_PATH}
178-
echo ::set-output name=LIB_FINAL_NAME::${LIB_FINAL_NAME}.tar.gz
54+
nif-version: ${{ matrix.nif }}
55+
project-dir: "native/ex_tokenizers"
56+
project-name: ex_tokenizers
57+
project-version: ${{ env.PROJECT_VERSION }}
58+
target: ${{ matrix.job.target }}
59+
use-cross: ${{ matrix.job.use-cross }}
17960

180-
- name: "Artifact upload"
181-
uses: actions/upload-artifact@v2
61+
- name: Artifact upload
62+
uses: actions/upload-artifact@v3
18263
with:
183-
name: ${{ steps.rename.outputs.LIB_FINAL_NAME }}
184-
path: ${{ steps.rename.outputs.LIB_FINAL_PATH }}
64+
name: ${{ steps.build-crate.outputs.file-name }}
65+
path: ${{ steps.build-crate.outputs.file-path }}
18566

18667
- name: Publish archives and packages
18768
uses: softprops/action-gh-release@v1
18869
with:
18970
files: |
190-
${{ steps.rename.outputs.LIB_FINAL_PATH }}
71+
${{ steps.build-crate.outputs.file-path }}
19172
if: startsWith(github.ref, 'refs/tags/')

0 commit comments

Comments
 (0)