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