-
Notifications
You must be signed in to change notification settings - Fork 129
[PETOSS-829] added action to publish OAUTH2Client nuget package #627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ryanNexus
wants to merge
10
commits into
master
Choose a base branch
from
PETOSS-829-publish-auth
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
41e755a
[PETOSS-829] added action to publish OAUTH2Client nuget package
5c97419
[PETOSS-829] moved action to publish OAUTH2Client nuget package to it…
0dce143
[PETOSS-829] updated Oauth2Client to have a seperate version tag so i…
1844cd8
[PETOSS-829] updated version to match bump of main sdk so a bump of 0…
6e8564a
[PETOSS-829] removed should publish output as not needed
2ea5274
[PETOSS-829] now commits the .csproj file with new version
5ca5445
Merge branch 'master' into PETOSS-829-publish-auth
ryanNexus ac4371a
[PETOSS-829] moved check for changes to explict step
b2bb2a2
[PETOSS-829] renamed dotnet work flow to match actual purpose
7589dba
[PETOSS-829] removed trigger on push
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,217 @@ | ||
| name: Publish OAuth2Client Package | ||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| cab_id: | ||
| description: "CAB id for the change/release" | ||
| required: true | ||
| type: string | ||
|
|
||
| jobs: | ||
| check-and-publish: | ||
|
|
||
| runs-on: ubuntu-latest | ||
| environment: prod | ||
|
|
||
| outputs: | ||
| # Used to conditionally run publish steps and notifications | ||
| client_version: ${{steps.calc_version.outputs.version}} | ||
| should_publish: ${{steps.check_changes.outputs.has_changes}} | ||
|
|
||
| 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: Check for changes | ||
| id: check_changes | ||
| run: | | ||
| # Get last client tag | ||
| LAST_CLIENT_TAG=$(git tag -l 'client-*' --sort=-v:refname | head -n 1) | ||
| echo "Found last client tag: $LAST_CLIENT_TAG" | ||
| echo "last_client_tag=$LAST_CLIENT_TAG" >> $GITHUB_OUTPUT | ||
|
|
||
| if [ -z "$LAST_CLIENT_TAG" ]; then | ||
| echo "No previous client tag found. Treating as changed (initial release)." | ||
| echo "has_changes=true" >> $GITHUB_OUTPUT | ||
| exit 0 | ||
| fi | ||
|
|
||
| # 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 "Changes detected in Xero.NetStandard.OAuth2Client/" | ||
| echo "has_changes=true" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "No changes detected in Xero.NetStandard.OAuth2Client/" | ||
| echo "has_changes=false" >> $GITHUB_OUTPUT | ||
| fi | ||
| working-directory: Xero-NetStandard | ||
| env: | ||
| GH_TOKEN: ${{secrets.GITHUB_TOKEN}} | ||
|
|
||
| - name: Calculate OAuth2Client version | ||
| id: calc_version | ||
| if: steps.check_changes.outputs.has_changes == 'true' | ||
| run: | | ||
| LAST_CLIENT_TAG="${{ steps.check_changes.outputs.last_client_tag }}" | ||
|
|
||
| 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 | ||
| exit 0 | ||
| fi | ||
|
|
||
| LAST_VERSION=${LAST_CLIENT_TAG#client-} | ||
| echo "Last OAuth2Client version: $LAST_VERSION (tag: $LAST_CLIENT_TAG)" | ||
|
|
||
| # Determine Bump Type from Main SDK tags | ||
| BUMP_TYPE="patch" | ||
| if [[ "$GITHUB_REF_TYPE" == "tag" ]]; then | ||
| CURRENT_MAIN_TAG=$GITHUB_REF_NAME | ||
| # Find previous main tag (exclude current) | ||
| PREV_MAIN_TAG=$(git tag -l '[0-9]*.[0-9]*.[0-9]*' --sort=-v:refname | grep -v "^$CURRENT_MAIN_TAG$" | head -n 1) | ||
|
|
||
| if [ ! -z "$PREV_MAIN_TAG" ]; then | ||
| echo "Main SDK Bump: $PREV_MAIN_TAG -> $CURRENT_MAIN_TAG" | ||
| IFS='.' read -r m1 m2 m3 <<< "$CURRENT_MAIN_TAG" | ||
| IFS='.' read -r p1 p2 p3 <<< "$PREV_MAIN_TAG" | ||
|
|
||
| if [ "$m1" != "$p1" ]; then | ||
| BUMP_TYPE="major" | ||
| elif [ "$m2" != "$p2" ]; then | ||
| BUMP_TYPE="minor" | ||
| fi | ||
| fi | ||
| fi | ||
| echo "Detected bump type: $BUMP_TYPE" | ||
|
|
||
| # Increment version based on bump type | ||
| IFS='.' read -r c1 c2 c3 <<< "$LAST_VERSION" | ||
| if [ "$BUMP_TYPE" == "major" ]; then | ||
| NEW_VERSION="$((c1 + 1)).0.0" | ||
| elif [ "$BUMP_TYPE" == "minor" ]; then | ||
| NEW_VERSION="${c1}.$((c2 + 1)).0" | ||
| else | ||
| NEW_VERSION="${c1}.${c2}.$((c3 + 1))" | ||
| fi | ||
|
|
||
| echo "Incrementing version ($BUMP_TYPE): $LAST_VERSION -> $NEW_VERSION" | ||
| echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT | ||
| 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 | ||
the-chris-mitchell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| - 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: Commit, Push and 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" | ||
|
|
||
| # Commit the version bump | ||
| git add ./Xero.NetStandard.OAuth2Client/Xero.NetStandard.OAuth2Client.csproj | ||
| git commit -m "Bump OAuth2Client version to ${{steps.calc_version.outputs.version}}" | ||
|
|
||
| # Push the commit to master | ||
| git push origin HEAD:master | ||
|
|
||
| # Create and push the tag | ||
| 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: | ||
ryanNexus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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}} | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.