|
| 1 | +on: |
| 2 | + push: |
| 3 | + branches: |
| 4 | + - release/* |
| 5 | + pull_request: |
| 6 | + branches: |
| 7 | + - release/* |
| 8 | + |
| 9 | +jobs: |
| 10 | + version-check: |
| 11 | + runs-on: windows-latest |
| 12 | + name: "Check crate versions" |
| 13 | + env: |
| 14 | + CARGO_TERM_COLOR: always |
| 15 | + RUSTFLAGS: -D warnings |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout Code |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Cache Cargo Dependencies |
| 22 | + uses: actions/cache@v3 |
| 23 | + with: |
| 24 | + path: | |
| 25 | + ~/.cargo/registry |
| 26 | + ~/.cargo/git |
| 27 | + key: ${{ runner.os }}-cargo-dependencies-${{ hashFiles('**/Cargo.lock') }} |
| 28 | + restore-keys: ${{ runner.os }}-cargo-dependencies- |
| 29 | + |
| 30 | + - name: Cache PowerShell Modules |
| 31 | + uses: actions/cache@v3 |
| 32 | + with: |
| 33 | + path: | |
| 34 | + $env:USERPROFILE\Documents\WindowsPowerShell\Modules |
| 35 | + key: ${{ runner.os }}-powershell-modules |
| 36 | + restore-keys: ${{ runner.os }}-powershell-modules- |
| 37 | + |
| 38 | + - name: Install Rust |
| 39 | + shell: pwsh |
| 40 | + run: rustup update stable && rustup default stable |
| 41 | + |
| 42 | + - name: Install PSSemVer |
| 43 | + shell: pwsh |
| 44 | + run: | |
| 45 | + try { |
| 46 | + Import-Module -Name PSSemVer -ErrorAction Stop |
| 47 | + } catch { |
| 48 | + Write-Host "Installing PSSemVer module..." |
| 49 | + Install-Module -Name PSSemVer -Scope CurrentUser -Force -ErrorAction Stop |
| 50 | + Import-Module -Name PSSemVer -ErrorAction Stop |
| 51 | + } |
| 52 | +
|
| 53 | + - name: Extract Branch Version |
| 54 | + id: extract_version |
| 55 | + shell: pwsh |
| 56 | + run: | |
| 57 | + $branchName = "${{ github.ref_name }}" |
| 58 | + try { |
| 59 | + $rawVersion = $branchName -replace '^release/', '' |
| 60 | + $expectedVersion = [PSSemVer]::Parse($rawVersion) |
| 61 | +
|
| 62 | +
|
| 63 | + Write-Output "expected_version=$expectedVersion" | Out-File -FilePath $GITHUB_OUTPUT -Encoding utf8 |
| 64 | + Write-Host "Expected version for crates: $expectedVersion" |
| 65 | + } catch { |
| 66 | + Write-Error "Branch name does not contain a valid semantic version. Current branch: $branchName" |
| 67 | + exit 1 |
| 68 | + } |
| 69 | +
|
| 70 | + - name: Parse and Compare Crate Versions |
| 71 | + shell: pwsh |
| 72 | + env: |
| 73 | + EXPECTED_VERSION: ${{ steps.extract_version.outputs.expected_version }} |
| 74 | + run: | |
| 75 | + try { |
| 76 | + $expectedSemVer = [PSSemVer]::Parse($env:EXPECTED_VERSION) |
| 77 | + } catch { |
| 78 | + Write-Error "Expected version '$env:EXPECTED_VERSION' is not a valid semantic version." |
| 79 | + exit 1 |
| 80 | + } |
| 81 | +
|
| 82 | + # Retrieve workspace metadata |
| 83 | + $metadataJson = cargo metadata --format-version 1 |
| 84 | + $metadata = $metadataJson | ConvertFrom-Json |
| 85 | + $workspaceMembers = $metadata.workspace_members |
| 86 | +
|
| 87 | + $errors = @() |
| 88 | +
|
| 89 | + foreach ($package in $metadata.packages) { |
| 90 | + # Skip non-workspace members |
| 91 | + if (-not ($workspaceMembers -contains $package.id)) { |
| 92 | + continue |
| 93 | + } |
| 94 | +
|
| 95 | + $name = $package.name |
| 96 | + $semVer = [PSSemVer]::Parse($package.version) |
| 97 | +
|
| 98 | + if ($semVer.CompareTo($expectedSemVer) -ne 0) { |
| 99 | + if ($package.publish -ne $false) { |
| 100 | + $errors += "ERROR: Publishable crate '$name' has version '$semVer', expected '$expectedSemVer'." |
| 101 | + } else { |
| 102 | + Write-Warning "Non-publishable crate '$name' has version '$semVer', expected '$expectedSemVer'." |
| 103 | + } |
| 104 | + } else { |
| 105 | + Write-Host "Crate '$name' with version '$semVer' matches the branch version." |
| 106 | + } |
| 107 | + } |
| 108 | +
|
| 109 | + if ($errors.Count -gt 0) { |
| 110 | + $errors | ForEach-Object { Write-Error $_ } |
| 111 | + exit 1 |
| 112 | + } |
| 113 | +
|
| 114 | + publish-dry-run: |
| 115 | + needs: version-check |
| 116 | + runs-on: windows-latest |
| 117 | + name: "Publish Dry-Run" |
| 118 | + env: |
| 119 | + CARGO_TERM_COLOR: always |
| 120 | + RUSTFLAGS: -D warnings |
| 121 | + |
| 122 | + steps: |
| 123 | + - name: Checkout Code |
| 124 | + uses: actions/checkout@v4 |
| 125 | + |
| 126 | + - name: Cache Cargo Dependencies |
| 127 | + uses: actions/cache@v3 |
| 128 | + with: |
| 129 | + path: | |
| 130 | + ~/.cargo/registry |
| 131 | + ~/.cargo/git |
| 132 | + key: ${{ runner.os }}-cargo-dependencies-${{ hashFiles('**/Cargo.lock') }} |
| 133 | + restore-keys: ${{ runner.os }}-cargo-dependencies- |
| 134 | + |
| 135 | + - name: Install Rust |
| 136 | + shell: pwsh |
| 137 | + run: rustup update stable && rustup default stable |
| 138 | + |
| 139 | + - name: Run Tests |
| 140 | + shell: pwsh |
| 141 | + run: | |
| 142 | + echo "Running tests..." |
| 143 | + cargo test --all-targets |
| 144 | +
|
| 145 | + - name: Publish Dry-Run |
| 146 | + env: |
| 147 | + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} |
| 148 | + shell: pwsh |
| 149 | + run: | |
| 150 | + echo "Running cargo publish dry-run..." |
| 151 | + cargo publish --dry-run |
0 commit comments