From 1f40d4b2891fff63c14d373be5386bd07cf42536 Mon Sep 17 00:00:00 2001
From: elzik <23397871+elzik@users.noreply.github.com>
Date: Sat, 26 Oct 2024 17:57:32 +0100
Subject: [PATCH] Split Build into Jobs (#97)
* Split build into jobs
* Run GitVersion on the CLI
* Move semver derivation to its own step
* Use latest version of GitVersion
* Move semver and tagging to release job
* Revert "Move semver and tagging to release job"
This reverts commit eadde102df5fb955964612248c4a1bde74ab88e0.
* Move tagging to release job and only release when necessary
* Fix release conditions
* Fix boolean casing
* Add debugging job
* Only run necessary jobs for testing
* Ensure job outputs variable
* Reinstate jobs
* Fix all installs of GitVersion to major version 6
* Checkout before tgging
* Fix artifact upload conditions
* Output and use semantic version
* Output semantic version
* Refer to correct job name
* Display all GitVersion info
* Make release dependant on check-release-requirement
* Run release on Lunux
* Set environment variable for WiX
* Revert "Set environment variable for WiX"
This reverts commit 83d549cbd813e26fc73c406e9a008dc412da1f22.
* Upgrade wix GitVersion
* Revert "Upgrade wix GitVersion"
This reverts commit 5f4320edaadaf803165898d0d10f078c1d60cb6d.
* Switch to ContinuousDelivery for GitVersion
* Upgrade GitVersion for Wix
* Use continuous delivery only for non-main branches
* Revert "Use continuous delivery only for non-main branches"
This reverts commit 26e1ea148a88fa6969c1329c14428ab7b60ce787.
---
.github/workflows/continuous-delivery.yml | 129 ++++++++++++------
Build/build-osx-installer.ps1 | 2 +-
Build/build-windows-installer.ps1 | 2 +-
Build/tag-with-semver.ps1 | 2 +-
.../Elzik.FmSync.WindowsInstaller.wixproj | 3 +-
5 files changed, 96 insertions(+), 42 deletions(-)
diff --git a/.github/workflows/continuous-delivery.yml b/.github/workflows/continuous-delivery.yml
index ddeef73..9dd61f3 100644
--- a/.github/workflows/continuous-delivery.yml
+++ b/.github/workflows/continuous-delivery.yml
@@ -10,14 +10,50 @@ on:
description: Force tag & release even when the source branch is not main or no production source files have changed
jobs:
- continuous-delivery:
-
- runs-on: ${{ matrix.os }}
+ check-release-requirement:
+ runs-on: ubuntu-latest
+ outputs:
+ needs-release: ${{ steps.release-check.outputs.needs-release }}
+ semantic-version: ${{ steps.get-semver.outputs.semantic-version }}
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+ - name: GetSemVer
+ id: get-semver
+ run: |
+ dotnet tool install --global GitVersion.Tool --version 6.*
+ output=$(dotnet-gitversion)
+ semver=$(echo $output | grep -oP '"SemVer"\s*:\s*"\K[^"]+')
+ echo $output
+ echo "Semantic version: $semver"
+ echo "semantic-version=$semver" >> $GITHUB_OUTPUT
+ - name: Check for Release Requirement
+ id: release-check
+ run: |
+ productionFilesChangedCount=$(git diff --name-only HEAD^ HEAD | grep -E 'src/|Installer/' | wc -l)
+ echo "$productionFilesChangedCount production source code files have changed"
+ productionFilesChanged=$((productionFilesChangedCount > 0))
+ echo "Git ref: ${{ github.ref_name }}"
+ branchIsMain=$([[ "${{ github.ref_name }}" == "main" ]] && echo true || echo false)
+ forceReleaseRequested=$([[ "${{ github.event.inputs.force-release }}" == "true" ]] && echo true || echo false)
+ echo "Forced release requested: $forceReleaseRequested"
+ needsRelease=$([[ "$forceReleaseRequested" == "true" || ( "$productionFilesChanged" == "1" && "$branchIsMain" == "true" ) ]] && echo true || echo false)
+ echo "Release will be generated: $needsRelease"
+ echo "needs-release=$needsRelease" >> $GITHUB_OUTPUT
- strategy:
- matrix:
- os: [windows-latest, macos-latest]
+ display-job-outputs:
+ needs: check-release-requirement
+ runs-on: ubuntu-latest
+ steps:
+ - name: Display Job Outputs
+ run: |
+ echo "needs-release = ${{ needs.check-release-requirement.outputs.needs-release }}"
+ echo "semantic-version = ${{ needs.check-release-requirement.outputs.semantic-version }}"
+ build-windows:
+ runs-on: windows-latest
+ needs: check-release-requirement
steps:
- uses: actions/checkout@v4
with:
@@ -30,7 +66,7 @@ jobs:
run: ./Build/build-and-test.ps1
shell: pwsh
- name: Upload Coverage Badge
- if: github.event_name != 'pull_request' && matrix.os == 'windows-latest' && github.actor != 'dependabot[bot]'
+ if: github.event_name != 'pull_request' && github.actor != 'dependabot[bot]'
uses: exuanbo/actions-deploy-gist@v1
with:
token: ${{ secrets.CODE_COVERAGE_AUTH_TOKEN }}
@@ -39,52 +75,69 @@ jobs:
gist_file_name: fmsync-code-coverage-${{ github.ref_name }}.svg
file_path: tests/TestResults/badge_shieldsio_linecoverage_green.svg
- name: Run codacy-coverage-reporter
- if: matrix.os == 'windows-latest' && github.actor != 'dependabot[bot]'
+ if: github.actor != 'dependabot[bot]'
uses: codacy/codacy-coverage-reporter-action@v1
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: tests/TestResults/Cobertura.xml
- name: Build Windows Installer
- if: matrix.os == 'windows-latest'
run: ./Build/build-windows-installer.ps1
shell: pwsh
+ - name: Upload Windows Artifact
+ if: needs.check-release-requirement.outputs.needs-release == 'true'
+ uses: actions/upload-artifact@v3
+ with:
+ name: windows-installer
+ path: ./Installer/Elzik.FmSync.WindowsInstaller/bin/x64/Release/en-US/fmsync*.msi
+
+ build-macos:
+ runs-on: macos-latest
+ needs: check-release-requirement
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+ - name: Setup .NET
+ uses: actions/setup-dotnet@v4
+ with:
+ dotnet-version: 8.0.x
+ - name: Build & Test
+ run: ./Build/build-and-test.ps1
+ shell: pwsh
- name: Build OSX Installer
- if: matrix.os == 'macos-latest'
run: ./Build/build-osx-installer.ps1
shell: pwsh
- - name: Check for Release Requirement
- id: release-check
- run: |
- $productionFilesChangedCount = (git diff --name-only HEAD^ HEAD | Select-String -pattern 'src/*|Installer/').Count
- Write-Output "$productionFilesChangedCount production source code files have changed"
- $productionFilesChanged = $productionFilesChangedCount -gt 0
- Write-Output "Git ref:` ${{ github.ref_name }}"
- $branchIsMain = "${{ github.ref_name }}" -eq 'main'
- $forceReleaseRequested = "${{ github.event.inputs.force-release }}" -eq 'true'
- Write-Output "Forced release requested:` $forceReleaseRequested"
- $needsRelease = $forceReleaseRequested -or ($productionFilesChanged -and $branchIsMain)
- Write-Output "Release will be generated:` $needsRelease"
- Add-Content -Path $env:GITHUB_OUTPUT -Value "needs-release=$needsRelease"
- shell: pwsh
+ - name: Upload macOS Artifact
+ if: needs.check-release-requirement.outputs.needs-release == 'true'
+ uses: actions/upload-artifact@v3
+ with:
+ name: macos-installer
+ path: ./Installer/Elzik.FmSync.OsxInstaller/x64/Release/fmsync-osx*.zip
+
+ release:
+ runs-on: ubuntu-latest
+ needs: [build-windows, build-macos, check-release-requirement]
+ if: needs.check-release-requirement.outputs.needs-release == 'true'
+ steps:
+ - uses: actions/checkout@v4
- name: Tag With SemVer
- if: steps.release-check.outputs.needs-release == 'True'
run: |
- git tag "v${{ env.GitVersion_SemVer }}"
+ git tag "v${{ needs.check-release-requirement.outputs.semantic-version }}"
git push --tags
- shell: pwsh
- - name: Windows Release
- uses: softprops/action-gh-release@v1
- if: steps.release-check.outputs.needs-release == 'True' && matrix.os == 'windows-latest'
+ - uses: actions/download-artifact@v3
with:
- tag_name: v${{ env.GitVersion_SemVer }}
- generate_release_notes: true
- prerelease: ${{ github.ref_name != 'main' }}
- files: ./Installer/Elzik.FmSync.WindowsInstaller/bin/x64/Release/en-US/fmsync*.msi
- - name: macOS Release
+ name: windows-installer
+ path: ./windows-installer
+ - uses: actions/download-artifact@v3
+ with:
+ name: macos-installer
+ path: ./macos-installer
+ - name: Create Release
uses: softprops/action-gh-release@v1
- if: steps.release-check.outputs.needs-release == 'True' && matrix.os == 'macos-latest'
with:
- tag_name: v${{ env.GitVersion_SemVer }}
+ tag_name: v${{ needs.check-release-requirement.outputs.semantic-version }}
generate_release_notes: true
prerelease: ${{ github.ref_name != 'main' }}
- files: ./Installer/Elzik.FmSync.OsxInstaller/x64/Release/fmsync-osx*.zip
+ files: |
+ ./windows-installer/fmsync*.msi
+ ./macos-installer/fmsync-osx*.zip
diff --git a/Build/build-osx-installer.ps1 b/Build/build-osx-installer.ps1
index ce13464..66c8724 100644
--- a/Build/build-osx-installer.ps1
+++ b/Build/build-osx-installer.ps1
@@ -72,7 +72,7 @@ Compress-Archive `
-Force
Test-ExitCode
-dotnet tool update --global GitVersion.Tool
+dotnet tool update --global GitVersion.Tool --version 6.*
Test-ExitCode
$SemVer = (dotnet-gitversion | ConvertFrom-Json).SemVer
diff --git a/Build/build-windows-installer.ps1 b/Build/build-windows-installer.ps1
index 5f1237c..bb908ec 100644
--- a/Build/build-windows-installer.ps1
+++ b/Build/build-windows-installer.ps1
@@ -31,7 +31,7 @@ dotnet build $repoRootPath\Installer\Elzik.FmSync.WindowsInstaller\Elzik.FmSync.
-p:PublishSingleFile=true
Test-ExitCode
-dotnet tool update --global GitVersion.Tool
+dotnet tool update --global GitVersion.Tool --version 6.*
Test-ExitCode
$SemVer = (dotnet-gitversion | ConvertFrom-Json).SemVer
diff --git a/Build/tag-with-semver.ps1 b/Build/tag-with-semver.ps1
index 53b5577..573a3b8 100644
--- a/Build/tag-with-semver.ps1
+++ b/Build/tag-with-semver.ps1
@@ -1,4 +1,4 @@
-dotnet tool update --global GitVersion.Tool
+dotnet tool update --global GitVersion.Tool --version 6.*
$semVer = (dotnet-gitversion | ConvertFrom-Json).SemVer
$tag = "v$semVer"
diff --git a/Installer/Elzik.FmSync.WindowsInstaller/Elzik.FmSync.WindowsInstaller.wixproj b/Installer/Elzik.FmSync.WindowsInstaller/Elzik.FmSync.WindowsInstaller.wixproj
index d94c572..bcf586d 100644
--- a/Installer/Elzik.FmSync.WindowsInstaller/Elzik.FmSync.WindowsInstaller.wixproj
+++ b/Installer/Elzik.FmSync.WindowsInstaller/Elzik.FmSync.WindowsInstaller.wixproj
@@ -2,12 +2,13 @@
false
false
+ net8.0
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive