Skip to content

Commit 5cab60d

Browse files
committed
ci: new ci
Use GitHub Action. Add windows target.
1 parent 0ba82b5 commit 5cab60d

File tree

7 files changed

+292
-112
lines changed

7 files changed

+292
-112
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Publish Crates
2+
3+
on:
4+
release:
5+
types: [created]
6+
workflow_dispatch:
7+
inputs:
8+
crate_name:
9+
description: 'Name of crate to be published'
10+
required: true
11+
type: string
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
crate_publish:
17+
environment: "publish to crates.io"
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v3
22+
- name: Install Rust toolchain
23+
uses: actions-rs/toolchain@v1
24+
with:
25+
toolchain: stable
26+
override: true
27+
profile: minimal
28+
- name: Install build dependencies
29+
run: |
30+
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
31+
echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-11 main" | sudo tee -a /etc/apt/sources.list
32+
sudo apt-get update
33+
sudo apt-get install -y clang-11 cmake
34+
if [ -f mbedtls-sys/vendor/scripts/basic.requirements.txt ]; then
35+
sudo apt-get install -y python3-pip
36+
python3 -m pip install -r mbedtls-sys/vendor/scripts/basic.requirements.txt
37+
fi
38+
- name: Get name of crate to be published
39+
run: |
40+
if [[ -z "${{ inputs.crate_name }}" ]]; then
41+
# Extract the crate name from the GITHUB_REF environment variable
42+
# GITHUB_REF contains the GitHub reference (e.g., refs/tags/mbedtls-sys-auto_v3.5.0) associated with the event
43+
export CRATE_NAME=$(python3 -c "print('$GITHUB_REF'.split('/')[2].rsplit('_v', 1)[0])")
44+
else
45+
export CRATE_NAME="${{ inputs.crate_name }}"
46+
fi
47+
echo "CRATE_NAME=$CRATE_NAME" >> $GITHUB_ENV
48+
- name: Publish crate to crates.io
49+
run: |
50+
echo "Publishing crate: $CRATE_NAME"
51+
cargo publish --locked --token ${CARGO_REGISTRY_TOKEN} --package "$CRATE_NAME"
52+
env:
53+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
54+
RUSTFLAGS: "-A ambiguous_glob_reexports"
55+
RUST_BACKTRACE: "1"
56+
PYTHONDONTWRITEBYTECODE: "1"

.github/workflows/test.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- 'v0.*'
7+
- staging
8+
- trying
9+
pull_request:
10+
branches:
11+
- master
12+
- 'v0.*'
13+
merge_group:
14+
15+
env:
16+
RUST_BACKTRACE: 1
17+
CARGO_TERM_COLOR: always
18+
CARGO_INCREMENTAL: 0
19+
CARGO_NET_RETRY: 10
20+
21+
jobs:
22+
test:
23+
name: Test
24+
strategy:
25+
matrix:
26+
include:
27+
- rust: stable
28+
target: x86_64-unknown-linux-gnu
29+
os: ubuntu-20.04
30+
- rust: stable
31+
target: x86_64-fortanix-unknown-sgx
32+
os: ubuntu-20.04
33+
- rust: stable
34+
target: x86_64-pc-windows-msvc
35+
os: windows-latest
36+
- rust: stable
37+
target: aarch64-unknown-linux-musl
38+
os: ubuntu-20.04
39+
- rust: beta
40+
target: x86_64-unknown-linux-gnu
41+
os: ubuntu-20.04
42+
- rust: nightly
43+
target: x86_64-unknown-linux-gnu
44+
os: ubuntu-20.04
45+
46+
runs-on: ${{ matrix.os }}
47+
48+
steps:
49+
- uses: actions/checkout@v2
50+
51+
- name: Install dependencies
52+
if: matrix.target == 'aarch64-unknown-linux-musl'
53+
run: |
54+
sudo apt-get update
55+
sudo apt-get install -y qemu-user
56+
57+
- name: Cache Dependencies
58+
uses: Swatinem/rust-cache@988c164c3d0e93c4dbab36aaf5bbeb77425b2894
59+
with:
60+
key: ${{ matrix.rust }}
61+
62+
- name: Setup Rust toolchain
63+
uses: actions-rs/toolchain@v1
64+
with:
65+
toolchain: ${{ matrix.rust }}
66+
target: ${{ matrix.target }}
67+
override: true
68+
69+
- name: Run tests
70+
run: |
71+
./ci_tools.sh
72+
./ci.sh
73+
env:
74+
TRAVIS_RUST_VERSION: ${{ matrix.rust }}
75+
TARGET: ${{ matrix.target }}
76+
ZLIB_INSTALLED: ${{ matrix.target == 'x86_64-unknown-linux-gnu' && 'true' || '' }}
77+
AES_NI_SUPPORT: ${{ matrix.target == 'x86_64-unknown-linux-gnu' && 'true' || '' }}
78+
shell: bash
79+
ci-success:
80+
name: ci
81+
if: always()
82+
needs:
83+
- test
84+
runs-on: ubuntu-20.04
85+
steps:
86+
- run: jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}'
87+
- name: Done
88+
run: exit 0

.travis.yml

Lines changed: 0 additions & 47 deletions
This file was deleted.

bors.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
status = [
2-
"continuous-integration/travis-ci/push",
2+
"ci",
33
]
4-
timeout_sec = 36000 # ten hours
4+
timeout_sec = 3600 # 1 hours

ci.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
set -ex
3+
cd "$(dirname "$0")"
4+
5+
repo_root=$(readlink -f $(dirname "${BASH_SOURCE[0]}"))
6+
7+
if [ -z $TRAVIS_RUST_VERSION ]; then
8+
echo "Expected TRAVIS_RUST_VERSION to be set in env"
9+
exit 1
10+
fi
11+
12+
# Test logic start from here
13+
export CFLAGS_x86_64_fortanix_unknown_sgx="-isystem/usr/include/x86_64-linux-gnu -mlvi-hardening -mllvm -x86-experimental-lvi-inline-asm-hardening"
14+
export CC_x86_64_fortanix_unknown_sgx=clang-11
15+
export CC_aarch64_unknown_linux_musl=/tmp/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc
16+
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=/tmp/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc
17+
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUNNER=qemu-aarch64
18+
19+
cd "${repo_root}/mbedtls"
20+
case "$TRAVIS_RUST_VERSION" in
21+
stable|beta|nightly)
22+
# Install the rust toolchain
23+
rustup default $TRAVIS_RUST_VERSION
24+
rustup target add --toolchain $TRAVIS_RUST_VERSION $TARGET
25+
printenv
26+
27+
# The SGX target cannot be run under test like a ELF binary
28+
if [ "$TARGET" != "x86_64-fortanix-unknown-sgx" ]; then
29+
# make sure that explicitly providing the default target works
30+
cargo nextest run --target $TARGET --release
31+
cargo nextest run --features pkcs12 --target $TARGET
32+
cargo nextest run --features pkcs12_rc2 --target $TARGET
33+
cargo nextest run --features dsa --target $TARGET
34+
cargo nextest run --test async_session --features=async-rt --target $TARGET
35+
cargo nextest run --test async_session --features=async-rt,legacy_protocols --target $TARGET
36+
37+
# If zlib is installed, test the zlib feature
38+
if [ -n "$ZLIB_INSTALLED" ]; then
39+
cargo nextest run --features zlib --target $TARGET
40+
cargo nextest run --test async_session --features=async-rt,zlib --target $TARGET
41+
cargo nextest run --test async_session --features=async-rt,zlib,legacy_protocols --target $TARGET
42+
fi
43+
44+
# If AES-NI is supported, test the feature
45+
if [ -n "$AES_NI_SUPPORT" ]; then
46+
cargo nextest run --features force_aesni_support --target $TARGET
47+
fi
48+
49+
# no_std tests only are able to run on x86 platform
50+
if [ "$TARGET" == "x86_64-unknown-linux-gnu" ] || [[ "$TARGET" =~ ^x86_64-pc-windows- ]]; then
51+
cargo nextest run --no-default-features --features no_std_deps,rdrand,time --target $TARGET
52+
cargo nextest run --no-default-features --features no_std_deps --target $TARGET
53+
fi
54+
55+
else
56+
cargo +$TRAVIS_RUST_VERSION test --no-run --target=$TARGET
57+
fi
58+
;;
59+
*)
60+
# Default case: If TRAVIS_RUST_VERSION does not match any of the above
61+
echo "Unknown version $TRAVIS_RUST_VERSION"
62+
exit 1
63+
;;
64+
esac

ci_tools.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
set -ex
3+
cd "$(dirname "$0")"
4+
5+
repo_root=$(readlink -f $(dirname "${BASH_SOURCE[0]}"))
6+
7+
# Setup dependencies and tools
8+
9+
# checks if a file has a specific sha512 hash
10+
check_sha512() {
11+
local hash="$1"
12+
local file="$2"
13+
local platform=$(uname)
14+
case $platform in
15+
Linux)
16+
sha512sum -c <<< "$hash *$file"
17+
;;
18+
Darwin)
19+
shasum -a 512 -c <<< "$hash *$file"
20+
;;
21+
MINGW64_NT-*)
22+
sha512sum -c <<< "$hash *$file"
23+
;;
24+
*)
25+
echo "Unsupported platform '$platfom'"
26+
exit 1
27+
;;
28+
esac
29+
}
30+
31+
# function for downloading pre-built `cargo-nextest` on various platforms
32+
download_cargo_nextest() {
33+
local platform="$1"
34+
local cargo_nextest_hash="$2"
35+
local url="$3"
36+
echo "Check if need to download pre-built $platform 'cargo-nextest'"
37+
if ! check_sha512 "${cargo_nextest_hash}" "${CARGO_HOME:-$HOME/.cargo}/bin/cargo-nextest"; then
38+
case $platform in
39+
MINGW64-*)
40+
curl -LsSf "$url" -o temp.zip && unzip -d "${CARGO_HOME:-$HOME/.cargo}/bin" temp.zip && rm temp.zip
41+
;;
42+
*)
43+
curl -LsSf "$url" | tar zxf - -C "${CARGO_HOME:-$HOME/.cargo}/bin"
44+
;;
45+
esac
46+
check_sha512 "${cargo_nextest_hash}" "${CARGO_HOME:-$HOME/.cargo}/bin/cargo-nextest"
47+
fi
48+
}
49+
50+
aarch64_cross_toolchain_hash=c8ee0e7fd58f5ec6811e3cec5fcdd8fc47cb2b49fb50e9d7717696ddb69c812547b5f389558f62dfbf9db7d6ad808a5a515cc466b8ea3e9ab3daeb20ba1adf33
51+
# save to directory that will be cached
52+
aarch64_cross_toolchain_save_path=${repo_root}/target/aarch64-linux-musl-cross.tgz
53+
mkdir -p ${repo_root}/target
54+
if [ "$TARGET" == "aarch64-unknown-linux-musl" ]; then
55+
if ! check_sha512 ${aarch64_cross_toolchain_hash} ${aarch64_cross_toolchain_save_path}; then
56+
wget https://more.musl.cc/10-20210301/x86_64-linux-musl/aarch64-linux-musl-cross.tgz -O ${aarch64_cross_toolchain_save_path}
57+
check_sha512 ${aarch64_cross_toolchain_hash} ${aarch64_cross_toolchain_save_path}
58+
fi
59+
tar -xf ${aarch64_cross_toolchain_save_path} -C /tmp;
60+
fi
61+
62+
# download pre-built `cargo-nextest`
63+
kernel=$(uname)
64+
architecture=$(uname -m)
65+
case "$kernel-$architecture" in
66+
Linux-x86_64 | Linux-amd64)
67+
download_cargo_nextest "amd64" "d22ce5799f3056807fd0cd8223a290c7153a5f084d5ab931fce755c2cabd33f79c0f75542eb724fe07a7ca083f415ec1f84edc46584b06df43d97a0ff91018da" "https://get.nexte.st/0.9.52/linux"
68+
;;
69+
Linux-arm64)
70+
download_cargo_nextest "arm64" "cff3297c84560de8693e7f887fcf6cf33ab0036e27a9debf2b0a0832094555335f34dc30d0f9d1128ce8472dcb4594a3cf33be2357b19dcc94269b58090cc1a9" "https://get.nexte.st/0.9.52/linux-arm"
71+
;;
72+
Darwin-x86_64)
73+
download_cargo_nextest "Darwin-amd64" "0bb8b77ce019de3d06ee6b7382d830ed67309f187781e0de3866a0635879b494c7db48d55eee7553cfaa0bfca59abd8f8540a6d81ed703f06f9c81514d20073d" "https://get.nexte.st/0.9.52/mac"
74+
;;
75+
MINGW64_NT-*-x86_64)
76+
download_cargo_nextest "MINGW64-amd64" "3ffd504a4ef0b4b5e988457e6c525e62bd030d46b8f303f1c4e83a9a8ba89aef34bb239e23f391d1dddb75bea6ff074499153b2c71b06338a05d74916408de9c" "https://get.nexte.st/0.9.52/windows"
77+
;;
78+
*)
79+
echo "Unknown platform '$kernel-$architecture'"
80+
exit 1
81+
;;
82+
esac

0 commit comments

Comments
 (0)