Skip to content

Use continuous delivery only for non-main branches #642

Use continuous delivery only for non-main branches

Use continuous delivery only for non-main branches #642

name: Continuous Delivery
on:
push: {}
pull_request: {}
workflow_dispatch:
inputs:
force-release:
type: boolean
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 }}
strategy:
matrix:
os: [windows-latest, macos-latest]
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: Upload Coverage Badge
if: github.event_name != 'pull_request' && matrix.os == 'windows-latest' && github.actor != 'dependabot[bot]'
uses: exuanbo/actions-deploy-gist@v1
with:
token: ${{ secrets.CODE_COVERAGE_AUTH_TOKEN }}
gist_id: 527882e89a938dc78f61a08c300edec4
gist_description: "code-coverage-${{ github.ref_name }}"
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]'
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: 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: Tag With SemVer
if: steps.release-check.outputs.needs-release == 'True'
run: |
git tag "v${{ env.GitVersion_SemVer }}"
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'
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
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 }}
generate_release_notes: true
prerelease: ${{ github.ref_name != 'main' }}
files: ./Installer/Elzik.FmSync.OsxInstaller/x64/Release/fmsync-osx*.zip