|
| 1 | +name: Build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "main" ] |
| 6 | + pull_request: |
| 7 | + branches: [ "main" ] |
| 8 | + release: |
| 9 | + types: [ "published" ] |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + |
| 14 | +env: |
| 15 | + DOTNET_NOLOGO: true |
| 16 | + DOTNET_CLI_TELEMETRY_OPTOUT: true |
| 17 | + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true |
| 18 | + |
| 19 | +jobs: |
| 20 | + |
| 21 | + build: |
| 22 | + |
| 23 | + name: ${{ matrix.os }} / ${{ matrix.configuration }} |
| 24 | + runs-on: ${{ matrix.os }} |
| 25 | + |
| 26 | + strategy: |
| 27 | + fail-fast: true |
| 28 | + matrix: |
| 29 | + configuration: [ Debug, Release ] |
| 30 | + os: [ windows-2022 ] |
| 31 | + |
| 32 | + env: |
| 33 | + SRC_SLN_PATH: source/WindowsAPICodePack |
| 34 | + NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages |
| 35 | + |
| 36 | + steps: |
| 37 | + |
| 38 | + - uses: actions/checkout@v3 |
| 39 | + |
| 40 | + # Assuming .NET Framework flavors are available in OS |
| 41 | + - name: Install .NET Core Runtimes |
| 42 | + uses: actions/setup-dotnet@v3 |
| 43 | + with: |
| 44 | + dotnet-version: | |
| 45 | + 6.0.x |
| 46 | + 5.0.x |
| 47 | + 3.1.x |
| 48 | +
|
| 49 | + # https://github.com/microsoft/setup-msbuild |
| 50 | + - name: Add MSBuild.exe to PATH |
| 51 | + uses: microsoft/setup-msbuild@v1 |
| 52 | + |
| 53 | + # Setup Short SHA |
| 54 | + - name: Setup Short SHA |
| 55 | + run: echo "build_sha=$("${{ github.sha }}".SubString(0, 7))" >> $env:GITHUB_ENV |
| 56 | + |
| 57 | + # Setup Build Suffix (for staging) |
| 58 | + - name: Setup Build Suffix |
| 59 | + if: github.event_name != 'release' |
| 60 | + run: echo "build_suffix=build.${{ env.build_sha }}" >> $env:GITHUB_ENV |
| 61 | + |
| 62 | + # Setup Build Suffix (for release) |
| 63 | + - name: Setup Build Suffix |
| 64 | + if: github.event_name == 'release' |
| 65 | + run: | |
| 66 | + $suffix = "${{ github.ref_name }}".Split("-",2)[1] |
| 67 | + echo "build_suffix=$( if($suffix) { "${suffix}.${{ env.build_sha }}" } else { '' } )" >> $env:GITHUB_ENV |
| 68 | +
|
| 69 | + # Create NuGet Cache |
| 70 | + - name: NuGet Cache |
| 71 | + id: nuget-cache |
| 72 | + uses: actions/cache@v3 |
| 73 | + with: |
| 74 | + path: ${{ env.NUGET_PACKAGES }} |
| 75 | + key: ${{ matrix.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} |
| 76 | + restore-keys: | |
| 77 | + ${{ matrix.os }}-nuget- |
| 78 | +
|
| 79 | + # Restore Build Deps |
| 80 | + - name: Restore Dependencies |
| 81 | + run: dotnet restore |
| 82 | + working-directory: ${{ env.SRC_SLN_PATH }} |
| 83 | + |
| 84 | + # Build Library |
| 85 | + - name: Build the Application |
| 86 | + run: dotnet build --no-restore -c $env:Configuration -p:VersionSuffix=${{ env.build_suffix }} |
| 87 | + working-directory: ${{ env.SRC_SLN_PATH }} |
| 88 | + env: |
| 89 | + Configuration: ${{ matrix.configuration }} |
| 90 | + |
| 91 | + # Upload Build Artifacts |
| 92 | + - name: Upload Build Artifacts |
| 93 | + if: matrix.configuration == 'Release' |
| 94 | + uses: actions/upload-artifact@v3 |
| 95 | + with: |
| 96 | + name: nupkg-${{ env.build_sha }} |
| 97 | + path: ${{env.SRC_SLN_PATH}}/**/bin/${{ matrix.configuration }}/*.*nupkg |
| 98 | + |
| 99 | + stage: |
| 100 | + |
| 101 | + needs: build |
| 102 | + if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' |
| 103 | + |
| 104 | + name: Stage Artifacts |
| 105 | + runs-on: ubuntu-latest |
| 106 | + |
| 107 | + steps: |
| 108 | + |
| 109 | + - name: Setup Short SHA |
| 110 | + run: echo "build_sha=${GITHUB_SHA::7}" >> $GITHUB_ENV |
| 111 | + |
| 112 | + - name: Download Build Artifacts |
| 113 | + uses: actions/download-artifact@v3 |
| 114 | + with: |
| 115 | + name: nupkg-${{ env.build_sha }} |
| 116 | + |
| 117 | + - uses: actions/setup-dotnet@v3 |
| 118 | + with: |
| 119 | + dotnet-version: '6.0.x' |
| 120 | + |
| 121 | + - name: Push to NuGet |
| 122 | + run: | |
| 123 | + for pkg in $GITHUB_WORKSPACE/**/bin/Release/*.nupkg |
| 124 | + do |
| 125 | + cd $(dirname $pkg) |
| 126 | + echo "Publishing $(basename $pkg)" |
| 127 | + dotnet nuget push "$(basename $pkg)" -k ${{ secrets.NUGET_TEST_API_KEY }} -s ${{ vars.NUGET_TEST_API_KEY_SOURCE }} --skip-duplicate |
| 128 | + done |
| 129 | +
|
| 130 | + deploy: |
| 131 | + |
| 132 | + needs: build |
| 133 | + if: github.event_name == 'release' |
| 134 | + |
| 135 | + name: Release Artifacts |
| 136 | + runs-on: ubuntu-latest |
| 137 | + |
| 138 | + steps: |
| 139 | + |
| 140 | + - name: Setup Short SHA |
| 141 | + run: echo "build_sha=${GITHUB_SHA::7}" >> $GITHUB_ENV |
| 142 | + |
| 143 | + - name: Download Build Artifacts |
| 144 | + uses: actions/download-artifact@v3 |
| 145 | + with: |
| 146 | + name: nupkg-${{ env.build_sha }} |
| 147 | + |
| 148 | + - uses: actions/setup-dotnet@v3 |
| 149 | + with: |
| 150 | + dotnet-version: '6.0.x' |
| 151 | + |
| 152 | + - name: Push to NuGet |
| 153 | + run: | |
| 154 | + for pkg in $GITHUB_WORKSPACE/**/bin/Release/*.nupkg |
| 155 | + do |
| 156 | + cd $(dirname $pkg) |
| 157 | + echo "Publishing $(basename $pkg)" |
| 158 | + dotnet nuget push "$(basename $pkg)" -k ${{ secrets.NUGET_API_KEY }} -s ${{ vars.NUGET_API_KEY_SOURCE }} --skip-duplicate |
| 159 | + done |
0 commit comments