Skip to content

Commit 9b119e8

Browse files
authored
prepare release-ci-cd (#11)
1 parent 7b4c3c8 commit 9b119e8

File tree

5 files changed

+282
-0
lines changed

5 files changed

+282
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Create GitHub Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
jobs:
9+
validate-and-release:
10+
runs-on: windows-latest
11+
env:
12+
CARGO_TERM_COLOR: always
13+
RUSTFLAGS: -D warnings
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
19+
- name: Cache Cargo Registry
20+
uses: actions/cache@v3
21+
with:
22+
path: ~/.cargo/registry
23+
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
24+
restore-keys: ${{ runner.os }}-cargo-registry-
25+
26+
- name: Cache Cargo Git Index
27+
uses: actions/cache@v3
28+
with:
29+
path: ~/.cargo/git
30+
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
31+
restore-keys: ${{ runner.os }}-cargo-index-
32+
33+
- name: Install Rust
34+
shell: pwsh
35+
run: rustup update stable && rustup default stable
36+
37+
- name: Install PSSemVer
38+
shell: pwsh
39+
run: |
40+
try {
41+
Import-Module -Name PSSemVer -ErrorAction Stop
42+
} catch {
43+
Write-Host "Installing PSSemVer module..."
44+
Install-Module -Name PSSemVer -Scope CurrentUser -Force -ErrorAction Stop
45+
Import-Module -Name PSSemVer -ErrorAction Stop
46+
}
47+
48+
- name: Validate Tag with PSSemVer
49+
id: validate
50+
shell: pwsh
51+
run: |
52+
$tagName = "${{ github.ref_name }}"
53+
try {
54+
$rawVersion = $tagName -replace '^v', ''
55+
$Version = [PSSemVer]::Parse($rawVersion)
56+
if ($Version.Prerelease) {
57+
echo "::set-output name=prerelease::true"
58+
} else {
59+
echo "::set-output name=prerelease::false"
60+
}
61+
} catch {
62+
Write-Error "Tag name does not contain a valid semantic version. Current tag: $tagName"
63+
exit 1
64+
}
65+
continue-on-error: false
66+
67+
- name: Cargo Publish Dry-Run
68+
run: cargo publish --dry-run
69+
70+
- name: Create GitHub Release
71+
id: release
72+
uses: actions/create-release@v1
73+
with:
74+
tag_name: ${{ github.ref_name }}
75+
release_name: |
76+
${{ steps.validate.outputs.prerelease == 'true' && 'Prerelease' || 'Release' }} ${{ github.ref_name }}
77+
body: |
78+
This is a ${{ steps.validate.outputs.prerelease == 'true' && 'prerelease' || 'release' }} of the crate.
79+
You can find the [main crate here](https://crates.io/crates/${{ github.repository }}).:
80+
prerelease: ${{ steps.validate.outputs.prerelease }}
81+
env:
82+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
83+
84+
- name: Cargo Publish
85+
run: cargo publish
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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

.github/workflows/release-tag.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Tag on Merge to Master
2+
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
branches:
8+
- master
9+
10+
jobs:
11+
create-tag:
12+
if: ${{ github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/') }}
13+
runs-on: windows-latest
14+
env:
15+
CARGO_TERM_COLOR: always
16+
17+
steps:
18+
- name: Checkout Repository
19+
uses: actions/checkout@v4
20+
21+
- name: Extract Version from Branch Name
22+
id: extract_version
23+
shell: pwsh
24+
run: |
25+
$branchName = "${{ github.event.pull_request.head.ref }}"
26+
$version = $branchName -replace '^release/', ''
27+
Write-Host "Extracted version: $version"
28+
echo "version=$version" >> $GITHUB_ENV
29+
30+
- name: Create Git Tag
31+
id: create_tag
32+
run: |
33+
git config user.name "GitHub Actions"
34+
git config user.email "[email protected]"
35+
git tag "v${{ env.version }}" -a -m "Release version ${{ env.version }}"
36+
git push origin "v${{ env.version }}"
37+
38+
- name: Verify Tag
39+
run: |
40+
git fetch --tags
41+
if (! git tag | grep -q "v${{ env.version }}") {
42+
echo "Tag creation failed for version ${{ env.version }}."
43+
exit 1
44+
}

plugin/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ version.workspace = true
55
license.workspace = true
66
repository.workspace = true
77
edition = "2021"
8+
publish = false
89

910
[lib]
1011
crate-type = ["cdylib"]

wslplugins-macro-tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ license.workspace = true
66
repository.workspace = true
77
description = "A Rust framework for developing WSL plugins using safe and idiomatic Rust."
88
edition = "2021"
9+
publish = false
910

1011
[dependencies]
1112
wslplugins-rs = { path = "../wslplugins-rs", features = ["macro"] }

0 commit comments

Comments
 (0)