diff --git a/.github/workflows/continuous-integration-dotnet.yml b/.github/workflows/continuous-integration-dotnet.yml index d1f0023c..f1daac52 100644 --- a/.github/workflows/continuous-integration-dotnet.yml +++ b/.github/workflows/continuous-integration-dotnet.yml @@ -28,7 +28,7 @@ jobs: build-and-test: runs-on: ubuntu-latest permissions: - packages: read + packages: write contents: read steps: - uses: actions/checkout@v4 @@ -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() diff --git a/Dfe.PersonsApi.Client/Dfe.PersonsApi.Client.csproj b/Dfe.PersonsApi.Client/Dfe.PersonsApi.Client.csproj index 53913fd7..5127bfc3 100644 --- a/Dfe.PersonsApi.Client/Dfe.PersonsApi.Client.csproj +++ b/Dfe.PersonsApi.Client/Dfe.PersonsApi.Client.csproj @@ -8,10 +8,15 @@ $(NoWarn);1591 true 1.0.0 + readme.md + DfE Persons API Client + 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. + DFE-Digital - + + diff --git a/Dfe.PersonsApi.Client/Generated/Client.g.cs b/Dfe.PersonsApi.Client/Generated/Client.g.cs index 409dda6b..f004e628 100644 --- a/Dfe.PersonsApi.Client/Generated/Client.g.cs +++ b/Dfe.PersonsApi.Client/Generated/Client.g.cs @@ -147,13 +147,13 @@ public virtual async System.Threading.Tasks.Task 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 { diff --git a/Dfe.PersonsApi.Client/Generated/swagger.json b/Dfe.PersonsApi.Client/Generated/swagger.json index eeb1b877..52cfbadb 100644 --- a/Dfe.PersonsApi.Client/Generated/swagger.json +++ b/Dfe.PersonsApi.Client/Generated/swagger.json @@ -18,7 +18,7 @@ "name": "constituencyName", "in": "path", "required": true, - "description": "The constituency name. ", + "description": "The constituency name.", "schema": { "type": "string" }, @@ -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." } } } diff --git a/Dfe.PersonsApi.Client/readme.md b/Dfe.PersonsApi.Client/readme.md new file mode 100644 index 00000000..8f56ade1 --- /dev/null +++ b/Dfe.PersonsApi.Client/readme.md @@ -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 \ No newline at end of file diff --git a/PersonsApi/Controllers/ConstituenciesController.cs b/PersonsApi/Controllers/ConstituenciesController.cs index 303138ea..659cd66a 100644 --- a/PersonsApi/Controllers/ConstituenciesController.cs +++ b/PersonsApi/Controllers/ConstituenciesController.cs @@ -20,13 +20,13 @@ public ConstituenciesController(IPersonsQueries personQueries) /// /// Retrieve Member of Parliament by constituency name /// - /// The constituency name. + /// The constituency name. /// The cancellation token. /// [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 GetMemberOfParliamentByConstituencyAsync([FromRoute] string constituencyName, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(constituencyName))