Update build_and_release.yml #17
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 | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| permissions: | |
| contents: write # allows creating releases, uploading assets | |
| 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 crate in "${CRATES[@]}"; do | |
| cargo build --release -p $crate --target-dir ./build/$crate | |
| 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 | |
| if (( ${#exe_files[@]} > 0 )); then | |
| cp -r "${exe_files[@]}" "./dist/$dist_name/" | |
| fi | |
| # 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 | |
| # Generate .tar.gz files | |
| if [ -n "$(ls -A ./dist/$dist_name/ 2>/dev/null)" ]; then | |
| tar -czf ./dist/$dist_name.tar.gz -C ./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 | |
| echo "version_tag=${VERSION}-${HASH}" >> $GITHUB_OUTPUT | |
| - name: Create release | |
| run: | | |
| VERSION_TAG="${{steps.prepare.outputs.version_tag}}" | |
| DIST_DIR="${{steps.prepare.outputs.dist_dir}}" | |
| gh release create $VERSION_TAG $DIST_DIR/*.tar.gz -t "Release $VERSION_TAG" -n "Release binaries for ooniprobe-rs" | |
| - 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 }}" |