Skip to content

Commit

Permalink
Split Build into Jobs (#97)
Browse files Browse the repository at this point in the history
* 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 eadde10.

* 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 83d549c.

* Upgrade wix GitVersion

* Revert "Upgrade wix GitVersion"

This reverts commit 5f4320e.

* 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 26e1ea1.
  • Loading branch information
elzik authored Oct 26, 2024
1 parent b509e70 commit 1f40d4b
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 42 deletions.
129 changes: 91 additions & 38 deletions .github/workflows/continuous-delivery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}
Expand All @@ -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
2 changes: 1 addition & 1 deletion Build/build-osx-installer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Build/build-windows-installer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Build/tag-with-semver.ps1
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
<PropertyGroup>
<UpdateAssemblyInfo>false</UpdateAssemblyInfo>
<GenerateGitVersionInformation>false</GenerateGitVersionInformation>
<GitVersionTargetFramework>net8.0</GitVersionTargetFramework>
</PropertyGroup>
<ItemGroup>
<None Include="LICENSE.rtf" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="GitVersion.MsBuild" Version="5.12.0">
<PackageReference Include="GitVersion.MsBuild" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down

0 comments on commit 1f40d4b

Please sign in to comment.