Skip to content

Commit

Permalink
Updated to trigger deployment (#581)
Browse files Browse the repository at this point in the history
* Updated to trigger deployment

* Added readme.md file

* Updated package permission

* Updated package description

* Modfied the CI to get build version

* Fixed build version module path

* Modified CI to update package version

* Added script to detect and increment version

* Updated CI script to increment package verison automatically

* Updated to bump the version

* Auto commit the updated csproj file

* Updated the CI file to commit the new version tot eh repo

* Updated CI file with new logic to commit version changes

* Updated CI file to detect version from the nuget feed

* Added osnition if the source exist then don't add it

* Added a different method to search the feed

* Fetching the list to see what is there and in what format their name is!

* Getting raw format of the nuget lists to detemine how to build jq query

* Updated to get the package version from the feed directly

* Updated with the latest version of logic to get package version

* Updated so it reads the commit message for a new mintor na dmajor update and if the package doesnt exist then it will default to 1.0.0

* printing commit message to see what it looks likein the GA env

* Changed the way we retrieve commit message

* Check last 10 commit messages

* Updated to trigger CI version update logic
(#update package version to 1.1.2)

* Updated to make the version update conditional

* Added more condition to make sure it is triggered only if it is a merge into main and not a PR

* Defaulting the version to 1.0.0

* Reading last 3 commits

---------

Co-authored-by: Farshad DASHTI <[email protected]>
  • Loading branch information
FrostyApeOne and Farshad DASHTI authored Aug 16, 2024
1 parent 4e6f1b3 commit ea8c248
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 13 deletions.
48 changes: 44 additions & 4 deletions .github/workflows/continuous-integration-dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
build-and-test:
runs-on: ubuntu-latest
permissions:
packages: read
packages: write
contents: read
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -103,15 +103,55 @@ jobs:
with:
filters: |
client:
- 'Dfe.PersonsApi.Client/**'
- 'Dfe.PersonsApi.Client/**'
- name: Set up curl and jq
run: sudo apt-get install -y curl jq

- name: Check for custom version in commit message or check the feed for the latest version and increment it
id: check_custom_version
run: |
# Retrieve the last 3 commit messages
COMMIT_MESSAGES=$(git log -n 3 --pretty=format:%B)
echo "Commit Messages:"
echo "$COMMIT_MESSAGES"

# Search for custom version update pattern in the last 10 commits
CUSTOM_VERSION=$(echo "$COMMIT_MESSAGES" | grep -oP '\(#update package version to \K([0-9]+\.[0-9]+\.[0-9]+)' | head -n 1)

if [[ -n "$CUSTOM_VERSION" ]]; then
echo "Using custom version: $CUSTOM_VERSION"
echo "NEW_VERSION=$CUSTOM_VERSION" >> $GITHUB_ENV
else
echo "No custom version found in the commit messages."
# Fetch the latest version and increment the version
PACKAGE_ID="Dfe.PersonsApi.Client"
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')

if [[ -z "$LATEST_VERSION" ]]; 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

echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
fi
shell: /usr/bin/bash -e {0}
if: steps.person-api-changes.outputs.client == 'true' && github.event_name != 'pull_request'

- name: Build, pack and publish
working-directory: Dfe.PersonsApi.Client
run: |
dotnet build -c Release
dotnet pack -c Release --output .
dotnet pack -c Release -p:PackageVersion=${{ env.NEW_VERSION }} --output .
dotnet nuget push "*.nupkg" --api-key ${{ secrets.GITHUB_TOKEN }} --source https://nuget.pkg.github.com/DFE-Digital/index.json
if: steps.person-api-changes.outputs.client == 'true'
if: steps.person-api-changes.outputs.client == 'true' && github.event_name != 'pull_request'

- name: Stop containers
if: always()
Expand Down
7 changes: 6 additions & 1 deletion Dfe.PersonsApi.Client/Dfe.PersonsApi.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
<NoWarn>$(NoWarn);1591</NoWarn>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.0.0</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
<Title>DfE Persons API Client</Title>
<Description>The Persons API Client Library provides a convenient and straightforward way to interact with the Persons API, a service that delivers contact and basic personal details of key individuals responsible within various organizations associated with the DfE.</Description>
<Authors>DFE-Digital</Authors>
</PropertyGroup>

<ItemGroup>
<None Include="bin\$(Configuration)\$(TargetFramework)\Dfe.PersonsApi.Client.xml" Pack="true" PackagePath="lib\$(TargetFramework)\" />
<None Include="bin\$(Configuration)\$(TargetFramework)\Dfe.PersonsApi.Client.xml" Pack="true" PackagePath="\" />
<None Include="readme.md" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Dfe.PersonsApi.Client/Generated/Client.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ public virtual async System.Threading.Tasks.Task<MemberOfParliament> GetMemberOf
if (status_ == 404)
{
string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new PersonsApiException("Constituency not found", status_, responseText_, headers_, null);
throw new PersonsApiException("Constituency not found.", status_, responseText_, headers_, null);
}
else
if (status_ == 400)
{
string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new PersonsApiException("Constituency cannot be null or empty", status_, responseText_, headers_, null);
throw new PersonsApiException("Constituency cannot be null or empty.", status_, responseText_, headers_, null);
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions Dfe.PersonsApi.Client/Generated/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"name": "constituencyName",
"in": "path",
"required": true,
"description": "The constituency name. ",
"description": "The constituency name.",
"schema": {
"type": "string"
},
Expand All @@ -37,10 +37,10 @@
}
},
"404": {
"description": "Constituency not found"
"description": "Constituency not found."
},
"400": {
"description": "Constituency cannot be null or empty"
"description": "Constituency cannot be null or empty."
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions Dfe.PersonsApi.Client/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Persons API Client Library

The Persons API Client Library provides a convenient and straightforward way to interact with the Persons API, a service that delivers contact and basic personal details of key individuals responsible within various organizations associated with the Department for Education (DfE).

## Overview

The Persons API serves as a centralised resource for obtaining up-to-date contact information and personal details of individuals who hold significant roles across different organizations under the DfE's purview. This API enables seamless access to essential information, ensuring that communication and engagement with these key personnel are both efficient and effective.

## Key Features

- **Comprehensive Contact Information**: Access detailed contact information for individuals across multiple organizations.
- **Personal Details**: Retrieve basic personal details, including names, roles, and affiliations within the DfE ecosystem.
- **Simple Integration**: Easily integrate with your .NET applications using this client library, which abstracts the complexities of interacting with the underlying API.

## Installation

To install the Persons API Client Library, use the following command in your .NET project:

```sh
dotnet add package Dfe.PersonsApi.Client
6 changes: 3 additions & 3 deletions PersonsApi/Controllers/ConstituenciesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public ConstituenciesController(IPersonsQueries personQueries)
/// <summary>
/// Retrieve Member of Parliament by constituency name
/// </summary>
/// <param name="constituencyName">The constituency name. </param>
/// <param name="constituencyName">The constituency name.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
[HttpGet("{constituencyName}/mp")]
[SwaggerResponse(200, "A Person object representing the Member of Parliament.", typeof(MemberOfParliament))]
[SwaggerResponse(404, "Constituency not found")]
[SwaggerResponse(400, "Constituency cannot be null or empty")]
[SwaggerResponse(404, "Constituency not found.")]
[SwaggerResponse(400, "Constituency cannot be null or empty.")]
public async Task<IActionResult> GetMemberOfParliamentByConstituencyAsync([FromRoute] string constituencyName, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(constituencyName))
Expand Down

0 comments on commit ea8c248

Please sign in to comment.