Skip to content
Merged
1 change: 0 additions & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ jobs:
run: dotnet nuget push ./Xero.NetStandard.OAuth2/bin/Release/Xero.NetStandard.OAuth2.${{steps.get_latest_release_number.outputs.release_tag}}.nupkg --api-key ${{ secrets.NUGET_APIKEY }} --source https://api.nuget.org/v3/index.json
working-directory: Xero-NetStandard


notify-codegen-repo:
needs: build
if: always()
Expand Down
168 changes: 168 additions & 0 deletions .github/workflows/publish-Oauth2Client-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
name: Publish OAuth2Client Package
on:
workflow_dispatch:
inputs:
cab_id:
description: "CAB id for the change/release"
required: true
type: string
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+' # Triggers on main SDK version tags

jobs:
check-and-publish:

runs-on: ubuntu-latest
environment: prod

outputs:
client_version: ${{steps.calc_version.outputs.version}}
should_publish: ${{steps.calc_version.outputs.should_publish}}

permissions:
contents: write
pull-requests: write

steps:

- name: checkout dotnet repo
uses: actions/checkout@v4
with:
repository: XeroAPI/Xero-NetStandard
path: Xero-NetStandard
fetch-depth: 0 # Fetch all history for git diff

- name: Calculate OAuth2Client version
id: calc_version
run: |
# Get last client tag
LAST_CLIENT_TAG=$(git tag -l 'client-*' --sort=-v:refname | head -n 1)

if [ -z "$LAST_CLIENT_TAG" ]; then
# No previous client tag, start with version from csproj
CURRENT_VERSION=$(grep '<Version>' ./Xero.NetStandard.OAuth2Client/Xero.NetStandard.OAuth2Client.csproj | sed 's/.*<Version>\(.*\)<\/Version>.*/\1/')
echo "No previous client tag found, using csproj version: $CURRENT_VERSION"
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "should_publish=true" >> $GITHUB_OUTPUT
exit 0
fi

LAST_VERSION=${LAST_CLIENT_TAG#client-}
echo "Last OAuth2Client version: $LAST_VERSION (tag: $LAST_CLIENT_TAG)"

# Check if OAuth2Client files changed since last client tag
if git diff --name-only $LAST_CLIENT_TAG HEAD | grep -q 'Xero.NetStandard.OAuth2Client/'; then
echo "OAuth2Client files have changed since $LAST_CLIENT_TAG"

# Increment patch version
IFS='.' read -r major minor patch <<< "$LAST_VERSION"
NEW_VERSION="${major}.${minor}.$((patch + 1))"

echo "Incrementing version: $LAST_VERSION -> $NEW_VERSION"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "should_publish=true" >> $GITHUB_OUTPUT
else
echo "No changes to OAuth2Client since $LAST_CLIENT_TAG"
echo "version=$LAST_VERSION" >> $GITHUB_OUTPUT
echo "should_publish=false" >> $GITHUB_OUTPUT
fi
working-directory: Xero-NetStandard
env:
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: Update csproj version
if: steps.calc_version.outputs.should_publish == 'true'
run: |
NEW_VERSION="${{steps.calc_version.outputs.version}}"
sed -i "s/<Version>.*<\/Version>/<Version>$NEW_VERSION<\/Version>/" \
./Xero.NetStandard.OAuth2Client/Xero.NetStandard.OAuth2Client.csproj
echo "Updated csproj to version $NEW_VERSION"
working-directory: Xero-NetStandard

- name: Setup .NET
if: steps.calc_version.outputs.should_publish == 'true'
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

- name: Restore dependencies
if: steps.calc_version.outputs.should_publish == 'true'
run: dotnet restore
working-directory: Xero-NetStandard

- name: Build
if: steps.calc_version.outputs.should_publish == 'true'
run: dotnet build --no-restore
working-directory: Xero-NetStandard

- name: Create OAuth2Client Package for Nuget.org
if: steps.calc_version.outputs.should_publish == 'true'
run: dotnet pack ./Xero.NetStandard.OAuth2Client/Xero.NetStandard.OAuth2Client.csproj
working-directory: Xero-NetStandard

- name: Publish OAuth2Client Package to Nuget.org
if: steps.calc_version.outputs.should_publish == 'true'
run: dotnet nuget push ./Xero.NetStandard.OAuth2Client/bin/Release/Xero.NetStandard.OAuth2Client.${{steps.calc_version.outputs.version}}.nupkg --api-key ${{ secrets.NUGET_APIKEY }} --source https://api.nuget.org/v3/index.json
working-directory: Xero-NetStandard

- name: Create client tag
if: steps.calc_version.outputs.should_publish == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "client-${{steps.calc_version.outputs.version}}"
git push origin "client-${{steps.calc_version.outputs.version}}"
working-directory: Xero-NetStandard
env:
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}

notify-slack-on-success:
runs-on: ubuntu-latest
needs: check-and-publish
if: success() && needs.check-and-publish.outputs.should_publish == 'true'
permissions:
contents: read
steps:
- name: Checkout Xero-NetStandard repo
uses: actions/checkout@v4
with:
repository: XeroAPI/Xero-NetStandard
path: Xero-NetStandard

- name: Send slack notification on success
uses: ./Xero-NetStandard/.github/actions/notify-slack
with:
heading_text: "OAuth2Client Package publish job has succeeded !"
alert_type: "thumbsup"
job_status: "Success"
XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}}
job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
button_type: "primary"
package_version: ${{needs.check-and-publish.outputs.client_version}}
repo_link: ${{github.server_url}}/${{github.repository}}

notify-slack-on-failure:
runs-on: ubuntu-latest
needs: check-and-publish
if: failure()
permissions:
contents: read
steps:
- name: Checkout Xero-NetStandard repo
uses: actions/checkout@v4
with:
repository: XeroAPI/Xero-NetStandard
path: Xero-NetStandard

- name: Send slack notification on failure
uses: ./Xero-NetStandard/.github/actions/notify-slack
with:
heading_text: "OAuth2Client Package publish job has failed !"
alert_type: "alert"
job_status: "Failed"
XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}}
job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
button_type: "danger"
package_version: ${{needs.check-and-publish.outputs.client_version}}
repo_link: ${{github.server_url}}/${{github.repository}}
Loading