Skip to content

Commit c8b7509

Browse files
authored
Implements Release system (#1)
1 parent d8792f6 commit c8b7509

File tree

7 files changed

+151
-24
lines changed

7 files changed

+151
-24
lines changed

.github/workflows/dotnet-build.yml

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: .NET
1+
name: .NET (build)
22

33
on:
44
push:
@@ -8,28 +8,27 @@ on:
88
paths:
99
- 'visual-dotnet/**'
1010

11+
defaults:
12+
run:
13+
working-directory: visual-dotnet
14+
1115
jobs:
1216
build:
1317
runs-on: windows-latest
1418

1519
steps:
16-
- uses: actions/checkout@v3
20+
- uses: actions/checkout@v4
1721
- name: Setup .NET
18-
uses: actions/setup-dotnet@v3
22+
uses: actions/setup-dotnet@v4
1923
with:
2024
dotnet-version: 6.0.x
2125
- name: Install dotnet-format tool
2226
run: dotnet tool install -g dotnet-format
23-
working-directory: visual-dotnet
2427
- name: Restore dependencies
2528
run: dotnet restore
26-
working-directory: visual-dotnet
2729
- name: Run dotnet format
2830
run: dotnet format '.' --verify-no-changes
29-
working-directory: visual-dotnet
3031
- name: Build
3132
run: dotnet build .\SauceLabs.Visual\SauceLabs.Visual.csproj --no-restore
32-
working-directory: visual-dotnet
3333
- name: Test
3434
run: dotnet test --verbosity normal
35-
working-directory: visual-dotnet

.github/workflows/dotnet-release.yml

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: .NET (Release)
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
releaseType:
7+
description: 'Release type - major, minor or patch'
8+
required: true
9+
default: 'minor'
10+
11+
defaults:
12+
run:
13+
working-directory: visual-dotnet
14+
15+
jobs:
16+
checks:
17+
runs-on: windows-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: actions/setup-dotnet@v4
21+
with:
22+
dotnet-version: 6.0.x
23+
- run: dotnet tool install -g dotnet-format
24+
- run: dotnet format '.' --verify-no-changes
25+
- run: dotnet restore
26+
- run: dotnet build .\SauceLabs.Visual\SauceLabs.Visual.csproj --no-restore
27+
- run: dotnet test --verbosity normal
28+
29+
release:
30+
runs-on: windows-latest
31+
needs:
32+
- checks
33+
34+
steps:
35+
- uses: actions/checkout@v4
36+
- uses: actions/setup-dotnet@v4
37+
with:
38+
dotnet-version: 6.0.x
39+
40+
- name: Setup Git
41+
if: ${{ steps.prep.outputs.tag_name == '' }}
42+
run: |
43+
git config --global user.name "sauce-visual-bot"
44+
git config --global user.email "[email protected]"
45+
46+
- name: upgrade & push version
47+
id: upgrade
48+
run: |
49+
$newVersion = .\scripts\UpdateVersion.ps1 -project .\SauceLabs.Visual\SauceLabs.Visual.csproj -releaseType ${{ github.event.inputs.releaseType }}
50+
git add ./SauceLabs.Visual/SauceLabs.Visual.csproj
51+
git commit -m "[release] dotnet-$newVersion"
52+
git tag "dotnet-$newVersion"
53+
git push
54+
git push origin "dotnet-$newVersion"
55+
56+
"tag_name=dotnet-$newVersion" | Out-File -Append $Env:GITHUB_OUTPUT
57+
"version=$newVersion" | Out-File -Append $Env:GITHUB_OUTPUT
58+
59+
- name: build artifact
60+
run: dotnet build .\SauceLabs.Visual\SauceLabs.Visual.csproj -c Release
61+
62+
- name: pack artifact
63+
run: dotnet pack .\SauceLabs.Visual\SauceLabs.Visual.csproj -c Release
64+
65+
- name: publish artifact
66+
run: |
67+
$version = "${{ steps.upgrade.outputs.version }}"
68+
$apiKey = "${{ secrets.NUGET_API_KEY }}"
69+
dotnet nuget push .\SauceLabs.Visual\bin\Release\SauceLabs.Visual.$version.nupkg --api-key $apiKey --source https://api.nuget.org/v3/index.json
70+
71+
- name: Github Release
72+
uses: softprops/action-gh-release@v2
73+
with:
74+
fail_on_unmatched_files: true
75+
tag_name: ${{ steps.upgrade.outputs.tag_name }}
76+
files: visual-dotnet/SauceLabs.Visual/bin/Release/SauceLabs.Visual.${{ steps.upgrade.outputs.version }}.nupkg
77+
generate_release_notes: true

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ This repository contains the SDKs for Sauce Labs Visual.
44

55
## SDKs
66

7-
- [C#][./visual-dotnet]
7+
- [C#](./visual-dotnet)

visual-dotnet/README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ Sauce Labs Visual for C# expose Sauce Labs Visual Testing for your C# project wi
44

55
# Installation
66

7-
[TO BE COMPLETED WHEN AVAILABLE WITH NUGET]
7+
Add SauceLabs.Visual to your current project
8+
```sh
9+
dotnet add package SauceLabs.Visual
10+
```
811

912
# How to use
1013

@@ -29,6 +32,6 @@ Sauce Labs Visual for C# expose Sauce Labs Visual Testing for your C# project wi
2932
- Get results of Visual Tests and run assertions on it
3033
```csharp
3134
var results = await visualClient.VisualResults(visualBuild.Id);
32-
// verify if any check is unapproved
33-
Assert.AreEqual(0, results[DiffStatus.Unapproved]);
35+
// verify that no differences have been detected
36+
Assert.AreEqual(0, results[DiffStatus.Approved]);
3437
```
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,40 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<PropertyGroup>
43
<TargetFramework>netstandard2.0</TargetFramework>
54
<RootNamespace>SauceLabs.Visual</RootNamespace>
65
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
7-
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
8-
<PackageLicenseUrl>https://github.com/saucelabs/visual-csharp-client/blob/main/LICENSE</PackageLicenseUrl>
6+
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
97
<language>en-US</language>
108
<NeutralLanguage>en</NeutralLanguage>
11-
12-
<PackageId>SauceLabs.Visual.Client</PackageId>
13-
<Version>0.0.1</Version>
9+
<PackageId>SauceLabs.Visual</PackageId>
10+
<Version>0.0.0</Version>
1411
<Title>Sauce Labs Visual Binding</Title>
1512
<PackageTags>saucelabs sauce labs visual testing screenshot capture dom</PackageTags>
16-
<RepositoryUrl>https://github.com/saucelabs/visual-csharp-client</RepositoryUrl>
13+
<RepositoryUrl>https://github.com/saucelabs/visual-sdks</RepositoryUrl>
1714
<RepositoryType>git</RepositoryType>
15+
<PackageProjectUrl>https://github.com/saucelabs/visual-sdks/tree/main/visual-dotnet</PackageProjectUrl>
16+
<PackageReadmeFile>README.md</PackageReadmeFile>
17+
<PackageIcon>icon.png</PackageIcon>
1818
<PackageLanguage>en-US</PackageLanguage>
1919
<Copyright>Sauce Labs</Copyright>
2020
<Authors>Sauce Labs</Authors>
2121
<Owners>Sauce Labs</Owners>
2222
<Company>Sauce Labs</Company>
23-
<Description>Sauce Labs Visual's integration with C# allows customers to run Visual Testing while running their Selenium sessions.</Description>
23+
<Description>Sauce Labs Visual's integration allows customers to run Visual Testing while running their Selenium sessions.</Description>
2424
<LangVersion>8</LangVersion>
2525
<Nullable>enable</Nullable>
2626
</PropertyGroup>
27-
2827
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
2928
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
3029
</PropertyGroup>
31-
3230
<ItemGroup>
3331
<PackageReference Include="AnyRetry" Version="1.0.31" />
3432
<PackageReference Include="GraphQL.Client" Version="6.0.2" />
3533
<PackageReference Include="GraphQL.Client.Abstractions" Version="6.0.2" />
3634
<PackageReference Include="GraphQL.Client.Serializer.Newtonsoft" Version="6.0.2" />
3735
<PackageReference Include="GraphQL.Primitives" Version="6.0.2" />
3836
<PackageReference Include="Selenium.WebDriver" Version="4.0.0" />
37+
<None Include="..\README.md" Pack="true" PackagePath="\" />
38+
<None Include="images\icon.png" Pack="true" PackagePath="" />
3939
</ItemGroup>
40-
41-
</Project>
40+
</Project>
1.38 KB
Loading
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
param (
2+
[Parameter(Mandatory=$true)][string]$projectFile,
3+
[Parameter(Mandatory=$true)][string]$releaseType
4+
)
5+
6+
function Update-Version {
7+
param (
8+
[string]$version,
9+
[string]$releaseType
10+
)
11+
[Int32[]]$subVersion = $version.Split('.')
12+
13+
if ($releaseType.Equals("major")) {
14+
$subVersion[0] = $subVersion[0] + 1
15+
$subVersion[1] = 0
16+
$subVersion[2] = 0
17+
}
18+
19+
if ($releaseType.Equals("minor")) {
20+
$subVersion[1] = $subVersion[1] + 1
21+
$subVersion[2] = 0
22+
}
23+
24+
if ($releaseType.Equals("patch")) {
25+
$subVersion[2] = $subVersion[2] + 1
26+
}
27+
return $subVersion -join "."
28+
};
29+
30+
31+
$possibleReleaseType = "major","minor","patch"
32+
if (!$possibleReleaseType.Contains($releaseType)) {
33+
throw "$releaseType is not a valid upgrade"
34+
}
35+
36+
if (!$projectFile.EndsWith(".csproj")) {
37+
throw "$projectFile is not a valid C# project"
38+
}
39+
40+
[xml]$projectContent = Get-Content $projectFile
41+
42+
$versionElement = $projectContent.SelectSingleNode("//Project/PropertyGroup/Version")
43+
44+
[string]$version = $versionElement.InnerText
45+
[string]$newVersion = Update-Version -version $version -releaseType $releaseType
46+
47+
$versionElement.InnerText = $newVersion
48+
$projectContent.Save($projectFile)
49+
Write-Output $newVersion

0 commit comments

Comments
 (0)