|
| 1 | +name: Deploy |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: [ master ] |
| 5 | + |
| 6 | +jobs: |
| 7 | + test: |
| 8 | + runs-on: windows-latest |
| 9 | + steps: |
| 10 | + - name: Checkout Sources |
| 11 | + uses: actions/checkout@v2 |
| 12 | + with: |
| 13 | + fetch-depth: 0 |
| 14 | + - name: Setup .NET 8 |
| 15 | + uses: actions/setup-dotnet@v4 |
| 16 | + with: |
| 17 | + dotnet-version: 8.0.x |
| 18 | + - name: "Build and Test" |
| 19 | + run: | |
| 20 | + dotnet build |
| 21 | + dotnet test |
| 22 | + version: |
| 23 | + needs: test |
| 24 | + runs-on: windows-latest |
| 25 | + outputs: |
| 26 | + version: ${{ steps.newversion.outputs.version }} |
| 27 | + tag: ${{ steps.newversion.outputs.tag }} |
| 28 | + steps: |
| 29 | + - name: Checkout Sources |
| 30 | + uses: actions/checkout@v2 |
| 31 | + with: |
| 32 | + fetch-depth: 0 |
| 33 | + - name: Set New Version |
| 34 | + id: newversion |
| 35 | + shell: pwsh |
| 36 | + run: | |
| 37 | + $currentVersion = git describe --abbrev=0 --tags --match "v[0-9]*.[0-9]*.[0-9]*-Release" |
| 38 | +
|
| 39 | + if ($currentVersion) { |
| 40 | + $v = $currentVersion.Split('-')[0].TrimStart('v') |
| 41 | + Write-Output "RELEASE: New Version: $($v)" |
| 42 | + Write-Output "version=$($v)" >> $Env:GITHUB_OUTPUT |
| 43 | + Write-Output "tag=$($currentVersion)" >> $Env:GITHUB_OUTPUT |
| 44 | + } else { |
| 45 | + |
| 46 | + $currentVersion = git describe --abbrev=0 --tags --match "v[0-9]*.[0-9]*.[0-9]*" |
| 47 | + $currentVersion = git describe --match "$($currentVersion)" --long |
| 48 | + $versionParts = $currentVersion.Split('-') |
| 49 | + $v = $versionParts[0] |
| 50 | + $increment = [int]$versionParts[1] |
| 51 | + |
| 52 | + if ($increment -gt 0) { |
| 53 | + $increment = 1 |
| 54 | + } |
| 55 | + |
| 56 | + $vparts = $v.Split('.') |
| 57 | + $vparts[2] = "$([int]$vparts[2] + [int]$increment)" |
| 58 | + $v = $vparts -join '.' |
| 59 | + $v = "$($v)".TrimStart("v") |
| 60 | + Write-Output "New Version: $($v)" |
| 61 | + Write-Output "version=$($v)" >> $Env:GITHUB_OUTPUT |
| 62 | + Write-Output "tag=" >> $Env:GITHUB_OUTPUT |
| 63 | + } |
| 64 | + prepublish: |
| 65 | + needs: [test, version] |
| 66 | + runs-on: windows-latest |
| 67 | + outputs: |
| 68 | + description: ${{ steps.meta.outputs.description }} |
| 69 | + changeinfo: ${{ steps.meta.outputs.changeinfo }} |
| 70 | + steps: |
| 71 | + - name: Checkout Sources |
| 72 | + uses: actions/checkout@v2 |
| 73 | + with: |
| 74 | + fetch-depth: 0 |
| 75 | + - name : Get Meta Data |
| 76 | + shell: pwsh |
| 77 | + id: meta |
| 78 | + run: | |
| 79 | + [xml]$xml = get-content "src/Autofac.EasyPropInject.csproj" |
| 80 | + $description = $xml.SelectSingleNode("//Description").InnerText; |
| 81 | + $changes = $xml.SelectSingleNode("//PackageReleaseNotes").InnerText; |
| 82 | + Write-Output "description=$($description.Trim().Replace("`t", '') | ConvertTo-Json)" >> $Env:GITHUB_OUTPUT |
| 83 | + Write-Output "changeinfo=$($changes.Trim().Replace("`t", '') | ConvertTo-Json)" >> $Env:GITHUB_OUTPUT |
| 84 | +
|
| 85 | + publish: |
| 86 | + needs: [test, version, prepublish] |
| 87 | + runs-on: windows-latest |
| 88 | + steps: |
| 89 | + - name: Setup .NET 8 |
| 90 | + uses: actions/setup-dotnet@v4 |
| 91 | + with: |
| 92 | + dotnet-version: 8.0.x |
| 93 | + - name: Checkout Sources |
| 94 | + uses: actions/checkout@v2 |
| 95 | + with: |
| 96 | + fetch-depth: 0 |
| 97 | + - name: Create Package |
| 98 | + run: | |
| 99 | + dotnet build src/Autofac.EasyPropInject.csproj -c Release -p:AssemblyVersion=${{ needs.version.outputs.version }} -p:PackageVersion=${{ needs.version.outputs.version }} |
| 100 | + dotnet pack src/Autofac.EasyPropInject.csproj -c Release -p:AssemblyVersion=${{ needs.version.outputs.version }} -p:PackageVersion=${{ needs.version.outputs.version }} --output nget_pkg |
| 101 | + - name: Create Release and Tag |
| 102 | + id: create_release |
| 103 | + uses: actions/create-release@latest |
| 104 | + env: |
| 105 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token |
| 106 | + with: |
| 107 | + tag_name: v${{ needs.version.outputs.version }} |
| 108 | + release_name: Release v${{ needs.version.outputs.version }} |
| 109 | + body: | |
| 110 | + # Release Info Version ${{ needs.version.outputs.version }} |
| 111 | + ## Info |
| 112 | + ${{fromJSON(needs.prepublish.outputs.description)}} |
| 113 | + ## Changes in v${{ needs.version.outputs.version }} |
| 114 | + ${{fromJSON(needs.prepublish.outputs.changeinfo)}} |
| 115 | + draft: false |
| 116 | + prerelease: false |
| 117 | + - name: Delete Release Tag |
| 118 | + if: ${{needs.version.outputs.tag}} |
| 119 | + uses: dev-drprasad/delete-tag-and-release@v1.0 |
| 120 | + with: |
| 121 | + tag_name: ${{needs.version.outputs.tag}} |
| 122 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 123 | + delete_release: false |
| 124 | + - name: Upload Release Asset Pkg |
| 125 | + id: upload-release-asset |
| 126 | + uses: actions/upload-release-asset@v1 |
| 127 | + env: |
| 128 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 129 | + with: |
| 130 | + upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps |
| 131 | + asset_path: ./nget_pkg/Autofac.EasyPropInject.${{ needs.version.outputs.version }}.nupkg |
| 132 | + asset_name: Autofac.EasyPropInject.${{ needs.prepublish.version.version }}.nupkg |
| 133 | + asset_content_type: application/zip |
| 134 | + - name: Upload Release Asset DLL |
| 135 | + id: upload-release-asset2 |
| 136 | + uses: actions/upload-release-asset@v1 |
| 137 | + env: |
| 138 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 139 | + with: |
| 140 | + upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps |
| 141 | + asset_path: src/bin/Release/net8.0/Autofac.EasyPropInject.dll |
| 142 | + asset_name: Autofac.EasyPropInject.dll |
| 143 | + asset_content_type: application/octet-stream |
| 144 | + - name: Publish package to nuget |
| 145 | + id: nugetpush |
| 146 | + run: dotnet nuget push "nget_pkg/Autofac.EasyPropInject.${{ needs.version.outputs.version }}.nupkg" -k ${{secrets.NUGET_KEY}} -s https://api.nuget.org/v3/index.json |
| 147 | + |
| 148 | + |
| 149 | + |
0 commit comments