Skip to content

Commit

Permalink
#12 Added build & publish pipeline
Browse files Browse the repository at this point in the history
(closes #12)
  • Loading branch information
Andrei15193 committed May 6, 2020
1 parent e0cd580 commit 57b4817
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 1 deletion.
158 changes: 158 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
name: Publish

on:
push:
branches:
- master
- releases/*

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Generate Package Info
if: startsWith(github.ref, 'refs/heads/releases/')
id: package_info
shell: pwsh
run: |
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
$releaseBranchName = $env:GITHUB_REF.Substring($env:GITHUB_REF.LastIndexOf('/') + 1)
$minorVersionSeparatorIndex = $releaseBranchName.IndexOf('.')
$preReleaseVersionSeparatorIndex = $releaseBranchName.IndexOf('-')
$majorVersion = $releaseBranchName.Substring(0, $minorVersionSeparatorIndex)
if ($preReleaseVersionSeparatorIndex -gt -1)
{
$minorVersion = $releaseBranchName.Substring($minorVersionSeparatorIndex + 1, $preReleaseVersionSeparatorIndex - $minorVersionSeparatorIndex - 1)
$preRelease = $releaseBranchName.Substring($preReleaseVersionSeparatorIndex + 1)
}
else
{
$minorVersion = $releaseBranchName.Substring($minorVersionSeparatorIndex + 1)
$preRelease = $null
}
$preReleaseOffset = switch ($preRelease)
{
'alpha' { 1000 }
'beta' { 2000 }
'rc' { 3000 }
default { 0 }
}
$latestRevision = 0
(git tag) |
Where-Object { $_ -match "^${majorVersion}\.${minorVersion}\.\d+(-\w+\d*)?$" } |
ForEach-Object { $latestRevision = [Math]::Max($latestRevision, $_.Split('.')[2].Split('-')[0]) }
$hasRelease = $false
$latestPreRelease = 0
(git tag) |
Where-Object { $_ -match "^${majorVersion}\.${minorVersion}\.${latestRevision}(-\w+\d*)?$" } |
ForEach-Object {
if ($_.Contains('-'))
{
$preReleasePart = $_.Split('-')[1]
if ($preRelease -ne $null -and $preReleasePart.StartsWith($preRelease))
{
$latestPreRelease = [Math]::Max($latestPreRelease, $preReleasePart.Substring($preRelease.Length))
}
}
else
{
$hasRelease = $true
}
}
$currentRevision = if ($hasRelease) { $latestRevision + 1 } else { $latestRevision }
if ($preRelease -ne $null)
{
$assemblyVersion = "${majorVersion}.${minorVersion}.$($preReleaseOffset + $latestPreRelease + 1).${currentRevision}"
$packageVersion = "${majorVersion}.${minorVersion}.${currentRevision}-${preRelease}$($latestPreRelease + 1)"
}
else
{
$assemblyVersion = "${majorVersion}.${minorVersion}.0.$($currentRevision)"
$packageVersion = "${majorVersion}.${minorVersion}.$($currentRevision)"
}
$description = (Select-Xml -Path ./CloudStub/CloudStub.csproj -XPath "//Project/PropertyGroup/Description/text()").Node.Data.Trim()
$releaseNotes = (
(Select-Xml -Path ./CloudStub/CloudStub.csproj -XPath "//Project/PropertyGroup/PackageReleaseNotes/text()").Node.Data -split '\r?\n\r?' |
Where-Object { -not [string]::IsNullOrWhiteSpace($_) } |
Foreach-Object { $_.Trim() }
) -join '%0A'
Write-Host "::set-output name=package_version::$packageVersion"
Write-Host "::set-output name=assembly_version::$assemblyVersion"
Write-Host "::set-output name=package_description::$description"
Write-Host "::set-output name=package_release_notes::$releaseNotes"
Write-Host "::set-output name=is_pre_release::$(($preRelease -ne $null).ToString().ToLowerInvariant())"
[System.IO.File]::WriteAllBytes([System.IO.Path]::Combine((pwd), "CloudStub.snk"), [Convert]::FromBase64String("${{ secrets.KeyFile }}"))
- name: Push Tag
if: startsWith(github.ref, 'refs/heads/releases/')
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CUSTOM_TAG : ${{ steps.package_info.outputs.package_version }}
RELEASE_BRANCHES: releases/*

- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.101

- name: Install Dependencies
run: dotnet restore

- name: Build
run: dotnet build --configuration Release --no-restore

- name: Test
run: dotnet test --configuration Release --no-restore --verbosity normal

- name: Pack
if: startsWith(github.ref, 'refs/heads/releases/')
shell: pwsh
run: |
dotnet pack CloudStub.sln `
--configuration Release `
--output publish `
-property:Version=${{ steps.package_info.outputs.assembly_version }} `
-property:PackageVersion=${{ steps.package_info.outputs.package_version }} `
-property:RepositoryCommit=$env:GITHUB_SHA `
-property:SignAssembly=True `
-property:AssemblyOriginatorKeyFile=../CloudStub.snk
- name: Create Release
if: startsWith(github.ref, 'refs/heads/releases/')
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.package_info.outputs.package_version }}
release_name: Release ${{ steps.package_info.outputs.package_version }}
body: |
${{ steps.package_info.outputs.package_description }}
Release Notes
-------------
${{ steps.package_info.outputs.package_release_notes }}
draft: true
prerelease: ${{ steps.package_info.outputs.is_pre_release }}

- name: Upload NuGet Package to Release
if: startsWith(github.ref, 'refs/heads/releases/')
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./publish/CloudStub.${{ steps.package_info.outputs.package_version }}.nupkg
asset_name: CloudStub.${{ steps.package_info.outputs.package_version }}.nupkg
asset_content_type: application/zip
19 changes: 18 additions & 1 deletion CloudStub/CloudStub.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.6</TargetFramework>
<Authors>Andrei15193</Authors>
<Description>An in-memory implementation of Azure Cloud Storage Services useful for testing.</Description>
<Copyright>Andrei15193</Copyright>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>logo.png</PackageIcon>
<PackageReleaseNotes>
* Added InMemoryCloudTable
</PackageReleaseNotes>
<PackageTags>stub;azure;storage;memory;in-memory;test</PackageTags>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/Andrei15193/CloudStub.git</RepositoryUrl>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
</ItemGroup>

<ItemGroup>
<None Include="..\LICENSE" Pack="true" PackagePath=""/>
<None Include="..\logo.png" Pack="true" PackagePath=""/>
</ItemGroup>

</Project>
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 57b4817

Please sign in to comment.