Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions .github/workflows/ps-ce-sdk-release.yaml
Original file line number Diff line number Diff line change
@@ -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

13 changes: 11 additions & 2 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -131,4 +138,6 @@ if ($TestsType -eq 'integration' -or $TestsType -eq 'all') {
# 6. Set exit code
if ($ExitProcess.IsPresent) {
exit $failedTests
} else {
$failedTests
}
47 changes: 47 additions & 0 deletions publish.ps1
Original file line number Diff line number Diff line change
@@ -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