Skip to content

Commit 3b2eed4

Browse files
authored
ci: Update publish workflow (#96)
* Update publish workflow * Remove workspace flag * Specify manifest path * Use cache * Pin server checks version * Move version to end * Use cargo install action * Add cargo cache back * Use cargo release * Fix level parameter * Remove unused * Add git user
1 parent 52afb98 commit 3b2eed4

File tree

2 files changed

+63
-16
lines changed

2 files changed

+63
-16
lines changed

.github/actions/setup/action.yml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,26 +69,30 @@ runs:
6969

7070
- name: Install 'cargo-audit'
7171
if: ${{ contains(inputs.components, 'audit') }}
72-
shell: bash
73-
run: cargo install cargo-audit
72+
uses: taiki-e/cache-cargo-install-action@v2
73+
with:
74+
tool: cargo-audit
7475

7576
- name: Install 'cargo-hack'
7677
if: ${{ contains(inputs.components, 'hack') }}
77-
shell: bash
78-
run: cargo install cargo-hack
78+
uses: taiki-e/cache-cargo-install-action@v2
79+
with:
80+
tool: cargo-hack
7981

8082
- name: Install 'cargo-release'
8183
if: ${{ contains(inputs.components, 'release') }}
82-
shell: bash
83-
run: cargo install [email protected]
84+
uses: taiki-e/cache-cargo-install-action@v2
85+
with:
86+
8487

8588
- name: Install 'cargo-semver-checks'
8689
if: ${{ contains(inputs.components, 'semver-checks') }}
87-
shell: bash
88-
run: cargo install cargo-semver-checks
90+
uses: taiki-e/cache-cargo-install-action@v2
91+
with:
92+
8993

9094
- name: Cache Cargo Dependencies
91-
if: ${{ inputs.cargo-cache-key && !inputs.cargo-cache-fallback-key }}
95+
if: ${{ inputs.cargo-cache-key }}
9296
uses: actions/cache@v4
9397
with:
9498
path: |
@@ -98,4 +102,3 @@ runs:
98102
~/.cargo/git/db/
99103
target/
100104
key: ${{ runner.os }}-${{ inputs.cargo-cache-key }}-${{ hashFiles('**/Cargo.lock') }}
101-
restore-keys: ${{ runner.os }}-${{ inputs.cargo-cache-key }}

.github/workflows/publish.yml

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ on:
2525
- patch
2626
- minor
2727
- major
28+
- rc
29+
- beta
30+
- alpha
31+
- release
32+
- version
33+
version:
34+
description: Version (used with level "version")
35+
required: false
36+
type: string
2837
dry_run:
2938
description: Dry run
3039
required: true
@@ -40,9 +49,42 @@ env:
4049
CACHE: true
4150

4251
jobs:
52+
semver_check:
53+
name: Check Semver
54+
runs-on: ubuntu-latest
55+
steps:
56+
- name: Git checkout
57+
uses: actions/checkout@v4
58+
59+
- name: Setup Environment
60+
uses: ./.github/actions/setup
61+
with:
62+
cargo-cache-key: cargo-semver-checks
63+
toolchain: test
64+
components: release, semver-checks
65+
66+
- name: Set Version
67+
run: |
68+
if [ "${{ inputs.level }}" == "version" ]; then
69+
LEVEL=${{ inputs.version }}
70+
else
71+
LEVEL=${{ inputs.level }}
72+
fi
73+
74+
git config --global user.email "[email protected]"
75+
git config --global user.name "github-actions"
76+
77+
cargo release $LEVEL --manifest-path ${{ inputs.crate }}/Cargo.toml --no-tag --no-publish --no-push --no-confirm --execute
78+
79+
- name: Check semver
80+
run: |
81+
pnpm semver ${{ inputs.crate }}
82+
83+
4384
publish_release:
4485
name: Publish
4586
runs-on: ubuntu-latest
87+
needs: semver_check
4688
steps:
4789
- name: Ensure CARGO_REGISTRY_TOKEN variable is set
4890
env:
@@ -61,7 +103,7 @@ jobs:
61103
with:
62104
cargo-cache-key: cargo-publish
63105
toolchain: test
64-
components: release, semver-checks
106+
components: release
65107
solana: true
66108

67109
- name: Build
@@ -75,22 +117,24 @@ jobs:
75117
git config --global user.email "[email protected]"
76118
git config --global user.name "github-actions"
77119
78-
- name: Check semver
79-
run: |
80-
pnpm semver ${{ inputs.crate }} --release-type ${{ inputs.level }}
81-
82120
- name: Publish Crate
83121
id: publish
84122
env:
85123
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
86124
run: |
125+
if [ "${{ inputs.level }}" == "version" ]; then
126+
LEVEL=${{ inputs.version }}
127+
else
128+
LEVEL=${{ inputs.level }}
129+
fi
130+
87131
if [ "${{ inputs.dry_run }}" == "true" ]; then
88132
OPTIONS="--dry-run"
89133
else
90134
OPTIONS=""
91135
fi
92136
93-
pnpm tsx ./scripts/publish.mts ${{ inputs.crate }} ${{ inputs.level }} $OPTIONS
137+
pnpm tsx ./scripts/publish.mts ${{ inputs.crate }} $LEVEL $OPTIONS
94138
95139
- name: Create GitHub release
96140
if: github.event.inputs.dry_run != 'true' && github.event.inputs.create_release == 'true'

0 commit comments

Comments
 (0)