CI: Use consistent wording when logging into image registries #765
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# originally copied from https://github.com/BurntSushi/ripgrep/blob/master/.github/workflows/ci.yml | |
name: ci | |
on: | |
pull_request: | |
push: | |
branches: | |
- main | |
tags: | |
- v* | |
schedule: | |
- cron: '0 0 * * 0' | |
workflow_dispatch: | |
permissions: | |
contents: write | |
jobs: | |
format: | |
name: Check code formatting | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install Rust | |
uses: dtolnay/rust-toolchain@984d158d699777abbaa79de23de3134e60c187fa # stable branch | |
- name: Run cargo fmt | |
run: | | |
cargo fmt --all -- --check | |
build: | |
name: Build | |
env: | |
CARGO: cargo | |
TARGET_FLAGS: --target ${{ matrix.target }} | |
RUST_BACKTRACE: full | |
timeout-minutes: 30 | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
build: | |
- linux-x86_64 | |
- linux-aarch64 | |
- macos | |
- windows | |
include: | |
- build: linux-x86_64 | |
os: ubuntu-22.04 | |
ruby-version: 3.3.1 | |
run-tests: 'true' | |
target: x86_64-unknown-linux-gnu | |
- build: linux-aarch64 | |
os: ubuntu-22.04 | |
ruby-version: 3.3.1 | |
run-tests: 'false' | |
target: aarch64-unknown-linux-gnu | |
- build: macos | |
os: macos-12 | |
ruby-version: 3.3.1 | |
run-tests: 'true' | |
target: x86_64-apple-darwin | |
- build: windows | |
os: windows-2022 | |
ruby-version: 3.3.0 | |
run-tests: 'true' | |
target: x86_64-pc-windows-msvc | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install Ruby | |
uses: ruby/setup-ruby@v1 | |
with: | |
ruby-version: ${{ matrix.ruby-version }} | |
- name: Install Rust | |
uses: dtolnay/rust-toolchain@984d158d699777abbaa79de23de3134e60c187fa # stable branch | |
- name: Install Rust toolchain target | |
run: | | |
rustup target add ${{ matrix.target }} | |
- name: Install cross-compile toolchain | |
if: matrix.target == 'aarch64-unknown-linux-gnu' | |
run: | | |
sudo apt update -qq && sudo apt install -qq -y gcc-aarch64-linux-gnu | |
- name: Cargo Cache | |
uses: Swatinem/rust-cache@v2.7.3 | |
with: | |
cache-on-failure: "true" | |
key: "${{ matrix.os }}-${{ matrix.target }}" | |
prefix-key: "20230109" | |
- name: Show command used for Cargo | |
run: | | |
echo "cargo command is: ${{ env.CARGO }}" | |
echo "target flag is: ${{ env.TARGET_FLAGS }}" | |
- name: Build rbspy | |
run: ${{ env.CARGO }} build --release --locked --workspace --all-targets ${{ env.TARGET_FLAGS }} | |
- name: Prepare binary for upload | |
if: runner.os != 'windows' | |
run: | | |
cp target/${{ matrix.target }}/release/rbspy rbspy-${{ matrix.target }} | |
- name: Prepare binary for upload | |
if: runner.os == 'windows' | |
run: | | |
copy target/${{ matrix.target }}/release/rbspy.exe rbspy-${{ matrix.target }}.exe | |
- name: Upload Linux and macOS Binaries | |
if: runner.os != 'windows' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: rbspy-${{ matrix.target }} | |
path: rbspy-${{ matrix.target }} | |
- name: Upload Windows Binaries | |
if: runner.os == 'windows' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: rbspy-${{ matrix.target }}.exe | |
path: rbspy-${{ matrix.target }}.exe | |
- name: Run tests | |
timeout-minutes: 5 | |
run: ${{ env.CARGO }} test --release ${{ env.TARGET_FLAGS }} | |
if: runner.os == 'linux' && matrix.run-tests == 'true' | |
- name: Run tests | |
timeout-minutes: 5 | |
run: sudo "PATH=$PATH" ${{ env.CARGO }} test --release ${{ env.TARGET_FLAGS }} | |
if: runner.os == 'macOS' && matrix.run-tests == 'true' | |
- name: Run tests | |
timeout-minutes: 5 | |
run: ${{ env.CARGO }} test --release ${{ env.TARGET_FLAGS }} -- --skip core::ruby_version::tests::test_get_ruby_stack_trace | |
if: runner.os == 'windows' && matrix.run-tests == 'true' | |
- name: Run rbspy with alternative mallocs | |
if: runner.os == 'linux' && matrix.run-tests == 'true' | |
run: | | |
set -e | |
sudo apt install -y libjemalloc2 libtcmalloc-minimal4 | |
target/${{ matrix.target }}/release/rbspy record env LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2 ruby ci/ruby-programs/short_program.rb | |
target/${{ matrix.target }}/release/rbspy record env LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libtcmalloc_minimal.so.4 ruby ci/ruby-programs/short_program.rb | |
build-linux-cross: | |
name: Build | |
runs-on: ubuntu-22.04 | |
strategy: | |
fail-fast: false | |
matrix: | |
target: | |
- i686-musl | |
- armv7-musleabihf | |
- aarch64-musl | |
- x86_64-musl | |
include: | |
- target: i686-musl | |
triple: i686-unknown-linux-musl | |
- target: armv7-musleabihf | |
triple: armv7-unknown-linux-musleabihf | |
- target: aarch64-musl | |
triple: aarch64-unknown-linux-musl | |
- target: x86_64-musl | |
triple: x86_64-unknown-linux-musl | |
container: | |
image: docker://messense/rust-musl-cross:${{ matrix.target }} | |
env: | |
RUSTUP_HOME: /root/.rustup | |
CARGO_HOME: /root/.cargo | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Cargo Cache | |
uses: Swatinem/rust-cache@v2.7.3 | |
with: | |
prefix-key: "20230109" | |
- name: Build | |
run: cargo build --release --locked | |
- name: Prepare binary for upload | |
run: | | |
cp target/*/release/rbspy rbspy-${{ matrix.triple }} | |
- name: Upload Binaries | |
uses: actions/upload-artifact@v4 | |
with: | |
name: rbspy-${{ matrix.triple }} | |
path: rbspy-${{ matrix.triple }} | |
build-freebsd: | |
name: Build (FreeBSD) | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install Rust | |
uses: dtolnay/rust-toolchain@984d158d699777abbaa79de23de3134e60c187fa # stable branch | |
- uses: Swatinem/rust-cache@v2.7.3 | |
- name: Cross-compile rbspy | |
run: | | |
wget -q -O cross https://github.com/acj/freebsd-firecracker/releases/download/v0.0.10/cross | |
chmod +x cross | |
mv cross /usr/local/bin/cross | |
cross build --release --target x86_64-unknown-freebsd | |
cp target/x86_64-unknown-freebsd/release/rbspy rbspy | |
rm -rf target/x86_64-unknown-freebsd/release/deps/rbspy-* | |
cross test --release --no-run --target x86_64-unknown-freebsd | |
- name: Launch Firecracker VM | |
uses: acj/freebsd-firecracker-action@v0.1.1 | |
with: | |
verbose: false | |
pre-run: | | |
rm -rf .cargo | |
ln -s $HOME/.cargo .cargo | |
include_path="$(mktemp)" | |
cat <<EOF > $include_path | |
rbspy | |
target | |
target/x86_64-unknown-freebsd | |
target/x86_64-unknown-freebsd/release | |
target/x86_64-unknown-freebsd/release/rbspy | |
target/x86_64-unknown-freebsd/release/deps | |
target/x86_64-unknown-freebsd/release/deps/rbspy-* | |
ci | |
ci/ruby-programs | |
ci/ruby-programs/infinite.rb | |
ci/ruby-programs/ruby_forks.rb | |
.cargo | |
.cargo/registry | |
.cargo/registry/src | |
.cargo/registry/src/index.* | |
.cargo/registry/src/index.*/rbspy-testdata-* | |
.cargo/registry/src/index.*/rbspy-testdata-*/data | |
.cargo/registry/src/index.*/rbspy-testdata-*/data/ruby-coredump-*.gz | |
EOF | |
rsync -r -e "ssh" \ | |
--relative \ | |
--copy-links \ | |
--include-from "$include_path" \ | |
--exclude "*" \ | |
. firecracker: | |
rm -f "$exclude_path" | |
run-in-vm: | | |
mkdir -p /home/runner | |
ln -s $(pwd)/.cargo /home/runner/.cargo | |
pkg install -y ruby | |
./rbspy --version | |
skip_tests="--skip core::ruby_spy::tests --skip sampler::tests" | |
failed=0 | |
for testbin in $(find target/x86_64-unknown-freebsd/release/deps -type f -perm -u+x ! -name "*.d" -print); do | |
if ! $testbin $skip_tests; then | |
failed=1 | |
fi | |
done | |
if [ $failed -ne 0 ]; then | |
exit 1 | |
fi | |
post-run: "" | |
- name: Prepare binary for upload | |
run: | | |
mv rbspy rbspy-x86_64-unknown-freebsd | |
- name: Upload Binaries | |
uses: actions/upload-artifact@v4 | |
with: | |
name: rbspy-x86_64-unknown-freebsd | |
path: rbspy-x86_64-unknown-freebsd | |
release: | |
name: Create draft release | |
runs-on: ubuntu-22.04 | |
if: "startsWith(github.ref, 'refs/tags/')" | |
needs: [build, build-freebsd, build-linux-cross] | |
steps: | |
- uses: actions/download-artifact@v4 | |
with: | |
path: raw-artifacts | |
- name: Prepare binary archives | |
run: | | |
set -euo pipefail | |
mkdir staging | |
mv $(find raw-artifacts -type f | xargs) staging | |
mkdir archives | |
cd staging | |
for target in $(ls); do | |
if echo "$target" | grep -q ".exe" 2>/dev/null; then | |
echo "Found Windows binary for target $target" | |
zip -j ../archives/$target.zip $target | |
else | |
echo "Found unix binary for target $target" | |
chmod a+x $target | |
tar czf ../archives/$target.tar.gz $target | |
fi | |
done | |
- uses: marvinpinto/action-automatic-releases@919008cf3f741b179569b7a6fb4d8860689ab7f0 # v1.1.1 | |
with: | |
repo_token: "${{ secrets.GITHUB_TOKEN }}" | |
draft: true | |
prerelease: false | |
files: | | |
archives/* |