Fix CI: Dry-run cargo-publish on crate to be published (#1490)

* Fix CI: Dry-run `cargo-publish` on crate to be published

If there's no crate to publish, do not dry-run `cargo-publish`.

Only dry-run `cargo-publish` on crate to be published to avoid
`cargo-publish` error on `cargo-binstall` when one of its direct
dependencies is bumped.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Fix passing of crate to `release-cli.yml`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Fix passing of `needs.pr-info.outpus.crate`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Fix `release-dry-run`: Only run if is release or is not PR event

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Fix passing of crate

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Rm `just-setup` from `release-cli.yml` since it cannot be cached

release is trigged by the closing of PR, so the cache is saved under the
branch `release/*` which cannot be reused.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Fix dry-run publish

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

---------

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2023-11-12 00:17:16 +10:00 committed by GitHub
parent 26b6db2244
commit 4599a70839
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 7 deletions

View file

@ -123,15 +123,30 @@ jobs:
- run: just avoid-dev-deps
- run: just lint
pr-info:
outputs:
is-release: ${{ steps.meta.outputs.is-release }}
crate: ${{ steps.meta.outputs.crates-names }}
runs-on: ubuntu-latest
steps:
- id: meta
if: github.event_name == 'pull_request'
uses: cargo-bins/release-meta@v1
with:
event-data: ${{ toJSON(github.event) }}
extract-notes-under: '### Release notes'
release-dry-run:
needs: pr-info
uses: ./.github/workflows/release-cli.yml
if: github.event_name != 'pull_request'
if: github.event_name != 'pull_request' || needs.pr-info.outputs.is-release == 'true'
secrets: inherit
with:
info: |
{
"is-release": false,
"crate": "cargo-binstall",
"crate": "${{ needs.pr-info.outputs.crate }}",
"version": "0.0.0",
"notes": ""
}

View file

@ -83,17 +83,15 @@ jobs:
with:
name: minisign.pub
- uses: ./.github/actions/just-setup
- run: .github/scripts/ephemeral-crate.sh
- if: fromJSON(inputs.info).is-release != 'true'
- if: fromJSON(inputs.info).is-release != 'true' && fromJSON(inputs.info).crate != ''
name: DRY-RUN Publish to crates.io
env:
crate: ${{ fromJSON(inputs.info).crate }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo package -p "$crate" --allow-dirty --no-default-features
- if: fromJSON(inputs.info).is-release != 'true'
run: cargo publish --dry-run -p "$crate" --allow-dirty --no-default-features
- if: fromJSON(inputs.info).is-release != 'true' && fromJSON(inputs.info).crate != ''
name: Upload crate package as artifact
uses: actions/upload-artifact@v3
with: