1
0
Эх сурвалжийг харах

CI: Fix semver checks on publish (#44)

* CI: Fix semver checks to use a script

#### Problem

The semver checks step during publish is broken because it's simply
passing in the folder, but there's some additional work needed to
decompose it into a manifest path.

#### Summary of changes

Similar to many other repos, add a semver script which will pull out the
manifest given a path.

* Do it differently

* Use pinocchio style

* Install things consistently

* Make publish depend on semver check

* Add back version options (and fix inputs.crate)
Jon C 6 сар өмнө
parent
commit
b503b243d4

+ 49 - 10
.github/workflows/publish-rust.yml

@@ -22,6 +22,15 @@ on:
           - patch
           - minor
           - major
+          - rc
+          - beta
+          - alpha
+          - release
+          - version
+      version:
+        description: Version (used with level "version")
+        required: false
+        type: string
       dry_run:
         description: Dry run
         required: true
@@ -50,11 +59,6 @@ jobs:
           cargo-cache-key: cargo-test-publish-${{ inputs.package_path }}
           cargo-cache-fallback-key: cargo-test-publish
 
-      - name: Install cargo-audit
-        uses: taiki-e/install-action@v2
-        with:
-          tool: cargo-semver-checks
-
       - name: Format
         run: pnpm zx ./scripts/rust/format.mjs "${{ inputs.package_path }}"
 
@@ -67,13 +71,40 @@ jobs:
       - name: Test
         run: pnpm zx ./scripts/rust/test.mjs "${{ inputs.package_path }}"
 
+  semver:
+    name: Check Semver
+    runs-on: ubuntu-latest
+    steps:
+      - name: Git checkout
+        uses: actions/checkout@v4
+
+      - name: Setup Environment
+        uses: ./.github/actions/setup
+        with:
+          cargo-cache-key: cargo-publish-semver-${{ inputs.package_path }}
+          cargo-cache-fallback-key: cargo-publish-semver
+
+      - name: Install cargo-semver-checks
+        uses: taiki-e/install-action@v2
+        with:
+          tool: cargo-semver-checks,cargo-release
+
+      - name: Set Version
+        run: |
+          if [ "${{ inputs.level }}" == "version" ]; then
+            LEVEL=${{ inputs.version }}
+          else
+            LEVEL=${{ inputs.level }}
+          fi
+          cargo release $LEVEL --manifest-path " ${{ inputs.package_path }}/Cargo.toml" --no-tag --no-publish --no-push --no-confirm --execute
+
       - name: Check semver
-        run: pnpm rust:semver ${{ inputs.package_path }} --release-type ${{ inputs.level }}
+        run: pnpm rust:semver --manifest-path "${{ inputs.package_path }}/Cargo.toml"
 
   publish:
     name: Publish Rust Crate
     runs-on: ubuntu-latest
-    needs: test
+    needs: [test, semver]
     permissions:
       contents: write
     steps:
@@ -89,8 +120,10 @@ jobs:
           cargo-cache-key: cargo-publish-${{ inputs.package_path }}
           cargo-cache-fallback-key: cargo-publish
 
-      - name: Install Cargo Release
-        run: which cargo-release || cargo install cargo-release
+      - name: Install cargo-release
+        uses: taiki-e/install-action@v2
+        with:
+          tool: cargo-release
 
       - name: Ensure CARGO_REGISTRY_TOKEN variable is set
         env:
@@ -111,13 +144,19 @@ jobs:
         env:
           CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
         run: |
+          if [ "${{ inputs.level }}" == "version" ]; then
+            LEVEL=${{ inputs.version }}
+          else
+            LEVEL=${{ inputs.level }}
+          fi
+
           if [ "${{ inputs.dry_run }}" == "true" ]; then
             OPTIONS="--dry-run"
           else
             OPTIONS=""
           fi
 
-          pnpm rust:publish "${{ inputs.package_path }}" "${{ inputs.level }}" $OPTIONS
+          pnpm rust:publish "${{ inputs.package_path }}" $LEVEL $OPTIONS
 
       - name: Generate a changelog
         if: github.event.inputs.create_release == 'true'