diff --git a/.github/workflows/nuget-package-template.yml b/.github/workflows/nuget-package-template.yml
index 91ecb02..c0d99e7 100644
--- a/.github/workflows/nuget-package-template.yml
+++ b/.github/workflows/nuget-package-template.yml
@@ -15,6 +15,10 @@ on:
required: true
type: string
description: "The name of the NuGet package"
+ custom_suffix:
+ required: false
+ type: string
+ default: ""
env:
DOTNET_VERSION: '8.0.x'
@@ -82,21 +86,88 @@ jobs:
if [[ -z "$CUSTOM_VERSION" ]]; then
echo "No unprocessed custom version found in the last 10 commits for $PROJECT_NAME. Proceeding to fetch and increment the latest version from the feed."
- # Fetch the latest version and increment it for the specific package
- PACKAGE_ID="${{ inputs.nuget_package_name }}"
- FEED_URL="https://nuget.pkg.github.com/DFE-Digital/query?q=$PACKAGE_ID"
- LATEST_VERSION=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "$FEED_URL" | jq -r '.data[0].version')
+ CUSTOM_SUFFIX=${{ inputs.custom_suffix }}
+
+ # Fetch the latest version and increment it for the specific package
+ PACKAGE_ID="${{ inputs.nuget_package_name }}"
+ FEED_URL="https://api.github.com/orgs/DFE-Digital/packages/nuget/$PACKAGE_ID/versions"
+
+ ALL_VERSIONS=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "$FEED_URL" | jq -r 'if type == "array" then .[].name else empty end')
+
+ if [[ -n "$ALL_VERSIONS" ]]; then
+
+ echo "All Versions: ${ALL_VERSIONS:-None}"
+
+ # Find the latest version with `-prerelease` suffix
+ LATEST_BETA_VERSION=$(echo "$ALL_VERSIONS" | grep -E '\-prerelease$' | sort -V | tail -n 1)
+
+ # Find the latest version without `-prerelease` suffix
+ LATEST_PROD_VERSION=$(echo "$ALL_VERSIONS" | grep -vE '\-prerelease$' | sort -V | tail -n 1)
+
+ # Log the versions we found
+ echo "Latest prerelease version: ${LATEST_BETA_VERSION:-None}"
+ echo "Latest production version: ${LATEST_PROD_VERSION:-None}"
+
+ # Strip `-prerelease` from the prerelease version for comparison
+ STRIPPED_BETA_VERSION=""
+ if [[ -n "$LATEST_BETA_VERSION" ]]; then
+ STRIPPED_BETA_VERSION=$(echo "$LATEST_BETA_VERSION" | sed 's/-prerelease//')
+ echo "Stripped prerelease version: $STRIPPED_BETA_VERSION"
+ fi
+
+ if [[ -n "$CUSTOM_SUFFIX" ]]; then
+ # Scenario 2: PR Build (inputs.custom_suffix has a value)
+ echo "This is a PR build. Custom suffix is: $CUSTOM_SUFFIX"
+
+ if [[ -n "$LATEST_BETA_VERSION" ]]; then
+ # Increment the patch version of the latest prerelease
+ BASE_VERSION=$(echo "$LATEST_BETA_VERSION" | sed 's/-prerelease//')
+ IFS='.' read -r -a VERSION_PARTS <<< "$BASE_VERSION"
+ NEW_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.$((VERSION_PARTS[2] + 1))$CUSTOM_SUFFIX"
+ else
+ # No prerelease version exists; use the latest production version
+ BASE_VERSION="$LATEST_PROD_VERSION"
+ IFS='.' read -r -a VERSION_PARTS <<< "$BASE_VERSION"
+ NEW_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.$((VERSION_PARTS[2] + 1))$CUSTOM_SUFFIX"
+ fi
+
+ echo "New Pre-Release version: $NEW_VERSION"
+
+ else
+ # Scenario 3: Push to Main (inputs.custom_suffix is empty)
+ echo "This is a push to main. Processing for production."
+
+ if [[ "$STRIPPED_BETA_VERSION" == "$LATEST_PROD_VERSION" ]]; then
+ # prerelease matches production; increment patch version
+ BASE_VERSION="$LATEST_PROD_VERSION"
+ IFS='.' read -r -a VERSION_PARTS <<< "$BASE_VERSION"
+ NEW_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.$((VERSION_PARTS[2] + 1))"
+ echo "PreRelease version matches production. Incrementing base version."
+ else
+ # prerelease doesn't match production; promote prerelease to production
+ if [[ -n "$LATEST_BETA_VERSION" ]]; then
+ NEW_VERSION="$STRIPPED_BETA_VERSION"
+ echo "Promoting beta version to production."
+ else
+ # No prerelease version exists; increment production
+ BASE_VERSION="$LATEST_PROD_VERSION"
+ IFS='.' read -r -a VERSION_PARTS <<< "$BASE_VERSION"
+ NEW_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.$((VERSION_PARTS[2] + 1))"
+ echo "No beta version exists. Incrementing production version."
+ fi
+ fi
+
+ echo "New production version: $NEW_VERSION"
+ fi
- if [[ -z "$LATEST_VERSION" || "$LATEST_VERSION" == "null" ]]; then
- echo "No existing version found in the feed. Defaulting to version 1.0.0"
- NEW_VERSION="1.0.0"
- else
- echo "Latest version is $LATEST_VERSION"
- IFS='.' read -r -a VERSION_PARTS <<< "$LATEST_VERSION"
- NEW_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.$((VERSION_PARTS[2] + 1))"
- echo "Incrementing to new version: $NEW_VERSION"
- fi
+ else
+
+ echo "No versions found for package $PACKAGE_ID. Defaulting to 1.0.0."
+ $NEW_VERSION="1.0.0"
+
+ fi
+ # Save the new version
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
fi
diff --git a/.github/workflows/pack-asyncprocessing.yml b/.github/workflows/pack-asyncprocessing.yml
index 840cd2d..487e1fb 100644
--- a/.github/workflows/pack-asyncprocessing.yml
+++ b/.github/workflows/pack-asyncprocessing.yml
@@ -8,9 +8,15 @@ on:
jobs:
build-and-package:
- if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' && github.event.workflow_run.event != 'pull_request' }}
+ if: >
+ github.event.workflow_run.conclusion == 'success' &&
+ (
+ (github.event.workflow_run.head_branch == 'main' && github.event.workflow_run.event == 'push') ||
+ github.event.workflow_run.event == 'pull_request'
+ )
uses: ./.github/workflows/nuget-package-template.yml
with:
project_name: DfE.CoreLibs.AsyncProcessing
project_path: src/DfE.CoreLibs.AsyncProcessing
nuget_package_name: DfE.CoreLibs.AsyncProcessing
+ custom_suffix: ${{ github.event.workflow_run.event == 'pull_request' && '-prerelease' || '' }}
diff --git a/.github/workflows/pack-caching.yml b/.github/workflows/pack-caching.yml
index 174df06..c0ba06a 100644
--- a/.github/workflows/pack-caching.yml
+++ b/.github/workflows/pack-caching.yml
@@ -8,9 +8,15 @@ on:
jobs:
build-and-package:
- if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' && github.event.workflow_run.event != 'pull_request' }}
+ if: >
+ github.event.workflow_run.conclusion == 'success' &&
+ (
+ (github.event.workflow_run.head_branch == 'main' && github.event.workflow_run.event == 'push') ||
+ github.event.workflow_run.event == 'pull_request'
+ )
uses: ./.github/workflows/nuget-package-template.yml
with:
project_name: DfE.CoreLibs.Caching
project_path: src/DfE.CoreLibs.Caching
nuget_package_name: DfE.CoreLibs.Caching
+ custom_suffix: ${{ github.event.workflow_run.event == 'pull_request' && '-prerelease' || '' }}
diff --git a/.github/workflows/pack-contracts.yml b/.github/workflows/pack-contracts.yml
index 8ae7090..026e231 100644
--- a/.github/workflows/pack-contracts.yml
+++ b/.github/workflows/pack-contracts.yml
@@ -8,9 +8,15 @@ on:
jobs:
build-and-package:
- if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' && github.event.workflow_run.event != 'pull_request' }}
+ if: >
+ github.event.workflow_run.conclusion == 'success' &&
+ (
+ (github.event.workflow_run.head_branch == 'main' && github.event.workflow_run.event == 'push') ||
+ github.event.workflow_run.event == 'pull_request'
+ )
uses: ./.github/workflows/nuget-package-template.yml
with:
project_name: DfE.CoreLibs.Contracts
project_path: src/DfE.CoreLibs.Contracts
nuget_package_name: DfE.CoreLibs.Contracts
+ custom_suffix: ${{ github.event.workflow_run.event == 'pull_request' && '-prerelease' || '' }}
diff --git a/.github/workflows/pack-http.yml b/.github/workflows/pack-http.yml
index 4557400..c590297 100644
--- a/.github/workflows/pack-http.yml
+++ b/.github/workflows/pack-http.yml
@@ -8,9 +8,15 @@ on:
jobs:
build-and-package:
- if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' && github.event.workflow_run.event != 'pull_request' }}
+ if: >
+ github.event.workflow_run.conclusion == 'success' &&
+ (
+ (github.event.workflow_run.head_branch == 'main' && github.event.workflow_run.event == 'push') ||
+ github.event.workflow_run.event == 'pull_request'
+ )
uses: ./.github/workflows/nuget-package-template.yml
with:
project_name: DfE.CoreLibs.Http
project_path: src/DfE.CoreLibs.Http
nuget_package_name: DfE.CoreLibs.Http
+ custom_suffix: ${{ github.event.workflow_run.event == 'pull_request' && '-prerelease' || '' }}
diff --git a/.github/workflows/pack-security.yml b/.github/workflows/pack-security.yml
index 1e1bf3b..088dbee 100644
--- a/.github/workflows/pack-security.yml
+++ b/.github/workflows/pack-security.yml
@@ -8,9 +8,15 @@ on:
jobs:
build-and-package:
- if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' && github.event.workflow_run.event != 'pull_request' }}
+ if: >
+ github.event.workflow_run.conclusion == 'success' &&
+ (
+ (github.event.workflow_run.head_branch == 'main' && github.event.workflow_run.event == 'push') ||
+ github.event.workflow_run.event == 'pull_request'
+ )
uses: ./.github/workflows/nuget-package-template.yml
with:
project_name: DfE.CoreLibs.Security
project_path: src/DfE.CoreLibs.Security
nuget_package_name: DfE.CoreLibs.Security
+ custom_suffix: ${{ github.event.workflow_run.event == 'pull_request' && '-prerelease' || '' }}
diff --git a/.github/workflows/pack-testing.yml b/.github/workflows/pack-testing.yml
index 2201015..b8cb2b4 100644
--- a/.github/workflows/pack-testing.yml
+++ b/.github/workflows/pack-testing.yml
@@ -8,9 +8,15 @@ on:
jobs:
build-and-package:
- if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' && github.event.workflow_run.event != 'pull_request' }}
+ if: >
+ github.event.workflow_run.conclusion == 'success' &&
+ (
+ (github.event.workflow_run.head_branch == 'main' && github.event.workflow_run.event == 'push') ||
+ github.event.workflow_run.event == 'pull_request'
+ )
uses: ./.github/workflows/nuget-package-template.yml
with:
project_name: DfE.CoreLibs.Testing
project_path: src/DfE.CoreLibs.Testing
nuget_package_name: DfE.CoreLibs.Testing
+ custom_suffix: ${{ github.event.workflow_run.event == 'pull_request' && '-prerelease' || '' }}
diff --git a/.github/workflows/pack-utilities.yml b/.github/workflows/pack-utilities.yml
index d38b3c9..ff86bd6 100644
--- a/.github/workflows/pack-utilities.yml
+++ b/.github/workflows/pack-utilities.yml
@@ -8,9 +8,15 @@ on:
jobs:
build-and-package:
- if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' && github.event.workflow_run.event != 'pull_request' }}
+ if: >
+ github.event.workflow_run.conclusion == 'success' &&
+ (
+ (github.event.workflow_run.head_branch == 'main' && github.event.workflow_run.event == 'push') ||
+ github.event.workflow_run.event == 'pull_request'
+ )
uses: ./.github/workflows/nuget-package-template.yml
with:
project_name: DfE.CoreLibs.Utilities
project_path: src/DfE.CoreLibs.Utilities
nuget_package_name: DfE.CoreLibs.Utilities
+ custom_suffix: ${{ github.event.workflow_run.event == 'pull_request' && '-prerelease' || '' }}
diff --git a/nuget-deployment.png b/nuget-deployment.png
index 765ef50..d6884c2 100644
Binary files a/nuget-deployment.png and b/nuget-deployment.png differ
diff --git a/src/DfE.CoreLibs.Testing/DfE.CoreLibs.Testing.csproj b/src/DfE.CoreLibs.Testing/DfE.CoreLibs.Testing.csproj
index a5b78fa..0cf220c 100644
--- a/src/DfE.CoreLibs.Testing/DfE.CoreLibs.Testing.csproj
+++ b/src/DfE.CoreLibs.Testing/DfE.CoreLibs.Testing.csproj
@@ -37,10 +37,10 @@
+
PreserveNewest
-
\ No newline at end of file