CI fixes #7
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
# Release-plz workflow from: | |
# https://release-plz.ieni.dev/docs/github/quickstart | |
# https://release-plz.ieni.dev/docs/github/output | |
name: Test, Build, and Release | |
permissions: | |
pull-requests: write | |
contents: write | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
mac-test: | |
runs-on: macos-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install Rust toolchain | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
components: rustfmt, clippy | |
- name: Run cargo check | |
uses: actions-rs/cargo@v1 | |
with: | |
command: check | |
- name: Install LLVM tools | |
run: brew install llvm | |
- name: Install cargo-llvm-cov | |
run: cargo install cargo-llvm-cov | |
- name: Run tests with coverage | |
run: cargo llvm-cov --workspace --lcov --output-path ./target/lcov.info | |
- name: Upload coverage reports to Codecov | |
uses: codecov/codecov-action@v4.4.1 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
- name: Install cargo bundle | |
run: cargo install cargo-bundle | |
- name: Bundle the application | |
run: cargo bundle --release | |
- name: Tarball the Mac App | |
run: tar -czvf target/release/bundle/osx/Weave.tar.gz target/release/bundle/osx/Weave.app | |
- name: Upload Mac App to GitHub | |
uses: actions/upload-artifact@v4 | |
with: | |
name: mac-app | |
path: target/release/bundle/osx/Weave.tar.gz | |
if-no-files-found: error | |
compression-level: 9 | |
overwrite: true | |
linux-test: | |
# It builds on my machine which is mantic until i `do-release-upgrade` | |
# so let's try mantic. | |
runs-on: ubuntu-mantic | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install Rust toolchain | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
components: rustfmt, clippy | |
- name: Install CUDA | |
run: sudo apt-get install nvidia-cuda-toolkit nvidia-cudnn nvidia-cuda-dev | |
- name: Install LLVM tools | |
run: sudo apt-get install llvm | |
- name: Install cargo-llvm-cov | |
run: cargo install cargo-llvm-cov | |
- name: Run cargo check | |
uses: actions-rs/cargo@v1 | |
with: | |
command: check | |
- name: Run tests with coverage | |
run: cargo llvm-cov --workspace --lcov --output-path ./target/lcov.info | |
- name: Upload coverage reports to Codecov | |
uses: codecov/codecov-action@v4.4.1 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
- name: Install cargo bundle | |
run: cargo install cargo-bundle | |
- name: Bundle the application | |
run: cargo bundle --release | |
- name: Tarball the Linux binary | |
run: tar -czvf target/release/bundle/linux/Weave.tar.gz target/release/bundle/linux/weave | |
- name: Upload Linux binary to GitHub | |
uses: actions/upload-artifact@v4 | |
with: | |
name: linux-binary | |
# This will be a problem since the path includes the version and we | |
# don't know that until release runs. So the release build will have | |
# to happen after `release-plz` runs. But for now let's test this. | |
path: target/release/bundle/deb/weave_0.0.0_amd64.deb | |
if-no-files-found: error | |
compression-level: 9 | |
overwrite: true | |
windows-test: | |
runs-on: windows-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install Rust toolchain | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
components: rustfmt, clippy | |
- name: Install LLVM and Clang | |
uses: KyleMayes/install-llvm-action@v2 | |
with: | |
version: "18" | |
- name: Installe Cuda Toolkit | |
uses: Jimver/cuda-toolkit@v0.2.15 | |
- name: Run cargo check | |
uses: actions-rs/cargo@v1 | |
with: | |
command: check | |
- name: Install LLVM tools | |
run: choco install llvm | |
- name: Install cargo-llvm-cov | |
run: cargo install cargo-llvm-cov | |
- name: Run tests with coverage | |
run: cargo llvm-cov --workspace --lcov --output-path ./target/lcov.info | |
- name: Upload coverage reports to Codecov | |
uses: codecov/codecov-action@v4.4.1 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
- name: Install cargo bundle | |
run: cargo install cargo-bundle | |
- name: Bundle the application | |
run: cargo bundle --release | |
- name: Upload Linux binary to GitHub | |
uses: actions/upload-artifact@v4 | |
with: | |
name: windows-exe | |
path: target/release/bundle/windows/ | |
if-no-files-found: error | |
compression-level: 9 | |
overwrite: true | |
release-plz: | |
name: Create a release on crates.io | |
needs: [mac-test, linux-test, windows-test] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.PAT }} | |
- name: Install Rust toolchain | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
components: rustfmt, clippy | |
- name: Run release-plz | |
id: release-plz | |
uses: MarcoIeni/release-plz-action@v0.5 | |
env: | |
# not sure how I feel about this being an env var | |
GITHUB_TOKEN: ${{ secrets.PAT }} | |
# ditto | |
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
- name: Read release output | |
env: | |
RELEASES: ${{ steps.release-plz.outputs.releases }} | |
PRS: ${{ steps.release-plz.outputs.prs }} | |
PR: ${{ steps.release-plz.outputs.pr }} | |
PRS_CREATED: ${{ steps.release-plz.outputs.prs_created }} | |
RELEASES_CREATED: ${{ steps.release-plz.outputs.releases_created }} | |
run: | | |
set -e | |
echo "releases: $RELEASES" # example: [{"package_name":"my-package","prs":[{"html_url":"https://github.com/user/proj/pull/1439","number":1439}],"tag":"v0.1.0","version":"0.1.0"}] | |
echo "prs: $PRS" # example: [{"base_branch":"main","head_branch":"release-plz-2024-05-01T20-38-05Z","html_url":"https://github.com/MarcoIeni/rust-workspace-example/pull/198","number":198}] | |
echo "pr: $PR" # example: {"base_branch":"main","head_branch":"release-plz-2024-05-01T20-38-05Z","html_url":"https://github.com/MarcoIeni/rust-workspace-example/pull/198","number":198} | |
echo "prs_created: $PRS_CREATED" # example: true | |
echo "releases_created: $RELEASES_CREATED" # example: true | |
# get the number of releases with jq | |
releases_length=$(echo "$RELEASES" | jq 'length') | |
echo "releases_length: $releases_length" | |
# access the first release with jq | |
release_version=$(echo "$RELEASES" | jq -r '.[0].version') | |
echo "release_version: $release_version" | |
# access the first release with fromJSON. Docs: https://docs.github.com/en/actions/learn-github-actions/expressions | |
echo "release_version: ${{ fromJSON(steps.release-plz.outputs.releases)[0].version }}" | |
release_tag=$(echo "$RELEASES" | jq -r '.[0].tag') | |
echo "release_tag: $release_tag" | |
release_package_name=$(echo "$RELEASES" | jq -r '.[0].package_name') | |
echo "release_package_name: $release_package_name" | |
# print all names of released packages, one per line | |
echo "package_names: $(echo "$RELEASES" | jq -r '.[].package_name')" | |
# TODO: show how to store this in a variable and iterate over it (maybe an array?). PR welcome! | |
# iterate over released packages | |
for package_name in $(echo "$RELEASES" | jq -r '.[].package_name'); do | |
echo "released $package_name" | |
done | |
echo "pr_number: ${{ fromJSON(steps.release-plz.outputs.pr).number }}" | |
echo "pr_html_url: ${{ fromJSON(steps.release-plz.outputs.pr).html_url }}" | |
echo "pr_head_branch: ${{ fromJSON(steps.release-plz.outputs.pr).head_branch }}" | |
echo "pr_base_branch: ${{ fromJSON(steps.release-plz.outputs.pr).base_branch }}" | |
- name: Tag released PRs | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
RELEASES: ${{ steps.release-plz.outputs.releases }} | |
run: | | |
set -e | |
# Iterate over released packages and add a label to the PRs | |
# shipped with the release. | |
for release in $(echo "$RELEASES" | jq -r -c '.[]'); do | |
package_name=$(echo "$release" | jq -r '.package_name') | |
version=$(echo "$release" | jq -r '.version') | |
prs_length=$(echo "$release" | jq '.prs | length') | |
if [ "$prs_length" -gt 0 ]; then | |
# Create label. | |
# Use `--force` to overwrite the label, | |
# so that the command does not fail if the label already exists. | |
label="released:$package_name-$version" | |
echo "Creating label $label" | |
gh label create $label --color BFD4F2 --force | |
for pr in $(echo "$release" | jq -r -c '.prs[]'); do | |
pr_number=$(echo "$pr" | jq -r '.number') | |
echo "Adding label $label to PR #$pr_number" | |
gh pr edit $pr_number --add-label $label | |
done | |
else | |
echo "No PRs found for package $package_name" | |
fi | |
done | |
publish-mac: | |
name: Publish Mac binary to GitHub | |
needs: [mac-test] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download Mac App | |
uses: actions/download-artifact@v4 | |
with: | |
name: mac-app | |
path: target/release/bundle/osx/Weave.tar.gz | |
- name: Publish Mac App | |
uses: softprops/action-gh-release@v2.0.5 | |
if: startsWith(github.ref, 'refs/tags/') | |
with: | |
files: target/release/bundle/osx/Weave.tar.gz | |
token: ${{ secrets.PAT }} | |
publish-linux: | |
name: Publish Linux binary to GitHub | |
needs: [linux-test] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download Linux binary | |
uses: actions/download-artifact@v4 | |
with: | |
name: linux-binary | |
path: target/release/bundle/linux/Weave.tar.gz | |
- name: Publish Linux binary | |
uses: softprops/action-gh-release@v2.0.5 | |
if: startsWith(github.ref, 'refs/tags/') | |
with: | |
files: target/release/bundle/deb/weave_0.0.0_amd64.deb | |
token: ${{ secrets.PAT }} | |
publish-windows: | |
name: Publish Windows binary to GitHub | |
needs: [windows-test] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download Windows binary | |
uses: actions/download-artifact@v4 | |
with: | |
name: windows-exe | |
path: target/release/bundle/windows/ | |
- name: Publish Windows binary | |
uses: softprops/action-gh-release@v2.0.5 | |
if: startsWith(github.ref, 'refs/tags/') | |
with: | |
files: target/release/bundle/windows/ | |
token: ${{ secrets.PAT }} |