Skip to content

Commit 90430f5

Browse files
authored
Create keyfactor-extension-release.yml
1 parent 6770003 commit 90430f5

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# This is a basic workflow to help you get started with Actions
2+
3+
name: Keyfactor Extension - Release
4+
5+
env:
6+
SOLUTION_FOLDER: '<SOLUTION_FOLDER_NAME>'
7+
PROJECT_FOLDER: '<PROJECT_FOLDER_NAME>'
8+
9+
# Controls when the action will run.
10+
on:
11+
# Triggers the workflow on pull requests closing
12+
pull_request:
13+
# only run this workflow when closing a PR to a branch that contains a release number. ignore -pre
14+
branches:
15+
- 'release-[0-9]+.[0-9]+'
16+
- '!release-[0-9]+.[0-9]+-pre'
17+
types: [closed]
18+
19+
# Allows you to run this workflow manually from the Actions tab
20+
workflow_dispatch:
21+
22+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
23+
jobs:
24+
# This workflow contains a single job called "build"
25+
build:
26+
# run if pull request is completed and merged, or if manually dispatched
27+
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true)
28+
29+
# The type of runner that the job will run on
30+
runs-on: windows-latest
31+
32+
# Steps represent a sequence of tasks that will be executed as part of the job
33+
steps:
34+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
35+
- uses: actions/checkout@v2
36+
37+
- name: Setup Envrionment
38+
id: setup_env
39+
run: |
40+
echo "Setup Envrionment Variables for Workflow"
41+
echo "Working Path: ${Env:GITHUB_WORKSPACE}"
42+
$slnPath = (Get-ChildItem -Include *.sln -File -Recurse).fullname
43+
$relName = "${{ github.ref }}".Split("/")
44+
$repoName = "${{ github.repository }}".Split("/")
45+
$relVersion = "${{ github.ref }}".Split("-")
46+
echo "Solution File Path: ${slnPath}"
47+
echo "SOLUTION_PATH=${slnPath}" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
48+
echo "Release Name: $($relName[-1])"
49+
echo "RELEASE_NAME=$($relName[-1])" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
50+
echo "Repo Name: $($repoName[-1])"
51+
echo "REPO_NAME=$($repoName[-1])" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
52+
echo "Release Version: $($relVersion[-1])"
53+
echo "RELEASE_VERSION=$($relVersion[-1])" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
54+
55+
- uses: actions/setup-dotnet@v1
56+
with:
57+
dotnet-version: '3.1.x' # SDK Version to use; x will use the latest version of the 3.1 channel
58+
#dotnet-version:
59+
60+
- name: Add Package Source
61+
run: |
62+
dotnet nuget add source https://nuget.pkg.github.com/Keyfactor/index.json -n github -u ${{ github.actor }} -p ${{ secrets.BUILD_PACKAGE_ACCESS }} --store-password-in-clear-text
63+
64+
# Configures msbuild path envrionment
65+
- name: setup-msbuild
66+
uses: microsoft/setup-msbuild@v1
67+
68+
# Restores Packages to Local Machine
69+
- name: restore nuget packages
70+
run: |
71+
nuget restore ${{ env.SOLUTION_PATH }}
72+
73+
- name: Create Release
74+
id: create_release
75+
#uses: zendesk/action-create-release@v1
76+
uses: keyfactor/action-create-release@786b73035fa09790f9eb11bb86834a6d7af1c256
77+
env:
78+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79+
with:
80+
release_name: ${{ env.REPO_NAME }} ${{ env.RELEASE_VERSION }}
81+
body: |
82+
[Changelog](../CHANGELOG.MD)
83+
draft: false
84+
prerelease: false
85+
auto_increment_type: patch
86+
tag_schema: semantic
87+
commitish: ${{ github.sha }}
88+
89+
# update version number of AssemblyInfo.cs file
90+
- name: Increment Assembly Version
91+
run: |
92+
$VersionRegex = "\d+\.\d+\.\d+"
93+
$assemblyInfoFiles = (Get-ChildItem -Include AssemblyInfo.cs -File -Recurse).fullname
94+
$newVer = "${{ steps.create_release.outputs.current_tag }}".TrimStart('v').Split('-')[0]
95+
echo "Prepared to overwrite Assembly version to: ${newVer}"
96+
foreach ($assemblyInfoFile in $assemblyInfoFiles)
97+
{
98+
$filecontent = Get-Content($assemblyInfoFile)
99+
attrib $assemblyInfoFile -r
100+
$filecontent -replace $VersionRegex, $newVer | Out-File $assemblyInfoFile
101+
}
102+
103+
- name: Execute MSBuild Commands
104+
run: |
105+
MSBuild.exe $Env:SOLUTION_PATH -p:RestorePackagesConfig=false -p:Configuration=Release
106+
107+
- name: Archive Files
108+
if: ${{ success() }}
109+
run: |
110+
md ${{ github.workspace }}\zip\Keyfactor
111+
Compress-Archive -Path `
112+
${{ env.SOLUTION_FOLDER }}\${{ env.PROJECT_FOLDER }}\bin\Release\*.dll, `
113+
${{ env.SOLUTION_FOLDER }}\${{ env.PROJECT_FOLDER }}\bin\Release\*.json, `
114+
${{ env.SOLUTION_FOLDER }}\${{ env.PROJECT_FOLDER }}\bin\Release\*.config `
115+
-DestinationPath ${{ github.workspace }}\zip\Keyfactor\$Env:REPO_NAME.zip -Force
116+
117+
- name: Upload Release Asset (x64)
118+
if: ${{ success() }}
119+
id: upload-release-asset-x64
120+
uses: actions/upload-release-asset@v1
121+
env:
122+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
123+
with:
124+
upload_url: ${{ steps.create_release.outputs.upload_url }}
125+
asset_path: ${{ github.workspace }}\zip\Keyfactor\${{ env.REPO_NAME}}.zip
126+
asset_name: ${{ env.REPO_NAME}}_${{ steps.create_release.outputs.current_tag }}.zip
127+
asset_content_type: application/zip
128+
129+
- name: On Failure - Remove Tags and Release
130+
if: ${{ failure() }}
131+
uses: dev-drprasad/[email protected]
132+
with:
133+
delete_release: true # default: false
134+
tag_name: ${{ steps.create_release.outputs.current_tag }}
135+
env:
136+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)