Skip to content

Commit a06c16b

Browse files
committed
fix release CI for pre-releases and drafts
1 parent 60a3152 commit a06c16b

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

.github/actions/cargo-publish/action.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ inputs:
44
cargo-registry-token:
55
description: 'API token for crates.io'
66
required: true
7+
github-token:
8+
description: 'Github API token'
9+
required: true
710

811
runs:
912
using: composite
@@ -13,7 +16,7 @@ runs:
1316
uses: mindsers/[email protected]
1417
with:
1518
# validation_depth: 10
16-
version: ${{ (github.ref_type == 'tag' && github.ref_name) || 'Unreleased' }}
19+
version: ${{ (github.ref_type == 'tag' && !contains(github.ref_name, '-') && github.ref_name) || 'Unreleased' }}
1720
path: ./CHANGELOG.md
1821

1922
- name: Download artifacts
@@ -30,6 +33,14 @@ runs:
3033
command: login
3134
args: -- ${{ inputs.cargo-registry-token }}
3235

36+
- run: gh release delete --yes Unreleased || exit 0
37+
if: >
38+
github.event_name == 'push' &&
39+
github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
40+
shell: bash
41+
env:
42+
GITHUB_TOKEN: ${{ inputs.github-token }}
43+
3344
- name: Create GitHub release
3445
if: >
3546
github.event_name == 'push' && (
@@ -38,10 +49,10 @@ runs:
3849
)
3950
uses: softprops/action-gh-release@v1
4051
with:
41-
tag_name: ${{ steps.changelog-reader.outputs.version }}
52+
tag_name: ${{ (github.ref_type == 'tag' && github.ref_name) || 'Unreleased' }}
4253
body: ${{ steps.changelog-reader.outputs.changes }}
43-
prerelease: ${{ steps.changelog-reader.outputs.status == 'prereleased' }}
44-
draft: ${{ steps.changelog-reader.outputs.status == 'unreleased' }}
54+
prerelease: ${{ startsWith(github.ref, 'refs/tags/v') && contains(github.ref_name, '-') }}
55+
draft: ${{ !startsWith(github.ref, 'refs/tags/v') && steps.changelog-reader.outputs.status == 'unreleased' }}
4556
files: |
4657
${{ steps.download-artifacts.outputs.download-path }}/*/*
4758

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ jobs:
301301
- uses: ./.github/actions/cargo-publish
302302
with:
303303
cargo-registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
304+
github-token: ${{ secrets.GITHUB_TOKEN }}
304305

305306
conclusion:
306307
needs: [shellcheck, fmt, clippy, test, generate-matrix, build, publish]

0 commit comments

Comments
 (0)