generated from IT-Service/PowerShell-GitHub-Action-template
-
Notifications
You must be signed in to change notification settings - Fork 0
146 lines (135 loc) · 7.07 KB
/
github-release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
name: Release to GihHub
on:
push:
# branches:
# - master
tags:
- "[0-9]+.[0-9]+.[0-9]+"
permissions:
actions: read
contents: write
deployments: write
issues: write
jobs:
release:
name: Release to GihHub
runs-on: windows-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install required PowerShell and NuGet modules
shell: powershell
run: |
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted;
Register-PackageSource -Name 'nuget.org' -Location 'https://api.nuget.org/v3/index.json' -ProviderName NuGet -Trusted -Force | Out-Null;
Install-Module -Name PowerShellForGitHub -Verbose | Out-Null;
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0.9.13
with:
versionSpec: "5.x"
- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/execute@v0.9.13
with:
useConfigFile: true
- name: Generate release notes
id: generate_release_notes
shell: powershell
run: |
$releaseNotesPath = 'ReleaseNotes.md';
$ChangeLog = ( Get-Content -Path './CHANGELOG.md' -Encoding UTF8 );
$releaseNotes = @( $ChangeLog | ForEach-Object `
-Begin {
$isExpectedSection = $false;
} `
-Process {
$isReleaseSectionHeader = ( $_ -match '##\s+(?:(?<version>\d+\.\d+\.\d+)|\[(?<version>\d+\.\d+\.\d+)\])' );
if ( $isReleaseSectionHeader ) {
$releaseVersion = $Matches[ 'version' ];
$isExpectedSection = ( $releaseVersion -eq '${{ steps.gitversion.outputs.semVer }}' );
} else {
if ( $isExpectedSection ) { return $_; };
};
}
) -join "`r`n";
$releaseNotes | Out-File -Encoding utf8 -FilePath $releaseNotesPath -NoNewLine;
echo "::set-output name=releaseNotesPath::$releaseNotesPath";
- name: Search GitHub Milestone
id: milestone_search
shell: powershell
run: |
Import-Module -Name PowerShellForGitHub | Out-Null;
Write-Verbose 'Configure PowerShellForGitHub...';
$GitHubToken = ( ConvertTo-SecureString -String '${{ github.token }}' -AsPlainText -Force );
Set-GitHubAuthentication -Credential ( New-Object System.Management.Automation.PSCredential 'username is ignored', $GitHubToken ) -SessionOnly;
Set-GitHubConfiguration -DefaultOwnerName '${{ github.repository_owner }}' -DefaultRepositoryName '${{ github.event.repository.name }}' -SessionOnly;
$milestones = Get-GitHubMilestone `
-OwnerName '${{ github.repository_owner }}' -RepositoryName '${{ github.event.repository.name }}' `
-State All;
$currentMilestone = $milestones | Where-Object -Property title -EQ '${{ steps.gitversion.outputs.semVer }}';
if ( $currentMilestone ) {
echo "::set-output name=exists::${{ true }}";
echo "::set-output name=url::$( $currentMilestone.html_url )";
echo "::set-output name=title::$( $currentMilestone.title )";
echo "::set-output name=number::$( $currentMilestone.MilestoneNumber )";
} else {
echo "::set-output name=exists::${{ false }}";
};
- name: Create GitHub Release
id: release
shell: powershell
run: |
Import-Module -Name PowerShellForGitHub | Out-Null;
Write-Verbose 'Configure PowerShellForGitHub...';
$GitHubToken = ( ConvertTo-SecureString -String '${{ github.token }}' -AsPlainText -Force );
Set-GitHubAuthentication -Credential ( New-Object System.Management.Automation.PSCredential 'username is ignored', $GitHubToken ) -SessionOnly;
Set-GitHubConfiguration -DefaultOwnerName '${{ github.repository_owner }}' -DefaultRepositoryName '${{ github.event.repository.name }}' -SessionOnly;
$releaseNotes = ( Get-Content -Path '${{ steps.generate_release_notes.outputs.releaseNotesPath }}' -Encoding UTF8 -Raw );
if ( $${{ steps.milestone_search.outputs.exists == 'true' }} ) {
$releaseDescription = `
"[![${{ steps.milestone_search.outputs.title }}](https://img.shields.io/badge/milestone-${{ steps.milestone_search.outputs.title }}-blue?style=plastic&logo=github)](${{ steps.milestone_search.outputs.url }})" +
"`r`n`r`n" + $releaseNotes;
} else {
$releaseDescription = $releaseNotes;
};
$release = Get-GitHubRelease `
-Tag '${{ steps.gitversion.outputs.semVer }}' `
-ErrorAction SilentlyContinue;
if ( $release ) {
Remove-GitHubRelease -Release ( $release.ID ) -Force;
};
$release = New-GitHubRelease `
-Tag '${{ steps.gitversion.outputs.semVer }}' `
-Name '${{ steps.gitversion.outputs.semVer }}' `
-Body $releaseDescription `
-Committish '${{ github.sha }}' `
-Verbose;
echo "::set-output name=url::$( $release.html_url )";
echo "::set-output name=tag_name::$( $release.tag_name )";
# Write-Verbose 'Adding produced files...';
# Get-ChildItem -Path 'extensions' -Filter '*.cfe' | ForEach-Object {
# $asset = New-GitHubReleaseAsset -Release ( $release.ID ) -Path ( %.FullName ) -Verbose;
# };
- name: Close GitHub Milestone
if: steps.milestone_search.outputs.exists == 'true'
shell: powershell
run: |
Import-Module -Name PowerShellForGitHub | Out-Null;
Write-Verbose 'Configure PowerShellForGitHub...';
$GitHubToken = ( ConvertTo-SecureString -String '${{ github.token }}' -AsPlainText -Force );
Set-GitHubAuthentication -Credential ( New-Object System.Management.Automation.PSCredential 'username is ignored', $GitHubToken ) -SessionOnly;
Set-GitHubConfiguration -DefaultOwnerName '${{ github.repository_owner }}' -DefaultRepositoryName '${{ github.event.repository.name }}' -SessionOnly;
$releaseNotes = ( Get-Content -Path '${{ steps.generate_release_notes.outputs.releaseNotesPath }}' -Encoding UTF8 -Raw );
$releaseDescription = `
"[![${{ steps.release.outputs.tag_name }}](https://img.shields.io/badge/release-${{ steps.release.outputs.tag_name }}-blue?style=plastic&logo=github)](${{ steps.release.outputs.url }})" +
"`r`n`r`n" + $releaseNotes;
Set-GitHubMilestone `
-OwnerName '${{ github.repository_owner }}' -RepositoryName '${{ github.event.repository.name }}' `
-Milestone ${{ steps.milestone_search.outputs.number }} `
-Title '${{ steps.gitversion.outputs.semVer }}' `
-State Closed `
-Description $releaseDescription `
-DueOn ( Get-Date ) `
-Verbose;