Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
255 changes: 176 additions & 79 deletions .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build & Release
name: Build & Release

on:
pull_request:
Expand All @@ -7,170 +7,267 @@ on:
push:
branches:
- main
- 'beta/**'
- 'release/**'
workflow_dispatch:
inputs:
ref:
description: 'Branch or tag to release from'
required: false
type: string
default: ''
release-version:
description: 'Explicit version (e.g. 12.0.0 or 12.0.0-beta.1). Leave empty or "none" to use GitVersion.'
required: false
type: string
default: ''

jobs:

version:
runs-on: windows-latest
outputs:
semVer: ${{ steps.gitversion.outputs.semVer }}
majorMinorPatch: ${{ steps.gitversion.outputs.majorMinorPatch }}
isPrerelease: ${{ steps.set_prerelease.outputs.is_prerelease }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event.inputs.ref || github.ref }}
fetch-depth: 0

- name: Setup GitVersion
run: dotnet tool install --global GitVersion.Tool --version 5.12.0

- name: Determine Version
id: gitversion
shell: pwsh
run: |
$releaseVersion = "${{ github.event.inputs.release-version }}".Trim()

if ($releaseVersion -and $releaseVersion -ne "none") {
if ($releaseVersion -notmatch '^\d+\.\d+\.\d+(-.+)?$') {
Write-Error "Invalid release-version value '$releaseVersion'. Use an explicit version like 12.3.0 or 12.3.0-beta.1, or leave empty/none to use GitVersion."
exit 1
}
Write-Host "Using explicit version: $releaseVersion"
$semVer = $releaseVersion
$parts = $releaseVersion -split '-', 2
$majorMinorPatch = $parts[0]
$preReleaseTag = if ($parts.Length -gt 1) { $parts[1] } else { "" }
} else {
$json = dotnet-gitversion /config GitVersion.yml | ConvertFrom-Json
$semVer = $json.SemVer
$majorMinorPatch = $json.MajorMinorPatch
$preReleaseTag = $json.PreReleaseTag
}

Write-Host "SemVer: $semVer | MajorMinorPatch: $majorMinorPatch | PreReleaseTag: $preReleaseTag"
echo "semVer=$semVer" >> $env:GITHUB_OUTPUT
echo "majorMinorPatch=$majorMinorPatch" >> $env:GITHUB_OUTPUT
echo "preReleaseTag=$preReleaseTag" >> $env:GITHUB_OUTPUT

- name: Determine Prerelease Flag
id: set_prerelease
shell: pwsh
run: |
$preTag = "${{ steps.gitversion.outputs.preReleaseTag }}"
$isPre = if ($preTag) { "true" } else { "false" }
Write-Host "SemVer: ${{ steps.gitversion.outputs.semVer }} | PreReleaseTag: $preTag | IsPrerelease: $isPre"
echo "is_prerelease=$isPre" >> $env:GITHUB_OUTPUT

build:
runs-on: windows-latest
needs: version
env:
SEMVER: ${{ needs.version.outputs.semVer }}
ASSEMBLY_VERSION: ${{ needs.version.outputs.majorMinorPatch }}.0
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event.inputs.ref || github.ref }}

- name: Restore Packages
run: dotnet restore src\ContinuousClearingTool.sln

- name: Build
run: dotnet build src\ContinuousClearingTool.sln
# Version/AssemblyVersion/FileVersion/InformationalVersion are passed in
# explicitly here (computed by GitVersion in the `version` job above) so
# that every CI-built DLL/NuGet package/Docker image always carries the
# live, correct version. None of the .csproj files hardcode a <Version>
# (see src/Directory.Build.props), so there is no stale version to forget
# to update - local/dev builds simply fall back to "0.0.0-dev".
run: >
dotnet build src\ContinuousClearingTool.sln
-p:Version=${{ env.SEMVER }}
-p:AssemblyVersion=${{ env.ASSEMBLY_VERSION }}
-p:FileVersion=${{ env.ASSEMBLY_VERSION }}
-p:InformationalVersion=${{ env.SEMVER }}

- name: Upload Build Output
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: buildoutput
path: ${{ github.workspace }}/out/net10.0

- name: Upload Entire Output Directory
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: full-build-output
path: ${{ github.workspace }}/out

build-docker:
runs-on: ubuntu-latest
needs: build
needs: [build, version]
env:
SEMVER: ${{ needs.version.outputs.semVer }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event.inputs.ref || github.ref }}

- name: Download Build Output
uses: actions/download-artifact@v4
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: buildoutput
path: ${{ github.workspace }}/out/net10.0

- name: Build Docker Image
run: |
docker build . --file Dockerfile --tag ${{ github.repository }}:continuous-clearing-v11.2.0
docker save ${{ github.repository }}:continuous-clearing-v11.2.0 -o continuous-clearing-v11.2.0.tar
docker build . --file Dockerfile --tag ${{ github.repository }}:continuous-clearing-v${{ env.SEMVER }}
docker save ${{ github.repository }}:continuous-clearing-v${{ env.SEMVER }} -o continuous-clearing-v${{ env.SEMVER }}.tar

- name: Upload Docker Image
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: docker-continuous-clearing
path: |
*.tar

pack-nuget:
runs-on: windows-latest
needs: build
needs: [build, version]
env:
SEMVER: ${{ needs.version.outputs.semVer }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event.inputs.ref || github.ref }}

- name: Download Build Output
uses: actions/download-artifact@v4
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: buildoutput
path: ${{ github.workspace }}/out/net10.0

- name: Pack NuGet Package
run: |
nuget pack CA.nuspec -Version 11.2.0
nuget pack CA.nuspec -Version ${{ env.SEMVER }}

- name: Upload NuGet Package
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: nuget-continuous-clearing
path: |
*.nupkg

release:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
if: |
startsWith(github.ref, 'refs/heads/main') ||
startsWith(github.ref, 'refs/heads/beta/') ||
startsWith(github.ref, 'refs/heads/release/') ||
github.event_name == 'workflow_dispatch'
runs-on: windows-latest
needs: [build, build-docker, pack-nuget]
needs: [build, build-docker, pack-nuget, version]
env:
SEMVER: ${{ needs.version.outputs.semVer }}
IS_PRERELEASE: ${{ needs.version.outputs.isPrerelease }}

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event.inputs.ref || github.ref }}

- name: Download Full Build Output
uses: actions/download-artifact@v4
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: full-build-output
path: ${{ github.workspace }}/out

- name: Download Docker Image
uses: actions/download-artifact@v4
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: docker-continuous-clearing

- name: Download NuGet Package
uses: actions/download-artifact@v4
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: nuget-continuous-clearing

- name: Verify NuGet Package
shell: pwsh
run: |
Get-ChildItem *.nupkg
$expected = "continuous-clearing.${{ env.SEMVER }}.nupkg"
if (-not (Test-Path $expected)) {
Write-Error "Expected NuGet package '$expected' not found."
exit 1
}

- name: Check if version tag already exists
id: check_tag
shell: pwsh
run: |
$tag = "v${{ env.SEMVER }}"
git fetch --tags
$exists = (git tag -l $tag)
if ($exists) {
Write-Host "Tag $tag already exists on this commit history. Skipping release creation to avoid duplicate/escalating tags."
echo "exists=true" >> $env:GITHUB_OUTPUT
} else {
echo "exists=false" >> $env:GITHUB_OUTPUT
}

- name: Create Release
id: create_release
uses: actions/create-release@v1
if: steps.check_tag.outputs.exists == 'false'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v11.2.0
release_name: Release v11.2.0
body: |
${{ github.event.head_commit.message }}
draft: true
prerelease: false
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
shell: pwsh
run: |
$tag = "v${{ env.SEMVER }}"
$notesFile = "${{ github.workspace }}/release_notes.txt"
$message = "$env:COMMIT_MESSAGE"
if ([string]::IsNullOrWhiteSpace($message)) {
$message = "Manual release"
}
Set-Content -Path $notesFile -Value $message
$ghArgs = @($tag, "--title", "Release $tag", "--notes-file", $notesFile, "--repo", "${{ github.repository }}", "--draft")
if ("${{ env.IS_PRERELEASE }}" -eq "true") {
$ghArgs += "--prerelease"
}
gh release create @ghArgs

- name: Compress Full Build Output into ZIP
if: steps.check_tag.outputs.exists == 'false'
run: |
powershell -Command "& {Compress-Archive -Path ${{ github.workspace }}/out/* -DestinationPath ${{ github.workspace }}/continuous-clearing-v11.2.0.zip}"

- name: Upload Full Build Output ZIP to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ github.workspace }}/continuous-clearing-v11.2.0.zip
asset_name: continuous-clearing-v11.2.0.zip
asset_content_type: application/zip

- name: Upload Docker Image(tar) to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./continuous-clearing-v11.2.0.tar
asset_name: continuous-clearing-v11.2.0.tar
asset_content_type: application/x-tar
powershell -Command "& {Compress-Archive -Path ${{ github.workspace }}/out/* -DestinationPath ${{ github.workspace }}/continuous-clearing-v${{ env.SEMVER }}.zip}"

- name: Upload NuGet Package to Release
uses: actions/upload-release-asset@v1
- name: Upload Release Assets
if: steps.check_tag.outputs.exists == 'false'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./continuous-clearing.11.2.0.nupkg
asset_name: continuous-clearing.11.2.0.nupkg
asset_content_type: application/octet-stream

- name: Upload ReadmeOSS_nupkg file to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ github.workspace }}/ReadmeOSS_continuous-clearing_nupkg.html
asset_name: ReadmeOSS_continuous-clearing_nupkg.html
asset_content_type: text/html

- name: Upload ReadmeOSS_Docker file to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ github.workspace }}/ReadmeOSS_continuous-clearing_DockerImage.html
asset_name: ReadmeOSS_continuous-clearing_DockerImage.html
asset_content_type: text/html
run: |
gh release upload v${{ env.SEMVER }} `
"${{ github.workspace }}/continuous-clearing-v${{ env.SEMVER }}.zip" `
"./continuous-clearing-v${{ env.SEMVER }}.tar" `
"./continuous-clearing.${{ env.SEMVER }}.nupkg" `
"${{ github.workspace }}/ReadmeOSS_continuous-clearing_nupkg.html" `
"${{ github.workspace }}/ReadmeOSS_continuous-clearing_DockerImage.html" `
--repo "${{ github.repository }}"
30 changes: 24 additions & 6 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
mode: Mainline
branches:
master:
regex: ^master$|^main$
ignore:
sha: [408943429d1788227ad19ef6434d1fb44257263c, 51eaa765411149f8411676ed421b6274b38aeb4b,d0aa8cbdab2a03b0cb34eda9022e8ffd87655260]
mode: Mainline
branches:
master:
regex: ^master$|^main$
source-branches: []
increment: Patch
beta:
regex: ^beta[/-]
tag: beta
source-branches: [master]
increment: None
release:
regex: ^release[/-]
tag: rc
source-branches: [master]
increment: None
pull-request:
regex: ^(pull|pull\-requests|pr)[/-]
tag: PullRequest
increment: Inherit
source-branches: [master, beta, release]
is-source-branch-for: []
ignore:
sha: [408943429d1788227ad19ef6434d1fb44257263c, 51eaa765411149f8411676ed421b6274b38aeb4b,d0aa8cbdab2a03b0cb34eda9022e8ffd87655260]
2 changes: 1 addition & 1 deletion src/SIT.APICommunications/ApiConstant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static class ApiConstant
/// <summary>
/// The API suffix for SW360 release URL endpoints.
/// </summary>
public const string Sw360ReleaseUrlApiSuffix = "/group/guest/components/-/component/release/detailRelease/";
public const string Sw360ReleaseUrlApiSuffix = "/components/releases/detail/";

/// <summary>
/// The API endpoint for searching SW360 releases by external ID.
Expand Down
Loading
Loading