Merge pull request #40 from nfMalde/2.0.x #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release 1.2.x | |
on: | |
push: | |
branches: [ release-2.0.x ] | |
jobs: | |
test: | |
runs-on: windows-latest | |
steps: | |
- name: Checkout Sources | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Setup .NET 8 | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: 8.0.x | |
- name: "Build and Test" | |
run: | | |
dotnet build | |
dotnet test | |
prepublish: | |
needs: test | |
runs-on: windows-latest | |
outputs: | |
description: ${{ steps.meta.outputs.description }} | |
changeinfo: ${{ steps.meta.outputs.changeinfo }} | |
version: ${{ steps.v.outputs.version }} | |
steps: | |
- name: Checkout Sources | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name : Get Meta Data | |
shell: pwsh | |
id: meta | |
run: | | |
[xml]$xml = get-content "src\AspNetCore.MailKitMailer\AspNetCore.MailKitMailer.csproj" | |
$description = $xml.SelectSingleNode("//Description").InnerText; | |
$changes = $xml.SelectSingleNode("//PackageReleaseNotes").InnerText; | |
Write-Output "::set-output name=description::$($description.Trim().Replace("`t", '') | ConvertTo-Json)" | |
Write-Output "::set-output name=changeinfo::$($changes.Trim().Replace("`t", '') | ConvertTo-Json)" | |
- name: Generate Version Number | |
shell: pwsh | |
id: v | |
run: | | |
# Check if we are on a version branch or release branch (eg. 1.1.x or release-1.1.x) | |
$currentBranch = $Env:GITHUB_REF_NAME | |
$isReleaseBranch = ("$($currentBranch)").StartsWith("release-"); | |
$parsedBranchName = $currentBranch; | |
if ($isReleaseBranch) { | |
Write-Host "We are on release branch. Versioning will be permanent" | |
$parsedBranchName = ("$($currentBranch)").Substring(("release-").Length) | |
} | |
if ($parsedBranchName.StartsWith('v')) { | |
$parsedBranchName = $parsedBranchName.Substring(1) | |
} | |
$isVersionBranch = $parsedBranchName -match "(\d+.\d+.x)" | |
if (!$isVersionBranch) { | |
Write-Host "Canceling. Not a version branch" | |
return 0 | |
} | |
$versionParts = $parsedBranchName.Split('.') | |
$versionPrefix = "$($versionParts[0]).$($versionParts[1])" | |
$startVersion = [version]::Parse("$($versionPrefix).0") | |
# Get Git Tags | |
$gitTags = @(git tag --list --sort=-version:refname "v$($versionPrefix).*") | |
$newVersion = [version]::Parse("$($startVersion.Major).$($startVersion.Minor).$($startVersion.Build)") | |
Write-Host "Tags: $($gitTags)" | |
if ($gitTags.Length -gt 0) { | |
if ($gitTags[0][0] -eq "v") { | |
$latest = ("$($gitTags[0])").Substring(1) | |
Write-Host "Latest Tag is $($latest)" | |
$versionInfo = [Version]::Parse($latest) | |
if ($versionInfo) { | |
Write-Host "Version Parsed: $($versionInfo.Major).$($versionInfo.Minor).$($versionInfo.Build)." | |
$newVersion = [version]::Parse("$($versionInfo.Major).$($versionInfo.Minor).$($versionInfo.Build+1)") | |
} | |
} | |
} | |
Write-Host "New Version is $($newVersion.Major).$($newVersion.Minor).$($newVersion.Build)" | |
Write-Output "::set-output name=version::$($newVersion.Major).$($newVersion.Minor).$($newVersion.Build)" | |
- name: Print Version | |
run: echo '${{ steps.v.outputs.version }}' | |
publish: | |
needs: prepublish | |
if: ${{ needs.prepublish.outputs.version && needs.prepublish.outputs.version != ''}} | |
runs-on: windows-latest | |
steps: | |
- name: Checkout Sources | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Print Description | |
id: printdescription | |
run: echo '${{fromJSON(needs.prepublish.outputs.description)}}' | |
- name: Print Change Info | |
run: echo '${{fromJSON(needs.prepublish.outputs.changeinfo) }}' | |
- name: Create Release and Tag | |
id: create_release | |
uses: actions/create-release@latest | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token | |
with: | |
tag_name: v${{ needs.prepublish.outputs.version }} | |
release_name: Release v${{ needs.prepublish.outputs.version }} | |
body: | | |
# Info | |
${{fromJSON(needs.prepublish.outputs.description)}} | |
# Changes in v${{ needs.prepublish.outputs.version }} | |
${{fromJSON(needs.prepublish.outputs.changeinfo)}} | |
draft: false | |
prerelease: false | |
- name: Setup .NET 8 | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: 8.0.x | |
- name: Create Package | |
run: | | |
dotnet build src/AspNetCore.MailKitMailer/AspNetCore.MailKitMailer.csproj -c Release -p:AssemblyVersion=${{ needs.prepublish.outputs.version }} -p:PackageVersion=${{ needs.prepublish.outputs.version }} | |
dotnet pack src/AspNetCore.MailKitMailer/AspNetCore.MailKitMailer.csproj -c Release -p:AssemblyVersion=${{ needs.prepublish.outputs.version }} -p:PackageVersion=${{ needs.prepublish.outputs.version }} --output nget_pkg | |
- name: Upload Release Asset Pkg | |
id: upload-release-asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps | |
asset_path: ./nget_pkg/AspNetCore.MailKitMailer.${{ needs.prepublish.outputs.version }}.nupkg | |
asset_name: AspNetCore.MailKitMailer.${{ needs.prepublish.outputs.version }}.nupkg | |
asset_content_type: application/zip | |
- name: Upload Release Asset DLL | |
id: upload-release-asset2 | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps | |
asset_path: src/AspNetCore.MailKitMailer/bin/Release/net8.0/AspNetCore.MailKitMailer.dll | |
asset_name: AspNetCore.MailKitMailer.dll | |
asset_content_type: application/octet-stream | |
- name: Publish package to nuget | |
id: nugetpush | |
run: dotnet nuget push "nget_pkg/AspNetCore.MailKitMailer.${{ needs.prepublish.outputs.version }}.nupkg" -k ${{secrets.NUGET_KEY}} -s https://api.nuget.org/v3/index.json |