Update build_and_release.yml #9
This file contains hidden or 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
| name: Build and release test helpers | |
| on: | |
| push: | |
| paths: | |
| - 'ooniprobe-helpers/**' | |
| - '.github/workflows/build_and_release.yml' | |
| branches: | |
| - 'main' | |
| - 'build-ci' # TODO Delete before merging | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v5.0.0 | |
| - name: Install rustup toolchain | |
| uses: dtolnay/rust-toolchain@v1 | |
| with: | |
| toolchain: "stable-x86_64-unknown-linux-gnu" | |
| - name: Cache Cargo registry + build | |
| uses: Swatinem/rust-cache@v2.8.0 | |
| - name: Extract crate version | |
| id: version | |
| run: | | |
| VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Get short commit hash | |
| id: commit | |
| run: | | |
| HASH="${GITHUB_SHA::4}" | |
| echo "hash=${HASH}" >> $GITHUB_OUTPUT | |
| - name: Build release binary | |
| run: | | |
| CRATES=("ooniprobe-helpers" "ooniprobe-services" "ooniprobe" "ooniprobe-core" ) | |
| for bin in "${CRATES[@]}"; do | |
| cargo build --release -p $bin --target-dir ./build/$bin | |
| done | |
| - name: Prepare artifacts | |
| id: prepare | |
| run: | | |
| mkdir -p dist | |
| VERSION="${{ steps.version.outputs.version }}" | |
| HASH="${{ steps.commit.outputs.hash }}" | |
| # All test helpers binaries | |
| PARENT_DIR='./build' | |
| for dir in "$PARENT_DIR"/*/; do | |
| dir_name=$(basename "$dir") | |
| dist_name="${dir_name}@${VERSION}-${HASH}" | |
| mkdir -p "./dist/$dist_name" | |
| # find exec files | |
| exe_files=() | |
| src_dir="$PARENT_DIR/$dir_name/release" | |
| for f in "$src_dir"/*; do [[ -x $f && -f $f ]] && exe_files+=( "$f" ); done | |
| # Copy exe files | |
| cp -r "${exe_files[@]}" "./dist/$dist_name/" | |
| # Copy .so files | |
| if find "$src_dir" -maxdepth 1 -type f -name "*.so" | grep -q .; then | |
| cp -r $src_dir/*.so "./dist/$dist_name" | |
| fi | |
| done | |
| echo "Files in dist: " | |
| pwd | |
| ls dist | |
| # Export dist path as step output | |
| echo "dist_dir=$(pwd)/dist" >> $GITHUB_OUTPUT | |
| - name: Upload artifact | |
| uses: "actions/upload-artifact@v4.6.2" | |
| with: | |
| name: "ooniprobe-rs@${{steps.version.outputs.version}}-${{steps.commit.outputs.hash}}" | |
| path: "${{ steps.prepare.outputs.dist_dir }}" | |
| - name: Print artifact info | |
| run: | | |
| echo "Artifact successfully built ✅" | |
| echo " Version: ooniprobe-rs@${{ steps.version.outputs.version }}-${{ steps.commit.outputs.hash }}" |