Merge pull request #34 from dmilov/topic/publish-script

Implement release workflow trigerred on a tag create
This commit is contained in:
dmilov 2021-06-08 14:30:01 +03:00 committed by GitHub
commit c047c133fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 146 additions and 2 deletions

View File

@ -0,0 +1,88 @@
# **************************************************************************
# Copyright (c) Cloud Native Foundation.
# SPDX-License-Identifier: Apache-2.0
# **************************************************************************
name: Release
on:
create:
tags:
- v*
workflow_dispatch:
jobs:
psgallery-publish:
name: Release CloudEvents.Sdk Module
runs-on: "ubuntu-latest"
env:
OUTPUT_DIR: release
CHANGE_LOG_FILE_NAME: RELEASE_CHANGELOG.md
timeout-minutes: 10
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Build and Test
shell: pwsh
run: ./build.ps1 -OutputDir $env:OUTPUT_DIR -TestsType all -ExitProcess
- name: Publish to PSGallery
shell: pwsh
run: ./publish.ps1 -ModuleReleaseDir $env:OUTPUT_DIR -NuGetApiKey ${{ secrets.CLOUDEVENTS_SDK_PUBLISHER_API_KEY }}
- name: Create CHANGELOG
env:
IMAGE: quay.io/git-chglog/git-chglog
# https://quay.io/repository/git-chglog/git-chglog from tag v0.14.2
IMAGE_SHA: 998e89dab8dd8284cfff5f8cfb9e9af41fe3fcd4671f2e86a180e453c20959e3
run: |
# generate CHANGELOG for this Github release tag only
docker run --rm -v $PWD:/workdir ${IMAGE}@sha256:${IMAGE_SHA} -o ${CHANGE_LOG_FILE_NAME} $(basename "${{ github.ref }}" )
- name: Create Github Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release create $(basename "${{ github.ref }}") -F ${CHANGE_LOG_FILE_NAME}
changelog-pull-request:
needs: psgallery-publish
name: Create CHANGELOG PR
runs-on: ubuntu-latest
continue-on-error: true
env:
CHANGE_LOG_FILE_NAME: CHANGELOG.md
steps:
- name: Checkout
uses: actions/checkout@v2
with:
# for changelog
fetch-depth: 0
ref: "main"
- name: Create CHANGELOG commit
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
IMAGE: quay.io/git-chglog/git-chglog
# https://quay.io/repository/git-chglog/git-chglog from tag v0.14.2
IMAGE_SHA: 998e89dab8dd8284cfff5f8cfb9e9af41fe3fcd4671f2e86a180e453c20959e3
run: |
# update CHANGELOG.md
docker run --rm -v $PWD:/workdir ${IMAGE}@sha256:${IMAGE_SHA} -o ${CHANGE_LOG_FILE_NAME}
git config user.email "${{ github.actor }}@users.noreply.github.com"
git config user.name "${{ github.actor }}"
git add ${CHANGE_LOG_FILE_NAME}
git commit -m "Update CHANGELOG for $(basename ${{ github.ref }})"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
with:
delete-branch: true
title: "Update CHANGELOG"
body: |
Update CHANGELOG.md for new release

View File

@ -42,7 +42,14 @@ $moduleName = 'CloudEvents.Sdk'
#region Input
if (-not $OutputDir) {
$OutputDir = $PSScriptRoot
$OutputDir = $PSScriptRoot
}
# Create Output Dir if it doesn't exist
if (-not (Test-Path $OutputDir)) {
New-Item -ItemType Directory -Path $OutputDir -Force -Confirm:$false | Out-Null
# Get the full path
$OutputDir = (Resolve-Path $OutputDir).Path
}
$OutputDir = Join-Path $OutputDir $moduleName
@ -112,7 +119,7 @@ Test-BuildToolsAreAvailable
# 2. Publish CloudEvents Module
Write-InfoLog "Publish CloudEvents.Sdk Module to '$OutputDir'"
dotnet publish -c Release -o $OutputDir $dotnetProjectPath
dotnet publish -c Release -o $OutputDir $dotnetProjectPath | Out-Null
# 3. Cleanup Unnecessary Outputs
Get-ChildItem "$dotnetProjectName*" -Path $OutputDir | Remove-Item -Confirm:$false
@ -131,4 +138,6 @@ if ($TestsType -eq 'integration' -or $TestsType -eq 'all') {
# 6. Set exit code
if ($ExitProcess.IsPresent) {
exit $failedTests
} else {
$failedTests
}

47
publish.ps1 Normal file
View File

@ -0,0 +1,47 @@
# **************************************************************************
# Copyright (c) Cloud Native Foundation.
# SPDX-License-Identifier: Apache-2.0
# **************************************************************************
<#
.SYNOPSIS
Publish the CloudEvents.Sdk module to PSGallery
.PARAMETER NuGetApiKey
PowerShell Gallery API Key to be used to publish the module
.PARAMETER ModuleReleaseDir
Parent directory of the 'CloudEvents.Sdk' module that will be published
#>
param(
[Parameter(Mandatory = $true)]
[string]
$NuGetApiKey,
[Parameter(Mandatory = $true)]
[ValidateScript({ Test-Path $_ })]
[string]
$ModuleReleaseDir
)
# Work with full path in case relative path is provided
$ModuleReleaseDir = (Resolve-Path $ModuleReleaseDir).Path
$moduleName = 'CloudEvents.Sdk'
# Build is successful and all tests pass
$env:PSModulePath += [IO.Path]::PathSeparator + $ModuleReleaseDir
$localModule = Get-Module $moduleName -ListAvailable
$psGalleryModule = Find-Module -Name $moduleName -Repository PSGallery
# Throw an exception if module with the same version is availble on PSGallery
if ( $null -ne $psGalleryModule -and `
$null -ne $localModule -and `
$psGalleryModule.Version -eq $localModule.Version ) {
throw "'$moduleName' module with version '$($localModule.Version)' is already available on PSGallery"
}
Write-Host "Performing operation: Publish-Module -Name $moduleName -RequiredVersion $($localModule.Version) -NuGetApiKey *** -Repository PSGallery -Confirm:`$false"
Publish-Module -Name $moduleName -RequiredVersion $localModule.Version -NuGetApiKey $NuGetApiKey -Repository PSGallery -Confirm:$false -ErrorAction Stop