From a74dc347b4bd5e9e978450cfef3cf7bcbf6dac05 Mon Sep 17 00:00:00 2001 From: Miguel Medeiros Date: Fri, 21 Feb 2025 17:51:00 -0300 Subject: [PATCH] ci: split workflows and improve CI efficiency (#75) * feat: add parallel PR check workflow * fix: remove branch restriction for PR check workflow * fix: suppress clippy warnings for needless lifetimes in CI workflows * refactor: consolidate Clippy checks and streamline test workflows * feat: add documentation workflow and remove legacy Rust CI workflow * feat: trigger PR check workflow on push to main branch * fix: update test command to use CI profile in PR check workflow * fix: enhance test command with partitioning and retries for improved performance * fix: remove partitioning from test command in PR check workflow * fix: update test job to use matrix strategy for multiple crates * fix: enhance test command with additional options for better output and error handling * fix: remove silent mode from test command for clearer output * fix: add check for existing tests before running in PR check workflow * fix: add missing fi statement to close if condition in PR check workflow * fix: improve test command logic to handle no tests found scenario --- .github/workflows/docs.yml | 57 +++++++++++++++ .github/workflows/pr-check.yml | 75 ++++++++++++++++++++ .github/workflows/rust.yaml | 123 --------------------------------- 3 files changed, 132 insertions(+), 123 deletions(-) create mode 100644 .github/workflows/docs.yml create mode 100644 .github/workflows/pr-check.yml delete mode 100644 .github/workflows/rust.yaml diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..618e1d8 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,57 @@ +name: Documentation + +on: + push: + branches: [ main ] + +permissions: + contents: write + +jobs: + docs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Cache mdbook installation + uses: actions/cache@v2 + with: + path: ~/.cargo/bin/mdbook + key: ${{ runner.os }}-mdbook + + - name: Cache mdbook-mermaid installation + uses: actions/cache@v2 + with: + path: ~/.cargo/bin/mdbook + key: ${{ runner.os }}-mdbook-mermaid + + - name: Install mdBook if not installed already + run: | + if [ ! -f ~/.cargo/bin/mdbook ]; then + cargo install mdbook + fi + + - name: Install mdBook-mermaid if not installed already + run: | + if [ ! -f ~/.cargo/bin/mdbook-mermaid ]; then + cargo install mdbook-mermaid + fi + + - name: Cache mdBook build + id: mdbook-build-cache + uses: actions/cache@v3 + with: + path: ./docs/book/ + key: ${{ runner.os }}-mdbook-${{ hashFiles('./docs/**') }} + restore-keys: | + ${{ runner.os }}-mdbook- + + - name: Build the book + if: steps.mdbook-build-cache.outputs.cache-hit != 'true' + run: mdbook build ./docs/ + + - name: Deploy book to GitHub Pages + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./docs/book/ diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml new file mode 100644 index 0000000..2e1d4c8 --- /dev/null +++ b/.github/workflows/pr-check.yml @@ -0,0 +1,75 @@ +name: PR Check + +on: + pull_request: + push: + branches: [ main ] + +jobs: + fmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + components: rustfmt + override: true + - name: Check formatting + run: cargo fmt --check + + clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + components: clippy + override: true + - name: Cache + uses: Swatinem/rust-cache@v2 + - name: Lint with Clippy + run: cargo clippy --workspace --all-features -- -D warnings -A clippy::needless_lifetimes + + test: + strategy: + matrix: + crate: [pubky, pubky-common, pubky-homeserver, pubky-testnet, http-relay] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - name: Install Nextest + uses: taiki-e/install-action@nextest + - name: Cache + uses: Swatinem/rust-cache@v2 + - name: Run tests + run: | + set -e + if cargo nextest run \ + -p ${{ matrix.crate }} \ + --all-features \ + --test-threads num-cpus \ + --retries 2 \ + --no-fail-fast \ + --verbose; then + echo "Tests passed for ${{ matrix.crate }}" + else + if [ $? -eq 4 ]; then + echo "No tests found for ${{ matrix.crate }}" + exit 0 + else + echo "Tests failed for ${{ matrix.crate }}" + exit 1 + fi + fi \ No newline at end of file diff --git a/.github/workflows/rust.yaml b/.github/workflows/rust.yaml deleted file mode 100644 index cafb818..0000000 --- a/.github/workflows/rust.yaml +++ /dev/null @@ -1,123 +0,0 @@ -name: Rust CI - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -permissions: - contents: write - -jobs: - build-and-test: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Set up Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - components: rustfmt, clippy - override: true - - - name: Cache cargo registry - uses: actions/cache@v2 - with: - path: ~/.cargo/registry - key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} - restore-keys: | - ${{ runner.os }}-cargo-registry- - - name: Cache cargo index - uses: actions/cache@v2 - with: - path: ~/.cargo/git - key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} - restore-keys: | - ${{ runner.os }}-cargo-index- - - name: Cache cargo build - id: cargo-build-cache - uses: actions/cache@v2 - with: - path: target - key: ${{ runner.os }}-cargo-build-${{ hashFiles('./Cargo.lock') }} - restore-keys: | - ${{ runner.os }}-cargo-build- - - name: Cache Nextest installation - uses: actions/cache@v2 - with: - path: ~/.cargo/bin/cargo-nextest - key: ${{ runner.os }}-cargo-nextest - - - name: Install Nextest if not cached - run: | - if [ ! -f ~/.cargo/bin/cargo-nextest ]; then - cargo install cargo-nextest - fi - - - name: Check no default features - run: cargo check --no-default-features - - - name: Check formatting - run: cargo fmt -- --check - - - name: Lint with Clippy - run: cargo clippy --workspace --all-features --bins --tests - - - name: Build - if: steps.cargo-build-cache.outputs.cache-hit != 'true' - run: cargo build --release --workspace --all-features --verbose - - - name: Run tests with Nextest - run: cargo nextest run --all-features --workspace --verbose - - - name: Run docs - run: cargo doc --workspace --all-features --no-deps --document-private-items --verbose - - - - name: Cache mdbook installation - uses: actions/cache@v2 - with: - path: ~/.cargo/bin/mdbook - key: ${{ runner.os }}-mdbook - - - name: Cache mdbook-mermaid installation - uses: actions/cache@v2 - with: - path: ~/.cargo/bin/mdbook - key: ${{ runner.os }}-mdbook-mermaid - - - name: Install mdBook if not installed already - run: | - if [ ! -f ~/.cargo/bin/mdbook ]; then - cargo install mdbook - fi - - - name: Install mdBook-mermaid if not installed already - run: | - if [ ! -f ~/.cargo/bin/mdbook-mermaid ]; then - cargo install mdbook-mermaid - fi - - - name: Cache mdBook build - id: mdbook-build-cache - uses: actions/cache@v3 - with: - path: ./docs/book/ - key: ${{ runner.os }}-mdbook-${{ hashFiles('./docs/**') }} - restore-keys: | - ${{ runner.os }}-mdbook- - - - name: Build the book - if: steps.mdbook-build-cache.outputs.cache-hit != 'true' - run: mdbook build ./docs/ - - - name: Deploy book to GitHub Pages - if: github.ref == 'refs/heads/main' # Deploy only when PR is merged to main - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./docs/book/