Skip to content

Commit

Permalink
Use GitHub Actions to deploy NuGet packages
Browse files Browse the repository at this point in the history
  • Loading branch information
RehanSaeed committed Jul 13, 2020
1 parent 51ec6a4 commit 6e0b6a9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 39 deletions.
50 changes: 45 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: Build

on:
push:
branches:
- '*'
tags:
- '*'
pull_request:
release:
types:
- published

env:
# Set the DOTNET_SKIP_FIRST_TIME_EXPERIENCE environment variable to stop wasting time caching packages
Expand All @@ -23,7 +23,7 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- name: Checkout
- name: 'Checkout'
uses: actions/checkout@v2
with:
lfs: true
Expand Down Expand Up @@ -52,3 +52,43 @@ jobs:
with:
name: ${{matrix.os}}
path: './Artefacts'

push-github-packages:
name: 'Push GitHub Packages'
needs: build
if: github.ref == 'refs/heads/master' || github.event_name == 'release'
runs-on: windows-latest
steps:
- name: 'Download Artefact'
uses: actions/download-artifact@v1
with:
name: 'windows-latest'
- name: 'Dotnet NuGet Add Source'
run: dotnet nuget add source https://nuget.pkg.github.com/RehanSaeed/index.json --name GitHub --username RehanSaeed --password ${{secrets.GITHUB_TOKEN}}
shell: pwsh
- name: 'Dotnet NuGet Push'
run: |
$count = 0;
do {
++$count;
dotnet nuget push .\windows-latest\*.nupkg --source GitHub --skip-duplicate;
}
while ($count -lt 30 -and $LastExitCode -ne 0)
shell: pwsh

push-nuget:
name: 'Push NuGet Packages'
needs: build
if: github.event_name == 'release'
runs-on: windows-latest
steps:
- name: 'Download Artefact'
uses: actions/download-artifact@v1
with:
name: 'windows-latest'
- name: 'Dotnet NuGet Push'
run: |
Get-ChildItem .\windows-latest -Filter *.nupkg |
Where-Object { !$_.Name.Contains('preview') } |
ForEach-Object { dotnet nuget push $_ --source https://api.nuget.org/v3/index.json --skip-duplicate --api-key ${{secrets.NUGET_API_KEY}} }
shell: pwsh
34 changes: 0 additions & 34 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,37 +85,3 @@ stages:
- pwsh: nuget push $(Agent.BuildDirectory)\Windows\*.nupkg -Source https://pkgs.dev.azure.com/serilog-exceptions/_packaging/serilog-exceptions/nuget/v3/index.json -ApiKey AzureArtifacts -SkipDuplicate
displayName: 'NuGet Push'
failOnStderr: true
- deployment: GitHub
condition: ne(variables['Build.Reason'], 'PullRequest')
pool:
vmImage: windows-latest
environment: 'GitHub'
strategy:
runOnce:
deploy:
steps:
- task: NuGetToolInstaller@1
displayName: 'NuGet Install'
- pwsh: nuget source Add -Name GitHub -Source https://nuget.pkg.github.com/RehanSaeed/index.json -UserName $(GitHubUserName) -Password $(GitHubPersonalAccessToken)
displayName: 'NuGet Add Source'
failOnStderr: true
- pwsh: nuget push $(Agent.BuildDirectory)\Windows\*.nupkg -Source GitHub -SkipDuplicate
displayName: 'NuGet Push'
failOnStderr: true
- deployment: NuGet
condition: and(ne(variables['Build.Reason'], 'PullRequest'), startsWith(variables['Build.sourceBranch'], 'refs/tags/'))
pool:
vmImage: windows-latest
environment: 'NuGet'
strategy:
runOnce:
deploy:
steps:
- task: NuGetToolInstaller@1
displayName: 'Install NuGet'
- pwsh: |
Get-ChildItem $(Agent.BuildDirectory)\Windows -Filter *.nupkg |
Where-Object { !$_.Name.Contains('preview') } |
ForEach-Object { nuget push $_ -Source https://api.nuget.org/v3/index.json -ApiKey $(NuGetApiKey) -SkipDuplicate }
displayName: 'NuGet Push'
failOnStderr: true

0 comments on commit 6e0b6a9

Please sign in to comment.