Skip to content

Commit

Permalink
Stop failing GitHub Action nightly build if no changes were detected
Browse files Browse the repository at this point in the history
  • Loading branch information
ManticSic committed Feb 23, 2020
1 parent 098a79b commit 28401b7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
27 changes: 19 additions & 8 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,52 +22,63 @@ jobs:
run: git checkout master

- name: Precondition
id: precondition
if: success()
run: .\build\precondition.ps1
run: |
$result = .\build\precondition.ps1
$previousHash = $result.PreviousHash
$latestBuildHash = $result.LatestBuildHash
$hasChanges = $result.HasChanges
echo "Previous hash: $previousHash"
echo "Latest build hash: $latestBuildHash"
echo "::set-output name=has_changes::$hasChanges"
- name: Setup MSBuild
if: steps.precondition.outputs.has_changes == 'true' && success()
uses: warrenbuckley/Setup-MSBuild@v1

- name: Setup Nuget
if: steps.precondition.outputs.has_changes == 'true' && success()
uses: warrenbuckley/Setup-Nuget@v1

- name: Setup Git
if: steps.precondition.outputs.has_changes == 'true' && success()
run: |
git config user.email [email protected]
git config user.name "GitHub Actions"
- name: Build
if: success()
if: steps.precondition.outputs.has_changes == 'true' && success()
run: .\build\build.ps1 nightly Release pack 0

- name: Find NUPKG
if: success()
if: steps.precondition.outputs.has_changes == 'true' && success()
run: |
$filesInPackDir = (Get-ChildItem -Path pack | Sort-Object -Property @{Expression="Name"; Descending=$true})
$nupkgFile = $filesInPackDir[0].FullName
echo "::set-env name=NUPKG_FILE::$nupkgFile"
- name: Update nightly.rev
if: success()
if: steps.precondition.outputs.has_changes == 'true' && success()
run: .\build\update-nightly-rev.ps1

- name: Increment version
if: success()
if: steps.precondition.outputs.has_changes == 'true' && success()
run: .\build\increment-build-version.ps1

- name: Git Commit
if: success()
if: steps.precondition.outputs.has_changes == 'true' && success()
run: |
git add ./build/ExceptionalDevs.Exceptional.nuspec
git add ./build/nightly.rev
git commit -m "Nightly Commit" --author="GitHub Actions<[email protected]>"
- name: Git Push
if: success()
if: steps.precondition.outputs.has_changes == 'true' && success()
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Publish
if: success()
if: steps.precondition.outputs.has_changes == 'true' && success()
run: nuget push ${{ env.NUPKG_FILE }} ${{ secrets.JETBRAINS_TOKEN }} -source https://plugins.jetbrains.com
26 changes: 9 additions & 17 deletions build/precondition.ps1
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path
$NightlyRevFile = Join-Path -Path $ScriptDir -ChildPath nightly.rev
$scriptDir = Split-Path $script:MyInvocation.MyCommand.Path
$nightlyRevFile = Join-Path -Path $scriptDir -ChildPath nightly.rev

$PreviousHash = git rev-parse HEAD~1
$HashOfLatestBuild = Get-Content -Path $NightlyRevFile -ErrorAction SilentlyContinue
$previousHash = git rev-parse HEAD~1
$hashOfLatestBuild = Get-Content -Path $nightlyRevFile -ErrorAction SilentlyContinue

Write-Output "Previous hash: $PreviousHash"
Write-Output "Latest Build Hash: $HashOfLatestBuild"
$hasChanges = -Not ($previousHash -eq $hashOfLatestBuild)

$HasChanges = -Not ($PreviousHash -eq $HashOfLatestBuild)

if ($HasChanges -eq $true)
{
"Some changes detected"
exit 0
}
else
{
Write-Output "No changes detected"
exit 1
return @{
"LatestBuildHash" = $hashOfLatestBuild;
"PreviousHash" = $previousHash;
"HasChanges" = $hasChanges;
}

0 comments on commit 28401b7

Please sign in to comment.