Skip to content

Commit

Permalink
Implements Release system (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
FriggaHel authored Mar 15, 2024
1 parent d8792f6 commit c8b7509
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 24 deletions.
15 changes: 7 additions & 8 deletions .github/workflows/dotnet-build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: .NET
name: .NET (build)

on:
push:
Expand All @@ -8,28 +8,27 @@ on:
paths:
- 'visual-dotnet/**'

defaults:
run:
working-directory: visual-dotnet

jobs:
build:
runs-on: windows-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x
- name: Install dotnet-format tool
run: dotnet tool install -g dotnet-format
working-directory: visual-dotnet
- name: Restore dependencies
run: dotnet restore
working-directory: visual-dotnet
- name: Run dotnet format
run: dotnet format '.' --verify-no-changes
working-directory: visual-dotnet
- name: Build
run: dotnet build .\SauceLabs.Visual\SauceLabs.Visual.csproj --no-restore
working-directory: visual-dotnet
- name: Test
run: dotnet test --verbosity normal
working-directory: visual-dotnet
77 changes: 77 additions & 0 deletions .github/workflows/dotnet-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: .NET (Release)

on:
workflow_dispatch:
inputs:
releaseType:
description: 'Release type - major, minor or patch'
required: true
default: 'minor'

defaults:
run:
working-directory: visual-dotnet

jobs:
checks:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x
- run: dotnet tool install -g dotnet-format
- run: dotnet format '.' --verify-no-changes
- run: dotnet restore
- run: dotnet build .\SauceLabs.Visual\SauceLabs.Visual.csproj --no-restore
- run: dotnet test --verbosity normal

release:
runs-on: windows-latest
needs:
- checks

steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x

- name: Setup Git
if: ${{ steps.prep.outputs.tag_name == '' }}
run: |
git config --global user.name "sauce-visual-bot"
git config --global user.email "[email protected]"
- name: upgrade & push version
id: upgrade
run: |
$newVersion = .\scripts\UpdateVersion.ps1 -project .\SauceLabs.Visual\SauceLabs.Visual.csproj -releaseType ${{ github.event.inputs.releaseType }}
git add ./SauceLabs.Visual/SauceLabs.Visual.csproj
git commit -m "[release] dotnet-$newVersion"
git tag "dotnet-$newVersion"
git push
git push origin "dotnet-$newVersion"
"tag_name=dotnet-$newVersion" | Out-File -Append $Env:GITHUB_OUTPUT
"version=$newVersion" | Out-File -Append $Env:GITHUB_OUTPUT
- name: build artifact
run: dotnet build .\SauceLabs.Visual\SauceLabs.Visual.csproj -c Release

- name: pack artifact
run: dotnet pack .\SauceLabs.Visual\SauceLabs.Visual.csproj -c Release

- name: publish artifact
run: |
$version = "${{ steps.upgrade.outputs.version }}"
$apiKey = "${{ secrets.NUGET_API_KEY }}"
dotnet nuget push .\SauceLabs.Visual\bin\Release\SauceLabs.Visual.$version.nupkg --api-key $apiKey --source https://api.nuget.org/v3/index.json
- name: Github Release
uses: softprops/action-gh-release@v2
with:
fail_on_unmatched_files: true
tag_name: ${{ steps.upgrade.outputs.tag_name }}
files: visual-dotnet/SauceLabs.Visual/bin/Release/SauceLabs.Visual.${{ steps.upgrade.outputs.version }}.nupkg
generate_release_notes: true
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ This repository contains the SDKs for Sauce Labs Visual.

## SDKs

- [C#][./visual-dotnet]
- [C#](./visual-dotnet)
9 changes: 6 additions & 3 deletions visual-dotnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ Sauce Labs Visual for C# expose Sauce Labs Visual Testing for your C# project wi

# Installation

[TO BE COMPLETED WHEN AVAILABLE WITH NUGET]
Add SauceLabs.Visual to your current project
```sh
dotnet add package SauceLabs.Visual
```

# How to use

Expand All @@ -29,6 +32,6 @@ Sauce Labs Visual for C# expose Sauce Labs Visual Testing for your C# project wi
- Get results of Visual Tests and run assertions on it
```csharp
var results = await visualClient.VisualResults(visualBuild.Id);
// verify if any check is unapproved
Assert.AreEqual(0, results[DiffStatus.Unapproved]);
// verify that no differences have been detected
Assert.AreEqual(0, results[DiffStatus.Approved]);
```
23 changes: 11 additions & 12 deletions visual-dotnet/SauceLabs.Visual/SauceLabs.Visual.csproj
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>SauceLabs.Visual</RootNamespace>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageLicenseUrl>https://github.com/saucelabs/visual-csharp-client/blob/main/LICENSE</PackageLicenseUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<language>en-US</language>
<NeutralLanguage>en</NeutralLanguage>

<PackageId>SauceLabs.Visual.Client</PackageId>
<Version>0.0.1</Version>
<PackageId>SauceLabs.Visual</PackageId>
<Version>0.0.0</Version>
<Title>Sauce Labs Visual Binding</Title>
<PackageTags>saucelabs sauce labs visual testing screenshot capture dom</PackageTags>
<RepositoryUrl>https://github.com/saucelabs/visual-csharp-client</RepositoryUrl>
<RepositoryUrl>https://github.com/saucelabs/visual-sdks</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageProjectUrl>https://github.com/saucelabs/visual-sdks/tree/main/visual-dotnet</PackageProjectUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIcon>icon.png</PackageIcon>
<PackageLanguage>en-US</PackageLanguage>
<Copyright>Sauce Labs</Copyright>
<Authors>Sauce Labs</Authors>
<Owners>Sauce Labs</Owners>
<Company>Sauce Labs</Company>
<Description>Sauce Labs Visual's integration with C# allows customers to run Visual Testing while running their Selenium sessions.</Description>
<Description>Sauce Labs Visual's integration allows customers to run Visual Testing while running their Selenium sessions.</Description>
<LangVersion>8</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AnyRetry" Version="1.0.31" />
<PackageReference Include="GraphQL.Client" Version="6.0.2" />
<PackageReference Include="GraphQL.Client.Abstractions" Version="6.0.2" />
<PackageReference Include="GraphQL.Client.Serializer.Newtonsoft" Version="6.0.2" />
<PackageReference Include="GraphQL.Primitives" Version="6.0.2" />
<PackageReference Include="Selenium.WebDriver" Version="4.0.0" />
<None Include="..\README.md" Pack="true" PackagePath="\" />
<None Include="images\icon.png" Pack="true" PackagePath="" />
</ItemGroup>

</Project>
</Project>
Binary file added visual-dotnet/SauceLabs.Visual/images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions visual-dotnet/scripts/UpdateVersion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
param (
[Parameter(Mandatory=$true)][string]$projectFile,
[Parameter(Mandatory=$true)][string]$releaseType
)

function Update-Version {
param (
[string]$version,
[string]$releaseType
)
[Int32[]]$subVersion = $version.Split('.')

if ($releaseType.Equals("major")) {
$subVersion[0] = $subVersion[0] + 1
$subVersion[1] = 0
$subVersion[2] = 0
}

if ($releaseType.Equals("minor")) {
$subVersion[1] = $subVersion[1] + 1
$subVersion[2] = 0
}

if ($releaseType.Equals("patch")) {
$subVersion[2] = $subVersion[2] + 1
}
return $subVersion -join "."
};


$possibleReleaseType = "major","minor","patch"
if (!$possibleReleaseType.Contains($releaseType)) {
throw "$releaseType is not a valid upgrade"
}

if (!$projectFile.EndsWith(".csproj")) {
throw "$projectFile is not a valid C# project"
}

[xml]$projectContent = Get-Content $projectFile

$versionElement = $projectContent.SelectSingleNode("//Project/PropertyGroup/Version")

[string]$version = $versionElement.InnerText
[string]$newVersion = Update-Version -version $version -releaseType $releaseType

$versionElement.InnerText = $newVersion
$projectContent.Save($projectFile)
Write-Output $newVersion

0 comments on commit c8b7509

Please sign in to comment.