66 description : " CAB id for the change/release"
77 required : true
88 type : string
9+ push :
10+ tags :
11+ - ' [0-9]+.[0-9]+.[0-9]+' # Triggers on main SDK version tags
912
1013jobs :
11- build :
14+ check-and-publish :
1215
1316 runs-on : ubuntu-latest
1417 environment : prod
1518
19+ outputs :
20+ client_version : ${{steps.calc_version.outputs.version}}
21+ should_publish : ${{steps.calc_version.outputs.should_publish}}
22+
1623 permissions :
1724 contents : write
1825 pull-requests : write
@@ -24,32 +31,96 @@ jobs:
2431 with :
2532 repository : XeroAPI/Xero-NetStandard
2633 path : Xero-NetStandard
34+ fetch-depth : 0 # Fetch all history for git diff
35+
36+ - name : Calculate OAuth2Client version
37+ id : calc_version
38+ run : |
39+ # Get last client tag
40+ LAST_CLIENT_TAG=$(git tag -l 'client-*' --sort=-v:refname | head -n 1)
41+
42+ if [ -z "$LAST_CLIENT_TAG" ]; then
43+ # No previous client tag, start with version from csproj
44+ CURRENT_VERSION=$(grep '<Version>' ./Xero.NetStandard.OAuth2Client/Xero.NetStandard.OAuth2Client.csproj | sed 's/.*<Version>\(.*\)<\/Version>.*/\1/')
45+ echo "No previous client tag found, using csproj version: $CURRENT_VERSION"
46+ echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
47+ echo "should_publish=true" >> $GITHUB_OUTPUT
48+ exit 0
49+ fi
50+
51+ LAST_VERSION=${LAST_CLIENT_TAG#client-}
52+ echo "Last OAuth2Client version: $LAST_VERSION (tag: $LAST_CLIENT_TAG)"
53+
54+ # Check if OAuth2Client files changed since last client tag
55+ if git diff --name-only $LAST_CLIENT_TAG HEAD | grep -q 'Xero.NetStandard.OAuth2Client/'; then
56+ echo "OAuth2Client files have changed since $LAST_CLIENT_TAG"
57+
58+ # Increment patch version
59+ IFS='.' read -r major minor patch <<< "$LAST_VERSION"
60+ NEW_VERSION="${major}.${minor}.$((patch + 1))"
61+
62+ echo "Incrementing version: $LAST_VERSION -> $NEW_VERSION"
63+ echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
64+ echo "should_publish=true" >> $GITHUB_OUTPUT
65+ else
66+ echo "No changes to OAuth2Client since $LAST_CLIENT_TAG"
67+ echo "version=$LAST_VERSION" >> $GITHUB_OUTPUT
68+ echo "should_publish=false" >> $GITHUB_OUTPUT
69+ fi
70+ working-directory : Xero-NetStandard
71+ env :
72+ GH_TOKEN : ${{secrets.GITHUB_TOKEN}}
73+
74+ - name : Update csproj version
75+ if : steps.calc_version.outputs.should_publish == 'true'
76+ run : |
77+ NEW_VERSION="${{steps.calc_version.outputs.version}}"
78+ sed -i "s/<Version>.*<\/Version>/<Version>$NEW_VERSION<\/Version>/" \
79+ ./Xero.NetStandard.OAuth2Client/Xero.NetStandard.OAuth2Client.csproj
80+ echo "Updated csproj to version $NEW_VERSION"
81+ working-directory : Xero-NetStandard
2782
2883 - name : Setup .NET
84+ if : steps.calc_version.outputs.should_publish == 'true'
2985 uses : actions/setup-dotnet@v4
3086 with :
3187 dotnet-version : 8.0.x
3288
3389 - name : Restore dependencies
90+ if : steps.calc_version.outputs.should_publish == 'true'
3491 run : dotnet restore
3592 working-directory : Xero-NetStandard
3693
3794 - name : Build
95+ if : steps.calc_version.outputs.should_publish == 'true'
3896 run : dotnet build --no-restore
3997 working-directory : Xero-NetStandard
4098
4199 - name : Create OAuth2Client Package for Nuget.org
100+ if : steps.calc_version.outputs.should_publish == 'true'
42101 run : dotnet pack ./Xero.NetStandard.OAuth2Client/Xero.NetStandard.OAuth2Client.csproj
43102 working-directory : Xero-NetStandard
44103
45104 - name : Publish OAuth2Client Package to Nuget.org
46- run : dotnet nuget push ./Xero.NetStandard.OAuth2Client/bin/Release/Xero.NetStandard.OAuth2Client.*.nupkg --api-key ${{ secrets.NUGET_APIKEY }} --source https://api.nuget.org/v3/index.json
105+ if : steps.calc_version.outputs.should_publish == 'true'
106+ 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
107+ working-directory : Xero-NetStandard
108+
109+ - name : Create client tag
110+ if : steps.calc_version.outputs.should_publish == 'true'
111+ run : |
112+ git config user.name "github-actions[bot]"
113+ git config user.email "github-actions[bot]@users.noreply.github.com"
114+ git tag "client-${{steps.calc_version.outputs.version}}"
115+ git push origin "client-${{steps.calc_version.outputs.version}}"
47116 working-directory : Xero-NetStandard
117+ env :
118+ GH_TOKEN : ${{secrets.GITHUB_TOKEN}}
48119
49120 notify-slack-on-success :
50121 runs-on : ubuntu-latest
51- needs : build
52- if : success()
122+ needs : check-and-publish
123+ if : success() && needs.check-and-publish.outputs.should_publish == 'true'
53124 permissions :
54125 contents : read
55126 steps :
@@ -68,12 +139,12 @@ jobs:
68139 XERO_SLACK_WEBHOOK_URL : ${{secrets.XERO_SLACK_WEBHOOK_URL}}
69140 job_url : " https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
70141 button_type : " primary"
71- package_version : " OAuth2Client "
142+ package_version : ${{needs.check-and-publish.outputs.client_version}}
72143 repo_link : ${{github.server_url}}/${{github.repository}}
73144
74145 notify-slack-on-failure :
75146 runs-on : ubuntu-latest
76- needs : build
147+ needs : check-and-publish
77148 if : failure()
78149 permissions :
79150 contents : read
93164 XERO_SLACK_WEBHOOK_URL : ${{secrets.XERO_SLACK_WEBHOOK_URL}}
94165 job_url : " https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
95166 button_type : " danger"
96- package_version : " OAuth2Client "
167+ package_version : ${{needs.check-and-publish.outputs.client_version}}
97168 repo_link : ${{github.server_url}}/${{github.repository}}
0 commit comments