|
| 1 | +name: .NET Core V2 |
| 2 | +on: |
| 3 | + push: |
| 4 | + pull_request: |
| 5 | + release: |
| 6 | + types: |
| 7 | + - published |
| 8 | +env: |
| 9 | + # Stop wasting time caching packages |
| 10 | + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true |
| 11 | + # Disable sending usage data to Microsoft |
| 12 | + DOTNET_CLI_TELEMETRY_OPTOUT: true |
| 13 | + # Project name to pack and publish |
| 14 | + PROJECT_NAME: SharpHelpers |
| 15 | + # GitHub Packages Feed settings |
| 16 | + GITHUB_FEED: https://nuget.pkg.github.com/shaprcode-it/ |
| 17 | + GITHUB_USER: iscifoni |
| 18 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 19 | + # Official NuGet Feed settings |
| 20 | + NUGET_FEED: https://api.nuget.org/v3/index.json |
| 21 | + NUGET_KEY: ${{ secrets.NUGET_TOKEN }} |
| 22 | +jobs: |
| 23 | + build: |
| 24 | + runs-on: ${{ matrix.os }} |
| 25 | + strategy: |
| 26 | + matrix: |
| 27 | + os: [ ubuntu-latest, windows-latest ] |
| 28 | + steps: |
| 29 | + - name: Checkout |
| 30 | + uses: actions/checkout@v2 |
| 31 | + - run: git fetch --unshallow |
| 32 | + - name: Setup .NET Core 3.1 |
| 33 | + uses: actions/setup-dotnet@v1 |
| 34 | + with: |
| 35 | + dotnet-version: 3.1.100 |
| 36 | + - name: Setup .NET Core 2.2 |
| 37 | + uses: actions/setup-dotnet@v1 |
| 38 | + with: |
| 39 | + dotnet-version: 2.2.402 |
| 40 | + - name: Install GitVersion |
| 41 | + uses: gittools/actions/gitversion/setup@v0.9.7 |
| 42 | + with: |
| 43 | + versionSpec: '5.1.x' |
| 44 | + - name: Use GitVersion |
| 45 | + id: gitversion # step id used as reference for output values |
| 46 | + uses: gittools/actions/gitversion/execute@v0.9.7 |
| 47 | + - run: | |
| 48 | + echo "NuGetVersionV2: ${{ steps.gitversion.outputs.nuGetVersionV2 }}" |
| 49 | + echo "NuGetPreReleaseTagV2: ${{ steps.gitversion.outputs.CommitsSinceVersionSourcePadded }}" |
| 50 | + - name: Restore |
| 51 | + run: dotnet restore ./SharpHelpers/SharpHelpers.sln |
| 52 | + - name: Build |
| 53 | + run: dotnet build -c Release --no-restore ./SharpHelpers/SharpHelpers.sln |
| 54 | + - name: Test |
| 55 | + run: dotnet test ./SharpHelpers/SharpHelpers.sln -c Release --no-build |
| 56 | + - name: Pack |
| 57 | + if: matrix.os == 'ubuntu-latest' |
| 58 | + run: dotnet pack -v normal -c Release --no-restore --no-build -p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersionV2 }}-${{ steps.gitversion.outputs.CommitsSinceVersionSourcePadded }} ./SharpHelpers/SharpHelpers.sln |
| 59 | + - name: Upload Artifact |
| 60 | + if: matrix.os == 'ubuntu-latest' |
| 61 | + uses: actions/upload-artifact@v2 |
| 62 | + with: |
| 63 | + name: nupkg |
| 64 | + path: ./SharpHelpers/${{ env.PROJECT_NAME }}/bin/Release/*.nupkg |
| 65 | + prerelease: |
| 66 | + needs: build |
| 67 | + if: github.ref == 'refs/heads/develop' |
| 68 | + runs-on: ubuntu-latest |
| 69 | + steps: |
| 70 | + - name: Download Artifact |
| 71 | + uses: actions/download-artifact@v1 |
| 72 | + with: |
| 73 | + name: nupkg |
| 74 | + - name: Push to GitHub Feed |
| 75 | + run: | |
| 76 | + for f in ./nupkg/*.nupkg |
| 77 | + do |
| 78 | + echo $f |
| 79 | + curl --silent --show-error --fail -vX PUT -u "$GITHUB_USER:$GITHUB_TOKEN" -F package=@$f $GITHUB_FEED |
| 80 | + done |
| 81 | + deploy: |
| 82 | + needs: build |
| 83 | + if: github.event_name == 'release' && startsWith(github.ref, 'refs/heads/v') |
| 84 | + runs-on: ubuntu-latest |
| 85 | + steps: |
| 86 | + - uses: actions/checkout@v2 |
| 87 | + - name: Setup .NET Core |
| 88 | + uses: actions/setup-dotnet@v1 |
| 89 | + with: |
| 90 | + dotnet-version: 5.0.100 |
| 91 | + - name: Create Release NuGet package |
| 92 | + run: | |
| 93 | + arrTag=(${GITHUB_REF//\// }) |
| 94 | + VERSION="${arrTag[2]}" |
| 95 | + echo Version: $VERSION |
| 96 | + VERSION="${VERSION//v}" |
| 97 | + echo Clean Version: $VERSION |
| 98 | + dotnet pack -v normal -c Release --include-symbols --include-source -p:PackageVersion=$VERSION -o nupkg src/$PROJECT_NAME/$PROJECT_NAME.*proj |
| 99 | + - name: Push to GitHub Feed |
| 100 | + run: | |
| 101 | + for f in ./nupkg/*.nupkg |
| 102 | + do |
| 103 | + curl -vX PUT -u "$GITHUB_USER:$GITHUB_TOKEN" -F package=@$f $GITHUB_FEED |
| 104 | + done |
| 105 | + - name: Push to NuGet Feed |
| 106 | + run: dotnet nuget push ./nupkg/*.nupkg --source $NUGET_FEED --skip-duplicate --api-key $NUGET_KEY |
0 commit comments