1- # This is a basic workflow to help you get started with Actions
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
23
3- name : Keyfactor Extension - Pre Release
4+ name : Keyfactor Extension - Release Candidate
5+
6+ env :
7+ SOLUTION_FOLDER : ' .'
8+ PROJECT_FOLDER : ' GCPAnyAgent'
49
510# Controls when the action will run.
611on :
7- # Triggers the workflow on push
8- push :
9- # only run this workflow when pushing to a branch that has the prerelease suffix
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
1016 branches :
11- - ' release-[0-9]+. [0-9]+.[0-9]+-pre'
12- - ' ! release-[0-9]+. [0-9]+.[0-9]+'
17+ - ' ! release-[0-9]+.[0-9]+-pre'
18+ - ' release-[0-9]+.[0-9]+'
1319
14- # Allows you to run this workflow manually from the Actions tab
20+ # Release Candidate can be triggered manually
1521 workflow_dispatch :
1622
17- # A workflow run is made up of one or more jobs that can run sequentially or in parallel
1823jobs :
1924 # This workflow contains a single job called "build"
2025 build :
@@ -32,14 +37,17 @@ jobs:
3237 echo "Setup Envrionment Variables for Workflow"
3338 echo "Working Path: ${Env:GITHUB_WORKSPACE}"
3439 $slnPath = (Get-ChildItem -Include *.sln -File -Recurse).fullname
35- $relName = "${{ github.ref }}".Split("/")
40+ $relName = "${{ github.base_ref }}".Split("/")
3641 $repoName = "${{ github.repository }}".Split("/")
42+ $relVersion = "${{ github.base_ref }}".Split("-")
3743 echo "Solution File Path: ${slnPath}"
3844 echo "SOLUTION_PATH=${slnPath}" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
3945 echo "Release Name: $($relName[-1])"
4046 echo "RELEASE_NAME=$($relName[-1])" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append
4147 echo "Repo Name: $($repoName[-1])"
4248 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
4351
4452 - uses : actions/setup-dotnet@v1
4553 with :
5866 - name : restore nuget packages
5967 run : |
6068 nuget restore ${{ env.SOLUTION_PATH }}
69+
70+ - name : GitHub Script checks for existing version tags
71+ id : existing_version
72+ 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+ }
61128
62129 # Runs a set of commands using the runners shell
63130 - name : Execute MSBuild Commands
@@ -67,36 +134,22 @@ jobs:
67134 - name : Archive Files
68135 run : |
69136 md ${{ github.workspace }}\zip\Keyfactor
70- Compress-Archive -Path ${{ github.workspace }}\GCPAnyAgent\bin\Release\*.dll,${{ github.workspace }}\GCPAnyAgent\bin\Release\GCPAnyAgent.dll.config -DestinationPath ${{ github.workspace }}\zip\Keyfactor\$Env:REPO_NAME.zip -Force
137+ Compress-Archive -Path `
138+ ${{ env.SOLUTION_FOLDER }}\${{ env.PROJECT_FOLDER }}\bin\Release\* `
139+ -DestinationPath ${{ github.workspace }}\zip\Keyfactor\$Env:REPO_NAME.zip -Force
71140
72141
73142 - name : Upload a Build Artifact
7414375144 with :
76145 # Artifact name
77- name : ${{ env.REPO_NAME}}.zip
146+ name : ${{ env.REPO_NAME }}.zip
78147 # A file, directory or wildcard pattern that describes what to upload
79148 path : |
80149 ${{ github.workspace }}\zip\Keyfactor\${{ env.REPO_NAME}}.zip
81150 # The desired behavior if no files are found using the provided path.
82151 if-no-files-found : error # optional, default is warn
83-
84- - name : Create Release
85- id : create_release
86- # uses: zendesk/action-create-release@v1 - Update when PR is approved
87- uses : keyfactor/action-create-release@786b73035fa09790f9eb11bb86834a6d7af1c256
88- env :
89- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
90- with :
91- release_name : Release ${{ env.RELEASE_NAME }}
92- body : |
93- [Changelog](../CHANGELOG.MD)
94- draft : false
95- prerelease : true
96- auto_increment_type : patch
97- tag_schema : semantic
98- commitish : ${{ github.sha }}
99-
152+
100153 - name : Upload Release Asset (x64)
101154 id : upload-release-asset-x64
102155 uses : actions/upload-release-asset@v1
@@ -105,5 +158,5 @@ jobs:
105158 with :
106159 upload_url : ${{ steps.create_release.outputs.upload_url }}
107160 asset_path : ${{ github.workspace }}\zip\Keyfactor\${{ env.REPO_NAME}}.zip
108- asset_name : ${{ env.REPO_NAME}}.zip
161+ asset_name : ${{ env.REPO_NAME}}_${{ steps.create_release.outputs.current_tag }} .zip
109162 asset_content_type : application/zip
0 commit comments