From 61d5021e085b7d71aaf2a5ded692fe77fe980d52 Mon Sep 17 00:00:00 2001 From: Jeb Bearer Date: Mon, 11 Mar 2024 15:46:43 -0400 Subject: [PATCH 1/3] Add workflow to publish crate --- .github/workflows/cargo-publish.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/cargo-publish.yml diff --git a/.github/workflows/cargo-publish.yml b/.github/workflows/cargo-publish.yml new file mode 100644 index 0000000..1d10aad --- /dev/null +++ b/.github/workflows/cargo-publish.yml @@ -0,0 +1,23 @@ +name: Publish Crate + +on: + push: + branches: + - main + pull_request: + branches: + - main + workflow_dispatch: +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - uses: katyo/publish-crates@v2 + with: + dry-run: ${{ github.event_name != 'push' }} + ignore-unpublished-changes: true From 836f537c3764a72be36cbeac328eec0eecc658e9 Mon Sep 17 00:00:00 2001 From: Jeb Bearer Date: Thu, 14 Mar 2024 12:33:38 -0400 Subject: [PATCH 2/3] Restructure CI to prevent publishing a broken crate Move build, lint, test, docs, and publish jobs into the same action. Require successful completion of build, test, lint, and docs before publishing a new version of the crate. --- .github/workflows/build.yml | 104 ++++++++++++++++++++++++++++ .github/workflows/cargo-publish.yml | 23 ------ .github/workflows/docs.yml | 45 ------------ .github/workflows/lint.yml | 41 ----------- .github/workflows/test.yml | 39 ----------- 5 files changed, 104 insertions(+), 148 deletions(-) delete mode 100644 .github/workflows/cargo-publish.yml delete mode 100644 .github/workflows/docs.yml delete mode 100644 .github/workflows/lint.yml delete mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e6abd0f..baf5b8e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,6 +12,34 @@ on: workflow_dispatch: jobs: + lint: + runs-on: ubuntu-latest + env: + RUST_LOG: info + steps: + - uses: styfle/cancel-workflow-action@0.12.1 + name: Cancel Outdated Builds + with: + all_but_latest: true + access_token: ${{ github.token }} + + - uses: actions/checkout@v4 + name: Checkout Repository + + - uses: dtolnay/rust-toolchain@stable + + - uses: Swatinem/rust-cache@v2 + name: Enable Rust Caching + + - name: Format Check + run: cargo fmt -- --check + + - uses: actions-rs/clippy-check@v1 + name: Clippy + with: + token: ${{ github.token }} + args: --workspace --all-features --all-targets -- -D warnings + build: runs-on: ubuntu-latest env: @@ -46,3 +74,79 @@ jobs: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./target/doc cname: tide-disco.docs.espressosys.com + + test: + runs-on: ubuntu-latest + env: + RUST_LOG: info + steps: + - uses: styfle/cancel-workflow-action@0.12.1 + name: Cancel Outdated Builds + with: + all_but_latest: true + access_token: ${{ github.token }} + + - uses: actions/checkout@v4 + name: Checkout Repository + + - uses: dtolnay/rust-toolchain@stable + + - uses: Swatinem/rust-cache@v2 + name: Enable Rust Caching + + - name: Build tests + run: cargo test --workspace --release --all-features --no-run + + - name: Test + run: cargo test --workspace --release --all-features --verbose -- --test-threads 2 + timeout-minutes: 60 + + docs: + runs-on: ubuntu-latest + env: + RUST_LOG: info + steps: + - uses: styfle/cancel-workflow-action@0.12.1 + name: Cancel Outdated Builds + with: + all_but_latest: true + access_token: ${{ github.token }} + + - uses: actions/checkout@v4 + name: Checkout Repository + + - uses: dtolnay/rust-toolchain@stable + + - uses: Swatinem/rust-cache@v2 + name: Enable Rust Caching + + - name: Generate Documentation + run: | + cargo doc --no-deps --lib --release --all-features + echo '' > target/doc/index.html + + - name: Deploy Documentation + uses: peaceiris/actions-gh-pages@v3 + if: ${{ github.ref == 'refs/heads/main' }} + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./target/doc + cname: base64-bytes.docs.espressosys.com + + publish: + needs: + - build + - test + - lint + - docs + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - uses: katyo/publish-crates@v2 + with: + dry-run: ${{ github.event_name != 'push' }} + ignore-unpublished-changes: true \ No newline at end of file diff --git a/.github/workflows/cargo-publish.yml b/.github/workflows/cargo-publish.yml deleted file mode 100644 index 1d10aad..0000000 --- a/.github/workflows/cargo-publish.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Publish Crate - -on: - push: - branches: - - main - pull_request: - branches: - - main - workflow_dispatch: -jobs: - publish: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - - uses: katyo/publish-crates@v2 - with: - dry-run: ${{ github.event_name != 'push' }} - ignore-unpublished-changes: true diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml deleted file mode 100644 index eb32468..0000000 --- a/.github/workflows/docs.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Documentation - -on: - push: - branches: - - main - - release-* - pull_request: - branches: - - main - - release-* - workflow_dispatch: - -jobs: - docs: - runs-on: ubuntu-latest - env: - RUST_LOG: info - steps: - - uses: styfle/cancel-workflow-action@0.12.1 - name: Cancel Outdated Builds - with: - all_but_latest: true - access_token: ${{ github.token }} - - - uses: actions/checkout@v4 - name: Checkout Repository - - - uses: dtolnay/rust-toolchain@stable - - - uses: Swatinem/rust-cache@v2 - name: Enable Rust Caching - - - name: Generate Documentation - run: | - cargo doc --no-deps --lib --release --all-features - echo '' > target/doc/index.html - - - name: Deploy Documentation - uses: peaceiris/actions-gh-pages@v3 - if: ${{ github.ref == 'refs/heads/main' }} - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./target/doc - cname: base64-bytes.docs.espressosys.com diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 5d81c55..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Lint - -on: - push: - branches: - - main - - release-* - pull_request: - branches: - - main - - release-* - workflow_dispatch: - -jobs: - lint: - runs-on: ubuntu-latest - env: - RUST_LOG: info - steps: - - uses: styfle/cancel-workflow-action@0.12.1 - name: Cancel Outdated Builds - with: - all_but_latest: true - access_token: ${{ github.token }} - - - uses: actions/checkout@v4 - name: Checkout Repository - - - uses: dtolnay/rust-toolchain@stable - - - uses: Swatinem/rust-cache@v2 - name: Enable Rust Caching - - - name: Format Check - run: cargo fmt -- --check - - - uses: actions-rs/clippy-check@v1 - name: Clippy - with: - token: ${{ github.token }} - args: --workspace --all-features --all-targets -- -D warnings diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 5959ea1..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: Test - -on: - push: - branches: - - main - - release-* - pull_request: - branches: - - main - - release-* - workflow_dispatch: - -jobs: - test: - runs-on: ubuntu-latest - env: - RUST_LOG: info - steps: - - uses: styfle/cancel-workflow-action@0.12.1 - name: Cancel Outdated Builds - with: - all_but_latest: true - access_token: ${{ github.token }} - - - uses: actions/checkout@v4 - name: Checkout Repository - - - uses: dtolnay/rust-toolchain@stable - - - uses: Swatinem/rust-cache@v2 - name: Enable Rust Caching - - - name: Build tests - run: cargo test --workspace --release --all-features --no-run - - - name: Test - run: cargo test --workspace --release --all-features --verbose -- --test-threads 2 - timeout-minutes: 60 From 6311db782aa30cb98af52d2b83f6b777a1935ad9 Mon Sep 17 00:00:00 2001 From: Jeb Bearer Date: Thu, 14 Mar 2024 12:42:22 -0400 Subject: [PATCH 3/3] Only publish crate when a release tag is pushed --- .github/workflows/build.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index baf5b8e..a43a1bf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,6 +5,8 @@ on: branches: - main - release-* + tags: + - v*.*.* pull_request: branches: - main @@ -148,5 +150,6 @@ jobs: override: true - uses: katyo/publish-crates@v2 with: - dry-run: ${{ github.event_name != 'push' }} + # Only do an actual publish if this is a push to a release tag. Otherwise, do a dry run. + dry-run: ${{ !(github.event_name == 'push' && github.ref_type == 'tag') }} ignore-unpublished-changes: true \ No newline at end of file