Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Create release
on:
push:
branches:
- 'main'
- 'new-build-ci' # TODO delete before merge
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 'new-build-ci' # TODO delete before merge

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-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 }}"
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
echo "files to tar: "
ls -A ./dist/$dist_name/
tar -czf ./dist/$dist_name.tar.gz -C ./dist/$dist_name/ $(echo ./dist/$dist_name/* | xargs -n1 basename)
fi
done
# Export dist path as step output
echo "dist_dir=$(pwd)/dist" >> $GITHUB_OUTPUT
echo "version_tag=${VERSION}-${HASH}" >> $GITHUB_OUTPUT

- name: Create release
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a bit hardcore to create a release package for every push to main, am I understanding this properly?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LDiazN ping here

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: Print artifact info
run: |
echo "Artifact successfully built ✅"
echo " Version: ooniprobe-rs@${{ steps.version.outputs.version }}-${{ steps.commit.outputs.hash }}"
23 changes: 23 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: test
on:
pull_request:
branches:
- 'main'
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: Run tests
run: cargo test --all-features --verbose

Loading