From 165bc74c53d68c6750abe465b87937aa61e165dd Mon Sep 17 00:00:00 2001 From: Eliot Jones Date: Sat, 14 Aug 2021 13:01:46 -0400 Subject: [PATCH] try creating a nightly push to nuget script v1 this is intended to create nightly build with package versions of the form x.y.z-yyyyMMdd.sha and push them to nuget automatically, only where there are new changes per day. since devops is a nightmare and entirely untestable we will have to go through 20 iterations to actually get this to work --- .github/workflows/check_nightly.yml | 16 ++++++++++++ .github/workflows/nightly_release.yml | 37 +++++++++++++++++++++++++++ tools/generate-nightly-version.ps1 | 7 +++++ tools/get-main-version.ps1 | 7 +++++ tools/set-version.ps1 | 9 ++++++- 5 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/check_nightly.yml create mode 100644 .github/workflows/nightly_release.yml create mode 100644 tools/generate-nightly-version.ps1 create mode 100644 tools/get-main-version.ps1 diff --git a/.github/workflows/check_nightly.yml b/.github/workflows/check_nightly.yml new file mode 100644 index 00000000..31efed5f --- /dev/null +++ b/.github/workflows/check_nightly.yml @@ -0,0 +1,16 @@ +# https://github.community/t/trigger-action-on-schedule-only-if-there-are-changes-to-the-branch/17887/2 +check_date: + runs-on: ubuntu-latest + name: Check latest commit + outputs: + should_run: ${{ steps.should_run.outputs.should_run }} + steps: + - uses: actions/checkout@v2 + - name: print latest_commit + run: echo ${{ github.sha }} + + - id: should_run + continue-on-error: true + name: check latest commit is less than a day ago + if: ${{ github.event_name == 'schedule' }} + run: test -z $(git rev-list --after="24 hours" ${{ github.sha }}) && echo "::set-output name=should_run::false" \ No newline at end of file diff --git a/.github/workflows/nightly_release.yml b/.github/workflows/nightly_release.yml new file mode 100644 index 00000000..4a206668 --- /dev/null +++ b/.github/workflows/nightly_release.yml @@ -0,0 +1,37 @@ +name: Nightly Release + +on: + schedule: + - cron: '0 0 * * *' + +jobs: + build_and_publish_nightly: + needs: check_date + if: ${{ needs.check_date.outputs.should_run != 'false' }} + runs-on: windows-latest + name: build_and_publish_nightly + steps: + - uses: actions/checkout@master + + - name: Set up dotnet core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: "2.1.x" + + - name: Add msbuild to PATH + uses: microsoft/setup-msbuild@v1.0.2 + + - name: Write nightly version to projects + run: | + $newVer = .\tools\generate-nightly-version.ps1; .\tools\set-version.ps1 $newVer + + - name: Restore packages + run: dotnet restore tools/UglyToad.PdfPig.Package/UglyToad.PdfPig.Package.sln + + - name: Build package + run: dotnet pack -c Release -o package tools/UglyToad.PdfPig.Package/UglyToad.PdfPig.Package.sln + + - name: Publish Nuget to GitHub registry + run: dotnet nuget push ./package/*.nupkg --api-key ${NUGET_API_KEY} --source https://api.nuget.org/v3/index.json + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/tools/generate-nightly-version.ps1 b/tools/generate-nightly-version.ps1 new file mode 100644 index 00000000..a74924a2 --- /dev/null +++ b/tools/generate-nightly-version.ps1 @@ -0,0 +1,7 @@ +$toolsRoot = (Split-Path -parent $PSCommandPath) + +$mainVersion = & "$toolsRoot\get-main-version.ps1" +$commitHash = (git rev-parse HEAD).Substring(0, 5) +$date = [System.DateTime]::Now.ToString('yyyyMMdd') +$nightlyVersion = "$mainVersion-$date.$commitHash" +Write-Output $nightlyVersion \ No newline at end of file diff --git a/tools/get-main-version.ps1 b/tools/get-main-version.ps1 new file mode 100644 index 00000000..05e5cb13 --- /dev/null +++ b/tools/get-main-version.ps1 @@ -0,0 +1,7 @@ +$xml = New-Object XML +$xml.Load(".\tools\UglyToad.PdfPig.Package\UglyToad.PdfPig.Package.csproj") +$current = $xml.Project.PropertyGroup[0].Version +$hyphenIndex = $current.IndexOf('-') +$len = If ($hyphenIndex -lt 0) { $current.Length } Else { $hyphenIndex } +$version = $current.Substring(0, $len) +Write-Output $version \ No newline at end of file diff --git a/tools/set-version.ps1 b/tools/set-version.ps1 index 624100ee..779babb7 100644 --- a/tools/set-version.ps1 +++ b/tools/set-version.ps1 @@ -1,5 +1,5 @@ param ( - [Parameter(Position=0,mandatory=$true)] + [Parameter(Position = 0, mandatory = $true)] [string]$version ) @@ -12,4 +12,11 @@ $projs | ForEach-Object { $xml.Project.PropertyGroup[0].Version = $version $xml.Save($_.FullName) } + +$packageProjectPath = "$root/UglyToad.PdfPig.Package/UglyToad.PdfPig.Package.csproj" +$xml = New-Object XML +$xml.Load($packageProjectPath) +$xml.Project.PropertyGroup[0].Version = $version +$xml.Save($packageProjectPath) + Write-Host $projs.Length \ No newline at end of file