Skip to content

Commit ccaaf6f

Browse files
authored
Create keyfactor-extension-prerelease.yml
1 parent bd79a1e commit ccaaf6f

File tree

1 file changed

+162
-0
lines changed

1 file changed

+162
-0
lines changed
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# This workflow will build a Release Candidate (pre-release)
2+
# It runs automatically when attempting a PR from pre-release branch to the release branch
3+
4+
name: Keyfactor Extension - Release Candidate
5+
6+
env:
7+
SOLUTION_FOLDER: '.'
8+
PROJECT_FOLDER: 'IISWithBindings'
9+
10+
# Controls when the action will run.
11+
on:
12+
# Triggers the workflow on PR open
13+
pull_request:
14+
types: [opened, synchronize]
15+
# only run this workflow when opening PR to release branch
16+
branches:
17+
- '!release-[0-9]+.[0-9]+-pre'
18+
- 'release-[0-9]+.[0-9]+'
19+
20+
# Release Candidate can be triggered manually
21+
workflow_dispatch:
22+
23+
jobs:
24+
# This workflow contains a single job called "build"
25+
build:
26+
# The type of runner that the job will run on
27+
runs-on: windows-latest
28+
29+
# Steps represent a sequence of tasks that will be executed as part of the job
30+
steps:
31+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
32+
- uses: actions/checkout@v2
33+
34+
- name: Setup Envrionment
35+
id: setup_env
36+
run: |
37+
echo "Setup Envrionment Variables for Workflow"
38+
echo "Working Path: ${Env:GITHUB_WORKSPACE}"
39+
$slnPath = (Get-ChildItem -Include *.sln -File -Recurse).fullname
40+
$relName = "${{ github.base_ref }}".Split("/")
41+
$repoName = "${{ github.repository }}".Split("/")
42+
$relVersion = "${{ github.base_ref }}".Split("-")
43+
echo "Solution File Path: ${slnPath}"
44+
echo "SOLUTION_PATH=${slnPath}" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
45+
echo "Release Name: $($relName[-1])"
46+
echo "RELEASE_NAME=$($relName[-1])" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
47+
echo "Repo Name: $($repoName[-1])"
48+
echo "REPO_NAME=$($repoName[-1])" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
49+
echo "Release Version: $($relVersion[-1])"
50+
echo "RELEASE_VERSION=$($relVersion[-1])" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
51+
52+
- uses: actions/setup-dotnet@v1
53+
with:
54+
dotnet-version: '3.1.x' # SDK Version to use; x will use the latest version of the 3.1 channel
55+
#dotnet-version:
56+
57+
- name: Add Package Source
58+
run: |
59+
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
60+
61+
# Configures msbuild path envrionment
62+
- name: setup-msbuild
63+
uses: microsoft/setup-msbuild@v1
64+
65+
# Restores Packages to Local Machine
66+
- name: restore nuget packages
67+
run: |
68+
nuget restore ${{ env.SOLUTION_PATH }}
69+
70+
- name: GitHub Script checks for existing version tags
71+
id: existing_version
72+
uses: actions/[email protected]
73+
env:
74+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75+
VERSION_NUMBER: ${{ env.RELEASE_VERSION }}
76+
with:
77+
script: |
78+
// check for existing tags on this major.minor version
79+
const tagsList = await github.git.listMatchingRefs({
80+
owner: context.repo.owner,
81+
repo: context.repo.repo,
82+
ref: 'tags'
83+
});
84+
85+
const { VERSION_NUMBER } = process.env;
86+
const tags = tagsList.data.reverse();
87+
88+
// assume linear release pattern - i.e. always working on latest major.minor version
89+
// if there are no tags, or latest tag does not start with VERSION_NUMBER, set a manual version for release
90+
if (tags.length < 1
91+
|| !tags.shift().ref.startsWith(`refs/tags/${VERSION_NUMBER}`)) {
92+
core.exportVariable('MANUAL_VERSION', `${VERSION_NUMBER}.0-rc.0`);
93+
}
94+
95+
# Create a new release to auto-increment (or use manual version number)
96+
- name: Create new release
97+
id: create_release
98+
#uses: zendesk/action-create-release@v1
99+
uses: keyfactor/action-create-release@786b73035fa09790f9eb11bb86834a6d7af1c256
100+
env:
101+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
102+
MANUAL_VERSION: ${{ env.MANUAL_VERSION }}
103+
with:
104+
release_name: Release Candidate ${{ env.REPO_NAME }} ${{ env.RELEASE_VERSION }}
105+
body: |
106+
[Changelog](../CHANGELOG.MD)
107+
draft: false
108+
prerelease: true
109+
prerelease_suffix: rc
110+
tag_name: ${{ env.MANUAL_VERSION }}
111+
auto_increment_type: prerelease
112+
tag_schema: semantic
113+
commitish: ${{ github.sha }}
114+
115+
# update version number of AssemblyInfo.cs file
116+
- name: Increment Assembly Version
117+
run: |
118+
$VersionRegex = "\d+\.\d+\.\d+"
119+
$assemblyInfoFiles = (Get-ChildItem -Include AssemblyInfo.cs -File -Recurse).fullname
120+
$newVer = "${{ steps.create_release.outputs.current_tag }}".TrimStart('v').Split('-')[0]
121+
echo "Prepared to overwrite Assembly version to: ${newVer}"
122+
foreach ($assemblyInfoFile in $assemblyInfoFiles)
123+
{
124+
$filecontent = Get-Content($assemblyInfoFile)
125+
attrib $assemblyInfoFile -r
126+
$filecontent -replace $VersionRegex, $newVer | Out-File $assemblyInfoFile
127+
}
128+
129+
# Runs a set of commands using the runners shell
130+
- name: Execute MSBuild Commands
131+
run: |
132+
MSBuild.exe $Env:SOLUTION_PATH -p:RestorePackagesConfig=true -p:Configuration=Release
133+
134+
- name: Archive Files
135+
run: |
136+
md ${{ github.workspace }}\zip\Keyfactor
137+
Compress-Archive -Path `
138+
${{ env.SOLUTION_FOLDER }}\${{ env.PROJECT_FOLDER }}\bin\Release\netcoreapp3.1\* `
139+
-DestinationPath ${{ github.workspace }}\zip\Keyfactor\$Env:REPO_NAME.zip -Force
140+
141+
142+
- name: Upload a Build Artifact
143+
uses: actions/[email protected]
144+
with:
145+
# Artifact name
146+
name: ${{ env.REPO_NAME }}.zip
147+
# A file, directory or wildcard pattern that describes what to upload
148+
path: |
149+
${{ github.workspace }}\zip\Keyfactor\${{ env.REPO_NAME}}.zip
150+
# The desired behavior if no files are found using the provided path.
151+
if-no-files-found: error # optional, default is warn
152+
153+
- name: Upload Release Asset (x64)
154+
id: upload-release-asset-x64
155+
uses: actions/upload-release-asset@v1
156+
env:
157+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
158+
with:
159+
upload_url: ${{ steps.create_release.outputs.upload_url }}
160+
asset_path: ${{ github.workspace }}\zip\Keyfactor\${{ env.REPO_NAME}}.zip
161+
asset_name: ${{ env.REPO_NAME}}_${{ steps.create_release.outputs.current_tag }}.zip
162+
asset_content_type: application/zip

0 commit comments

Comments
 (0)