Skip to content

Commit

Permalink
Merge pull request #18 from Keyfactor/workflow-updates
Browse files Browse the repository at this point in the history
use branch name for setting version
  • Loading branch information
doebrowsk authored Sep 15, 2021
2 parents 7f4020a + 5e3db7a commit 51ac2d3
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 51 deletions.
121 changes: 88 additions & 33 deletions .github/workflows/keyfactor-extension-prerelease.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
# This is a basic workflow to help you get started with Actions
# This workflow will build a Release Candidate (pre-release)
# It runs automatically when attempting a PR from pre-release branch to the release branch

name: Keyfactor Extension - Pre Release
name: Keyfactor Extension - Release Candidate

env:
SOLUTION_FOLDER: '.'
PROJECT_FOLDER: 'PEMStoreSSH'

# Controls when the action will run.
on:
# Triggers the workflow on push
push:
#only run this workflow when pushing to a branch that has the prerelease suffix
# Triggers the workflow on PR open
pull_request:
types: [opened, synchronize]
# only run this workflow when opening PR to release branch
branches:
- 'release-[0-9]+.[0-9]+-pre'
- '!release-[0-9]+.[0-9]+'

# Allows you to run this workflow manually from the Actions tab
- '!release-[0-9]+.[0-9]+-pre'
- 'release-[0-9]+.[0-9]+'
# Release Candidate can be triggered manually
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
Expand All @@ -32,14 +37,17 @@ jobs:
echo "Setup Envrionment Variables for Workflow"
echo "Working Path: ${Env:GITHUB_WORKSPACE}"
$slnPath = (Get-ChildItem -Include *.sln -File -Recurse).fullname
$relName = "${{ github.ref }}".Split("/")
$relName = "${{ github.base_ref }}".Split("/")
$repoName = "${{ github.repository }}".Split("/")
$relVersion = "${{ github.base_ref }}".Split("-")
echo "Solution File Path: ${slnPath}"
echo "SOLUTION_PATH=${slnPath}" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
echo "Release Name: $($relName[-1])"
echo "RELEASE_NAME=$($relName[-1])" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
echo "Repo Name: $($repoName[-1])"
echo "REPO_NAME=$($repoName[-1])" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
echo "Release Version: $($relVersion[-1])"
echo "RELEASE_VERSION=$($relVersion[-1])" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
- uses: actions/setup-dotnet@v1
with:
Expand All @@ -58,6 +66,65 @@ jobs:
- name: restore nuget packages
run: |
nuget restore ${{ env.SOLUTION_PATH }}
- name: GitHub Script checks for existing version tags
id: existing_version
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION_NUMBER: ${{ env.RELEASE_VERSION }}
with:
script: |
// check for existing tags on this major.minor version
const tagsList = await github.git.listMatchingRefs({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'tags'
});
const { VERSION_NUMBER } = process.env;
const tags = tagsList.data.reverse();
// assume linear release pattern - i.e. always working on latest major.minor version
// if there are no tags, or latest tag does not start with VERSION_NUMBER, set a manual version for release
if (tags.length < 1
|| !tags.shift().ref.startsWith(`refs/tags/${VERSION_NUMBER}`)) {
core.exportVariable('MANUAL_VERSION', `${VERSION_NUMBER}.0-rc.0`);
}
# Create a new release to auto-increment (or use manual version number)
- name: Create new release
id: create_release
#uses: zendesk/action-create-release@v1
uses: keyfactor/action-create-release@786b73035fa09790f9eb11bb86834a6d7af1c256
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MANUAL_VERSION: ${{ env.MANUAL_VERSION }}
with:
release_name: Release Candidate ${{ env.REPO_NAME }} ${{ env.RELEASE_VERSION }}
body: |
[Changelog](../CHANGELOG.MD)
draft: false
prerelease: true
prerelease_suffix: rc
tag_name: ${{ env.MANUAL_VERSION }}
auto_increment_type: prerelease
tag_schema: semantic
commitish: ${{ github.sha }}

# update version number of AssemblyInfo.cs file
- name: Increment Assembly Version
run: |
$VersionRegex = "\d+\.\d+\.\d+"
$assemblyInfoFiles = (Get-ChildItem -Include AssemblyInfo.cs -File -Recurse).fullname
$newVer = "${{ steps.create_release.outputs.current_tag }}".TrimStart('v').Split('-')[0]
echo "Prepared to overwrite Assembly version to: ${newVer}"
foreach ($assemblyInfoFile in $assemblyInfoFiles)
{
$filecontent = Get-Content($assemblyInfoFile)
attrib $assemblyInfoFile -r
$filecontent -replace $VersionRegex, $newVer | Out-File $assemblyInfoFile
}
# Runs a set of commands using the runners shell
- name: Execute MSBuild Commands
Expand All @@ -66,38 +133,26 @@ jobs:
- name: Archive Files
run: |
md ${{ github.workspace }}\zip\Keyfactor
Compress-Archive -Path ${{ github.workspace }}\PEMStoreSSH\bin\Release\*.dll,${{ github.workspace }}\PEMStoreSSH\bin\Release\config.json -DestinationPath ${{ github.workspace }}\zip\Keyfactor\$Env:REPO_NAME.zip -Force
md ${{ github.workspace }}\zip\Keyfactor
Compress-Archive -Path `
${{ env.SOLUTION_FOLDER }}\${{ env.PROJECT_FOLDER }}\bin\Release\*.dll, `
${{ env.SOLUTION_FOLDER }}\${{ env.PROJECT_FOLDER }}\bin\Release\*.json, `
${{ env.SOLUTION_FOLDER }}\${{ env.PROJECT_FOLDER }}\bin\Release\*.config, `
${{ env.SOLUTION_FOLDER }}\${{ env.PROJECT_FOLDER }}\bin\Release\Keyfactor.Extensions.Pam.Config.exe `
-DestinationPath ${{ github.workspace }}\zip\Keyfactor\$Env:REPO_NAME.zip -Force

- name: Upload a Build Artifact
uses: actions/[email protected]
with:
# Artifact name
name: ${{ env.REPO_NAME}}.zip
name: ${{ env.REPO_NAME }}.zip
# A file, directory or wildcard pattern that describes what to upload
path: |
${{ github.workspace }}\zip\Keyfactor\${{ env.REPO_NAME}}.zip
# The desired behavior if no files are found using the provided path.
if-no-files-found: error # optional, default is warn

- name: Create Release
id: create_release
#uses: zendesk/action-create-release@v1 - Update when PR is approved
uses: keyfactor/action-create-release@786b73035fa09790f9eb11bb86834a6d7af1c256
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_name: Release ${{ env.RELEASE_NAME }}
body: |
[Changelog](../CHANGELOG.MD)
draft: false
prerelease: true
prerelease_suffix: pre
auto_increment_type: prerelease
tag_schema: semantic
commitish: ${{ github.sha }}


- name: Upload Release Asset (x64)
id: upload-release-asset-x64
uses: actions/upload-release-asset@v1
Expand All @@ -106,5 +161,5 @@ jobs:
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ github.workspace }}\zip\Keyfactor\${{ env.REPO_NAME}}.zip
asset_name: ${{ env.REPO_NAME}}.zip
asset_name: ${{ env.REPO_NAME}}_${{ steps.create_release.outputs.current_tag }}.zip
asset_content_type: application/zip
50 changes: 32 additions & 18 deletions .github/workflows/keyfactor-extension-release.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# This is a basic workflow to help you get started with Action
# This is a basic workflow to help you get started with Actions

name: Keyfactor Extension - Release

env:
SOLUTION_FOLDER: '.'
PROJECT_FOLDER: 'PEMStoreSSH'

# Controls when the action will run.
on:
# Triggers the workflow on pull requests closing
pull_request:
# only run this workflow when closing a PR to a branch that contains a release number. ignore -pre
branches:
- 'release-[0-9]+.[0-9]+'
- '!release-[0-9]+.[0-9]+-pre'
- '!release-[0-9]+.[0-9]+-pre'
types: [closed]

# Allows you to run this workflow manually from the Actions tab
Expand All @@ -19,7 +23,7 @@ on:
jobs:
# This workflow contains a single job called "build"
build:
# run if pull request is completed and merged, or if manually dispatched
# run if pull request is completed and merged, or if manually dispatched
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true)

# The type of runner that the job will run on
Expand All @@ -38,12 +42,15 @@ jobs:
$slnPath = (Get-ChildItem -Include *.sln -File -Recurse).fullname
$relName = "${{ github.ref }}".Split("/")
$repoName = "${{ github.repository }}".Split("/")
$relVersion = "${{ github.ref }}".Split("-")
echo "Solution File Path: ${slnPath}"
echo "SOLUTION_PATH=${slnPath}" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
echo "Release Name: $($relName[-1])"
echo "RELEASE_NAME=$($relName[-1])" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
echo "Repo Name: $($repoName[-1])"
echo "REPO_NAME=$($repoName[-1])" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
echo "Release Version: $($relVersion[-1])"
echo "RELEASE_VERSION=$($relVersion[-1])" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
- uses: actions/setup-dotnet@v1
with:
Expand All @@ -62,34 +69,36 @@ jobs:
- name: restore nuget packages
run: |
nuget restore ${{ env.SOLUTION_PATH }}
- name: Create Release
id: create_release
#uses: zendesk/action-create-release@v1 - Update when PR is approved
#uses: zendesk/action-create-release@v1
uses: keyfactor/action-create-release@786b73035fa09790f9eb11bb86834a6d7af1c256
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_name: Release ${{ env.RELEASE_NAME }}
release_name: ${{ env.REPO_NAME }} ${{ env.RELEASE_VERSION }}
body: |
Changes in this Release
- First Change
- Second Change
[Changelog](../CHANGELOG.MD)
draft: false
prerelease: false
auto_increment_type: patch
tag_schema: semantic
commitish: ${{ github.sha }}
commitish: ${{ github.sha }}

#update version number of AssemblyInfo.cs file
# update version number of AssemblyInfo.cs file
- name: Increment Assembly Version
run: |
$VersionRegex = "\d+\.\d+\.\d+"
$assemlyFilePath = (Get-ChildItem -Include AssemblyInfo.cs -File -Recurse).fullname
$filecontent = Get-Content($assemlyFilePath)
$newVer = "${{ steps.create_release.outputs.current_tag }}".TrimStart('v')
attrib $assemlyFilePath -r
$filecontent -replace $VersionRegex, $newVer | Out-File $assemlyFilePath
$assemblyInfoFiles = (Get-ChildItem -Include AssemblyInfo.cs -File -Recurse).fullname
$newVer = "${{ steps.create_release.outputs.current_tag }}".TrimStart('v').Split('-')[0]
echo "Prepared to overwrite Assembly version to: ${newVer}"
foreach ($assemblyInfoFile in $assemblyInfoFiles)
{
$filecontent = Get-Content($assemblyInfoFile)
attrib $assemblyInfoFile -r
$filecontent -replace $VersionRegex, $newVer | Out-File $assemblyInfoFile
}
- name: Execute MSBuild Commands
run: |
Expand All @@ -99,7 +108,12 @@ jobs:
if: ${{ success() }}
run: |
md ${{ github.workspace }}\zip\Keyfactor
Compress-Archive -Path ${{ github.workspace }}\PEMStoreSSH\bin\Release\*.dll,${{ github.workspace }}\PEMStoreSSH\bin\Release\*.json,${{ github.workspace }}\PEMStoreSSH\bin\Release\*.config,${{ github.workspace }}\PEMStoreSSH\bin\Release\Keyfactor.Extensions.Pam.Config.exe -DestinationPath ${{ github.workspace }}\zip\Keyfactor\$Env:REPO_NAME.zip -Force
Compress-Archive -Path `
${{ env.SOLUTION_FOLDER }}\${{ env.PROJECT_FOLDER }}\bin\Release\*.dll, `
${{ env.SOLUTION_FOLDER }}\${{ env.PROJECT_FOLDER }}\bin\Release\*.json, `
${{ env.SOLUTION_FOLDER }}\${{ env.PROJECT_FOLDER }}\bin\Release\*.config, `
${{ env.SOLUTION_FOLDER }}\${{ env.PROJECT_FOLDER }}\bin\Release\Keyfactor.Extensions.Pam.Config.exe `
-DestinationPath ${{ github.workspace }}\zip\Keyfactor\$Env:REPO_NAME.zip -Force
- name: Upload Release Asset (x64)
if: ${{ success() }}
Expand All @@ -113,7 +127,7 @@ jobs:
asset_name: ${{ env.REPO_NAME}}_${{ steps.create_release.outputs.current_tag }}.zip
asset_content_type: application/zip

- name: On Failure Remove Tags and Release
- name: On Failure - Remove Tags and Release
if: ${{ failure() }}
uses: dev-drprasad/[email protected]
with:
Expand Down

0 comments on commit 51ac2d3

Please sign in to comment.