From 9df09b0b77bdc7b4eba8fab47d81ee7449797e23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20V=C3=A9ril?= Date: Sat, 25 Jan 2025 14:06:52 +0100 Subject: [PATCH 1/5] Remove publish for plugin and macro-tests --- plugin/Cargo.toml | 1 + wslplugins-macro-tests/Cargo.toml | 1 + 2 files changed, 2 insertions(+) diff --git a/plugin/Cargo.toml b/plugin/Cargo.toml index 0b5505b..0905bcb 100644 --- a/plugin/Cargo.toml +++ b/plugin/Cargo.toml @@ -5,6 +5,7 @@ version.workspace = true license.workspace = true repository.workspace = true edition = "2021" +publish = false [lib] crate-type = ["cdylib"] diff --git a/wslplugins-macro-tests/Cargo.toml b/wslplugins-macro-tests/Cargo.toml index 2430b84..d77e33a 100644 --- a/wslplugins-macro-tests/Cargo.toml +++ b/wslplugins-macro-tests/Cargo.toml @@ -6,6 +6,7 @@ license.workspace = true repository.workspace = true description = "A Rust framework for developing WSL plugins using safe and idiomatic Rust." edition = "2021" +publish = false [dependencies] wslplugins-rs = { path = "../wslplugins-rs", features = ["macro"] } From 2d9fcea1bfadc9133d914d6249ea128c9d6448f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20V=C3=A9ril?= Date: Sat, 25 Jan 2025 17:04:38 +0100 Subject: [PATCH 2/5] Add release-check.yml --- .github/workflows/release-checks.yml | 162 +++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 .github/workflows/release-checks.yml diff --git a/.github/workflows/release-checks.yml b/.github/workflows/release-checks.yml new file mode 100644 index 0000000..ae5929c --- /dev/null +++ b/.github/workflows/release-checks.yml @@ -0,0 +1,162 @@ +on: + push: + branches: + - release/* + pull_request: + branches: + - release/* + +jobs: + version-check: + runs-on: windows-latest + name: "Check crate versions" + env: + CARGO_TERM_COLOR: always + RUSTFLAGS: -D warnings + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Cache Cargo Dependencies + uses: actions/cache@v3 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-dependencies-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo-dependencies- + + - name: Cache PowerShell Modules + uses: actions/cache@v3 + with: + path: | + $env:USERPROFILE\Documents\WindowsPowerShell\Modules + key: ${{ runner.os }}-powershell-modules + restore-keys: ${{ runner.os }}-powershell-modules- + + - name: Install Rust + shell: pwsh + run: rustup update stable && rustup default stable + + - name: Install PSSemVer + shell: pwsh + run: | + try { + Import-Module -Name PSSemVer -ErrorAction Stop + } catch { + Write-Host "Installing PSSemVer module..." + Install-Module -Name PSSemVer -Scope CurrentUser -Force -ErrorAction Stop + Import-Module -Name PSSemVer -ErrorAction Stop + } + + - name: Extract Branch Version + id: extract_version + shell: pwsh + run: | + $branchName = "${{ github.ref_name }}" + try { + $rawVersion = $branchName -replace '^release/', '' + $expectedVersion = [PSSemVer]::Parse($rawVersion) + + if ($expectedVersion.HasMetadata) { + Write-Error "Extracted version '$rawVersion' contains metadata, which is not allowed." + exit 1 + } + + Write-Output "expected_version=$expectedVersion" | Out-File -FilePath $GITHUB_OUTPUT -Encoding utf8 + Write-Host "Expected version for crates: $expectedVersion" + } catch { + Write-Error "Branch name does not contain a valid semantic version. Current branch: $branchName" + exit 1 + } + + - name: Parse and Compare Crate Versions + shell: pwsh + env: + EXPECTED_VERSION: ${{ steps.extract_version.outputs.expected_version }} + run: | + try { + $expectedSemVer = [PSSemVer]::Parse($env:EXPECTED_VERSION) + } catch { + Write-Error "Expected version '$env:EXPECTED_VERSION' is not a valid semantic version." + exit 1 + } + + # Retrieve workspace metadata + $metadataJson = cargo metadata --format-version 1 + $metadata = $metadataJson | ConvertFrom-Json + $workspaceMembers = $metadata.workspace_members + + $errors = @() + + foreach ($package in $metadata.packages) { + # Skip non-workspace members + if (-not ($workspaceMembers -contains $package.id)) { + continue + } + + $name = $package.name + $versionStr = [PSSemVer]::Parse($package.version).ToString("M.N.P") # Parse and format without metadata + + try { + $semVer = [PSSemVer]::Parse($versionStr) + } catch { + $errors += "ERROR: Version '$versionStr' of crate '$name' is not a valid semantic version." + continue + } + + if ($semVer.CompareTo($expectedSemVer) -ne 0) { + if ($package.publish -ne $false) { + $errors += "ERROR: Publishable crate '$name' has version '$semVer', expected '$expectedSemVer'." + } else { + Write-Warning "Non-publishable crate '$name' has version '$semVer', expected '$expectedSemVer'." + } + } else { + Write-Host "Crate '$name' with version '$semVer' matches the branch version." + } + } + + if ($errors.Count -gt 0) { + $errors | ForEach-Object { Write-Error $_ } + exit 1 + } + + publish-dry-run: + needs: version-check + runs-on: windows-latest + name: "Publish Dry-Run" + env: + CARGO_TERM_COLOR: always + RUSTFLAGS: -D warnings + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Cache Cargo Dependencies + uses: actions/cache@v3 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-dependencies-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo-dependencies- + + - name: Install Rust + shell: pwsh + run: rustup update stable && rustup default stable + + - name: Run Tests + shell: pwsh + run: | + echo "Running tests..." + cargo test --all-targets + + - name: Publish Dry-Run + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + shell: pwsh + run: | + echo "Running cargo publish dry-run..." + cargo publish --dry-run From ea089d8c7b4bd4523de44dd93421411d635a7bcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20V=C3=A9ril?= Date: Sun, 26 Jan 2025 19:51:53 +0100 Subject: [PATCH 3/5] Add actions for release branches and CD --- .github/workflows/deploy.yml | 86 ++++++++++++++++++++++++++++ .github/workflows/release-checks.yml | 11 +--- .github/workflows/release-tag.yml | 44 ++++++++++++++ 3 files changed, 133 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/deploy.yml create mode 100644 .github/workflows/release-tag.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..14b31fc --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,86 @@ +name: Create GitHub Release + +on: + push: + tags: + - "v*" + +jobs: + validate-and-release: + runs-on: windows-latest + env: + CARGO_TERM_COLOR: always + RUSTFLAGS: -D warnings + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Cache Cargo Registry + uses: actions/cache@v3 + with: + path: ~/.cargo/registry + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo-registry- + + - name: Cache Cargo Git Index + uses: actions/cache@v3 + with: + path: ~/.cargo/git + key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo-index- + + - name: Install Rust + shell: pwsh + run: rustup update stable && rustup default stable + + - name: Install PSSemVer + shell: pwsh + run: | + try { + Import-Module -Name PSSemVer -ErrorAction Stop + } catch { + Write-Host "Installing PSSemVer module..." + Install-Module -Name PSSemVer -Scope CurrentUser -Force -ErrorAction Stop + Import-Module -Name PSSemVer -ErrorAction Stop + } + + - name: Validate Tag with PSSemVer + id: validate + shell: pwsh + run: | + $tagName = "${{ github.ref_name }}" + try { + $rawVersion = $tagName -replace '^v', '' + $Version = [PSSemVer]::Parse($rawVersion) + if ($Version.HasMetadata) { + Write-Error "Extracted version '$rawVersion' contains metadata, which is not allowed." + exit 1 + } + # Renvoyer si c'est une prerelease + if ($Version.Prerelease) { + echo "::set-output name=prerelease::true" + } else { + echo "::set-output name=prerelease::false" + } + } catch { + Write-Error "Tag name does not contain a valid semantic version. Current tag: $tagName" + exit 1 + } + continue-on-error: false + + - name: Cargo Publish Dry-Run + run: cargo publish --dry-run + + - name: Create GitHub Release + id: release + uses: actions/create-release@v1 + with: + tag_name: ${{ github.ref_name }} + release_name: Release ${{ github.ref_name }} + prerelease: ${{ steps.validate.outputs.prerelease }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Cargo Publish + run: cargo publish diff --git a/.github/workflows/release-checks.yml b/.github/workflows/release-checks.yml index ae5929c..3287e2f 100644 --- a/.github/workflows/release-checks.yml +++ b/.github/workflows/release-checks.yml @@ -78,6 +78,7 @@ jobs: run: | try { $expectedSemVer = [PSSemVer]::Parse($env:EXPECTED_VERSION) + $expectedSemVer.Metadata = "" # Remove metadata for comparison } catch { Write-Error "Expected version '$env:EXPECTED_VERSION' is not a valid semantic version." exit 1 @@ -97,14 +98,8 @@ jobs: } $name = $package.name - $versionStr = [PSSemVer]::Parse($package.version).ToString("M.N.P") # Parse and format without metadata - - try { - $semVer = [PSSemVer]::Parse($versionStr) - } catch { - $errors += "ERROR: Version '$versionStr' of crate '$name' is not a valid semantic version." - continue - } + $semVer = [PSSemVer]::Parse($package.version) + $semVer.Metadata = "" # Remove metadata for comparison if ($semVer.CompareTo($expectedSemVer) -ne 0) { if ($package.publish -ne $false) { diff --git a/.github/workflows/release-tag.yml b/.github/workflows/release-tag.yml new file mode 100644 index 0000000..ae5612d --- /dev/null +++ b/.github/workflows/release-tag.yml @@ -0,0 +1,44 @@ +name: Tag on Merge to Master + +on: + pull_request: + types: + - closed + branches: + - master + +jobs: + create-tag: + if: ${{ github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/') }} + runs-on: windows-latest + env: + CARGO_TERM_COLOR: always + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Extract Version from Branch Name + id: extract_version + shell: pwsh + run: | + $branchName = "${{ github.event.pull_request.head.ref }}" + $version = $branchName -replace '^release/', '' + Write-Host "Extracted version: $version" + echo "version=$version" >> $GITHUB_ENV + + - name: Create Git Tag + id: create_tag + run: | + git config user.name "GitHub Actions" + git config user.email "actions@github.com" + git tag "v${{ env.version }}" -a -m "Release version ${{ env.version }}" + git push origin "v${{ env.version }}" + + - name: Verify Tag + run: | + git fetch --tags + if (! git tag | grep -q "v${{ env.version }}") { + echo "Tag creation failed for version ${{ env.version }}." + exit 1 + } From b3a1bf9da874d55e5c0af816e6fd7236c15b603a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20V=C3=A9ril?= Date: Sun, 26 Jan 2025 20:55:26 +0100 Subject: [PATCH 4/5] Improve release body --- .github/workflows/deploy.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 14b31fc..2df7265 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -57,7 +57,6 @@ jobs: Write-Error "Extracted version '$rawVersion' contains metadata, which is not allowed." exit 1 } - # Renvoyer si c'est une prerelease if ($Version.Prerelease) { echo "::set-output name=prerelease::true" } else { @@ -77,7 +76,11 @@ jobs: uses: actions/create-release@v1 with: tag_name: ${{ github.ref_name }} - release_name: Release ${{ github.ref_name }} + release_name: | + ${{ steps.validate.outputs.prerelease == 'true' && 'Prerelease' || 'Release' }} ${{ github.ref_name }} + body: | + This is a ${{ steps.validate.outputs.prerelease == 'true' && 'prerelease' || 'release' }} of the crate. + You can find the [main crate here](https://crates.io/crates/${{ github.repository }}).: prerelease: ${{ steps.validate.outputs.prerelease }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 5c0d3e441f6b9bc1019f2073218fef03e0bd86fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20V=C3=A9ril?= Date: Sat, 1 Feb 2025 17:33:42 +0100 Subject: [PATCH 5/5] Taking metadata into account now --- .github/workflows/deploy.yml | 4 ---- .github/workflows/release-checks.yml | 6 ------ 2 files changed, 10 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2df7265..5988965 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -53,10 +53,6 @@ jobs: try { $rawVersion = $tagName -replace '^v', '' $Version = [PSSemVer]::Parse($rawVersion) - if ($Version.HasMetadata) { - Write-Error "Extracted version '$rawVersion' contains metadata, which is not allowed." - exit 1 - } if ($Version.Prerelease) { echo "::set-output name=prerelease::true" } else { diff --git a/.github/workflows/release-checks.yml b/.github/workflows/release-checks.yml index 3287e2f..39fa227 100644 --- a/.github/workflows/release-checks.yml +++ b/.github/workflows/release-checks.yml @@ -59,10 +59,6 @@ jobs: $rawVersion = $branchName -replace '^release/', '' $expectedVersion = [PSSemVer]::Parse($rawVersion) - if ($expectedVersion.HasMetadata) { - Write-Error "Extracted version '$rawVersion' contains metadata, which is not allowed." - exit 1 - } Write-Output "expected_version=$expectedVersion" | Out-File -FilePath $GITHUB_OUTPUT -Encoding utf8 Write-Host "Expected version for crates: $expectedVersion" @@ -78,7 +74,6 @@ jobs: run: | try { $expectedSemVer = [PSSemVer]::Parse($env:EXPECTED_VERSION) - $expectedSemVer.Metadata = "" # Remove metadata for comparison } catch { Write-Error "Expected version '$env:EXPECTED_VERSION' is not a valid semantic version." exit 1 @@ -99,7 +94,6 @@ jobs: $name = $package.name $semVer = [PSSemVer]::Parse($package.version) - $semVer.Metadata = "" # Remove metadata for comparison if ($semVer.CompareTo($expectedSemVer) -ne 0) { if ($package.publish -ne $false) {