Skip to content

Commit c047c13

Browse files
authored
Merge pull request #34 from dmilov/topic/publish-script
Implement release workflow trigerred on a tag create
2 parents d4f8ff9 + 78b7e9e commit c047c13

File tree

3 files changed

+146
-2
lines changed

3 files changed

+146
-2
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# **************************************************************************
2+
# Copyright (c) Cloud Native Foundation.
3+
# SPDX-License-Identifier: Apache-2.0
4+
# **************************************************************************
5+
6+
name: Release
7+
8+
on:
9+
create:
10+
tags:
11+
- v*
12+
workflow_dispatch:
13+
14+
jobs:
15+
psgallery-publish:
16+
name: Release CloudEvents.Sdk Module
17+
runs-on: "ubuntu-latest"
18+
env:
19+
OUTPUT_DIR: release
20+
CHANGE_LOG_FILE_NAME: RELEASE_CHANGELOG.md
21+
22+
timeout-minutes: 10
23+
24+
steps:
25+
- name: Check out code
26+
uses: actions/checkout@v2
27+
28+
- name: Build and Test
29+
shell: pwsh
30+
run: ./build.ps1 -OutputDir $env:OUTPUT_DIR -TestsType all -ExitProcess
31+
32+
- name: Publish to PSGallery
33+
shell: pwsh
34+
run: ./publish.ps1 -ModuleReleaseDir $env:OUTPUT_DIR -NuGetApiKey ${{ secrets.CLOUDEVENTS_SDK_PUBLISHER_API_KEY }}
35+
36+
- name: Create CHANGELOG
37+
env:
38+
IMAGE: quay.io/git-chglog/git-chglog
39+
# https://quay.io/repository/git-chglog/git-chglog from tag v0.14.2
40+
IMAGE_SHA: 998e89dab8dd8284cfff5f8cfb9e9af41fe3fcd4671f2e86a180e453c20959e3
41+
run: |
42+
# generate CHANGELOG for this Github release tag only
43+
docker run --rm -v $PWD:/workdir ${IMAGE}@sha256:${IMAGE_SHA} -o ${CHANGE_LOG_FILE_NAME} $(basename "${{ github.ref }}" )
44+
45+
- name: Create Github Release
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
run: gh release create $(basename "${{ github.ref }}") -F ${CHANGE_LOG_FILE_NAME}
49+
50+
changelog-pull-request:
51+
needs: psgallery-publish
52+
name: Create CHANGELOG PR
53+
runs-on: ubuntu-latest
54+
continue-on-error: true
55+
env:
56+
CHANGE_LOG_FILE_NAME: CHANGELOG.md
57+
58+
steps:
59+
- name: Checkout
60+
uses: actions/checkout@v2
61+
with:
62+
# for changelog
63+
fetch-depth: 0
64+
ref: "main"
65+
66+
- name: Create CHANGELOG commit
67+
env:
68+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
69+
IMAGE: quay.io/git-chglog/git-chglog
70+
# https://quay.io/repository/git-chglog/git-chglog from tag v0.14.2
71+
IMAGE_SHA: 998e89dab8dd8284cfff5f8cfb9e9af41fe3fcd4671f2e86a180e453c20959e3
72+
run: |
73+
# update CHANGELOG.md
74+
docker run --rm -v $PWD:/workdir ${IMAGE}@sha256:${IMAGE_SHA} -o ${CHANGE_LOG_FILE_NAME}
75+
76+
git config user.email "${{ github.actor }}@users.noreply.github.com"
77+
git config user.name "${{ github.actor }}"
78+
git add ${CHANGE_LOG_FILE_NAME}
79+
git commit -m "Update CHANGELOG for $(basename ${{ github.ref }})"
80+
81+
- name: Create Pull Request
82+
uses: peter-evans/create-pull-request@v3
83+
with:
84+
delete-branch: true
85+
title: "Update CHANGELOG"
86+
body: |
87+
Update CHANGELOG.md for new release
88+

build.ps1

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,14 @@ $moduleName = 'CloudEvents.Sdk'
4242

4343
#region Input
4444
if (-not $OutputDir) {
45-
$OutputDir = $PSScriptRoot
45+
$OutputDir = $PSScriptRoot
46+
}
47+
48+
# Create Output Dir if it doesn't exist
49+
if (-not (Test-Path $OutputDir)) {
50+
New-Item -ItemType Directory -Path $OutputDir -Force -Confirm:$false | Out-Null
51+
# Get the full path
52+
$OutputDir = (Resolve-Path $OutputDir).Path
4653
}
4754

4855
$OutputDir = Join-Path $OutputDir $moduleName
@@ -112,7 +119,7 @@ Test-BuildToolsAreAvailable
112119

113120
# 2. Publish CloudEvents Module
114121
Write-InfoLog "Publish CloudEvents.Sdk Module to '$OutputDir'"
115-
dotnet publish -c Release -o $OutputDir $dotnetProjectPath
122+
dotnet publish -c Release -o $OutputDir $dotnetProjectPath | Out-Null
116123

117124
# 3. Cleanup Unnecessary Outputs
118125
Get-ChildItem "$dotnetProjectName*" -Path $OutputDir | Remove-Item -Confirm:$false
@@ -131,4 +138,6 @@ if ($TestsType -eq 'integration' -or $TestsType -eq 'all') {
131138
# 6. Set exit code
132139
if ($ExitProcess.IsPresent) {
133140
exit $failedTests
141+
} else {
142+
$failedTests
134143
}

publish.ps1

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# **************************************************************************
2+
# Copyright (c) Cloud Native Foundation.
3+
# SPDX-License-Identifier: Apache-2.0
4+
# **************************************************************************
5+
6+
<#
7+
.SYNOPSIS
8+
Publish the CloudEvents.Sdk module to PSGallery
9+
10+
.PARAMETER NuGetApiKey
11+
PowerShell Gallery API Key to be used to publish the module
12+
13+
.PARAMETER ModuleReleaseDir
14+
Parent directory of the 'CloudEvents.Sdk' module that will be published
15+
#>
16+
17+
param(
18+
[Parameter(Mandatory = $true)]
19+
[string]
20+
$NuGetApiKey,
21+
22+
[Parameter(Mandatory = $true)]
23+
[ValidateScript({ Test-Path $_ })]
24+
[string]
25+
$ModuleReleaseDir
26+
)
27+
28+
# Work with full path in case relative path is provided
29+
$ModuleReleaseDir = (Resolve-Path $ModuleReleaseDir).Path
30+
31+
$moduleName = 'CloudEvents.Sdk'
32+
33+
# Build is successful and all tests pass
34+
$env:PSModulePath += [IO.Path]::PathSeparator + $ModuleReleaseDir
35+
36+
$localModule = Get-Module $moduleName -ListAvailable
37+
$psGalleryModule = Find-Module -Name $moduleName -Repository PSGallery
38+
39+
# Throw an exception if module with the same version is availble on PSGallery
40+
if ( $null -ne $psGalleryModule -and `
41+
$null -ne $localModule -and `
42+
$psGalleryModule.Version -eq $localModule.Version ) {
43+
throw "'$moduleName' module with version '$($localModule.Version)' is already available on PSGallery"
44+
}
45+
46+
Write-Host "Performing operation: Publish-Module -Name $moduleName -RequiredVersion $($localModule.Version) -NuGetApiKey *** -Repository PSGallery -Confirm:`$false"
47+
Publish-Module -Name $moduleName -RequiredVersion $localModule.Version -NuGetApiKey $NuGetApiKey -Repository PSGallery -Confirm:$false -ErrorAction Stop

0 commit comments

Comments
 (0)