From bfc4d0f43500acbd8deee49b1bb6d1a0af8324e9 Mon Sep 17 00:00:00 2001 From: Tushar Mathur Date: Thu, 28 Nov 2024 15:14:02 -0800 Subject: [PATCH] chore: update workflow for release --- .github/workflows/ci.yml | 22 ++++++++++++++++++++-- Cargo.toml | 1 + crates/gh-workflow/tests/ci.rs | 22 +++++++++++++--------- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f8e3e35..55a05de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,10 +50,26 @@ jobs: - name: Cargo Clippy run: cargo +nightly clippy --all-features --workspace -- -D warnings release: + name: Release + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + packages: write + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + steps: + - name: Checkout Code + uses: actions/checkout@v4 + - name: Release Plz + uses: MarcoIeni/release-plz-action@v0.5 + with: + command: release + release-pr: needs: - build - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} - name: Release + name: Release PR runs-on: ubuntu-latest permissions: contents: write @@ -67,3 +83,5 @@ jobs: uses: actions/checkout@v4 - name: Release Plz uses: MarcoIeni/release-plz-action@v0.5 + with: + command: release-pr diff --git a/Cargo.toml b/Cargo.toml index a4909fd..a0f58b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,4 @@ [workspace] edition = "2021" +resolver = "2" members = ["crates/*"] diff --git a/crates/gh-workflow/tests/ci.rs b/crates/gh-workflow/tests/ci.rs index c5ac9e3..2e32c11 100644 --- a/crates/gh-workflow/tests/ci.rs +++ b/crates/gh-workflow/tests/ci.rs @@ -1,6 +1,5 @@ -use ctx::Context; use gh_workflow::*; -use release_plz::Release; +use release_plz::{Command, Release}; use toolchain::Toolchain; #[test] @@ -51,12 +50,16 @@ fn generate() { .contents(Level::Write); let release = Job::new("Release") - .cond( - Context::github() - .event_name() - .eq("push".into()) - .and(Context::github().ref_().eq("refs/heads/main".into())), - ) + .add_env(Env::github()) + .add_env(Env::new( + "CARGO_REGISTRY_TOKEN", + "${{ secrets.CARGO_REGISTRY_TOKEN }}", + )) + .permissions(permissions.clone()) + .add_step(Step::checkout()) + .add_step(Release::default().command(Command::Release)); + + let release_pr = Job::new("Release PR") .add_needs(build.clone()) .add_env(Env::github()) .add_env(Env::new( @@ -65,13 +68,14 @@ fn generate() { )) .permissions(permissions) .add_step(Step::checkout()) - .add_step(Release::default()); + .add_step(Release::default().command(Command::ReleasePR)); Workflow::new("CI") .add_env(flags) .on(event) .add_job("build", build) .add_job("release", release) + .add_job("release-pr", release_pr) .generate() .unwrap(); }