diff --git a/.github/workflows/dotnet.yml b/.github/workflows/publish-Oauth2-package.yml similarity index 95% rename from .github/workflows/dotnet.yml rename to .github/workflows/publish-Oauth2-package.yml index 26dc1927..0c648431 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/publish-Oauth2-package.yml @@ -1,4 +1,4 @@ -name: Publish & Release SDK +name: Publish OAuth2 Package on: workflow_dispatch: inputs: @@ -49,15 +49,14 @@ jobs: run: dotnet build --no-restore working-directory: Xero-NetStandard - - name: Create Package for Nuget.org\ + - name: Create OAuth2 Package for Nuget.org run: dotnet pack working-directory: Xero-NetStandard - - name: Publish Package to Nuget.org + - name: Publish OAuth2 Package to Nuget.org 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() @@ -125,7 +124,7 @@ jobs: - name: Send slack notification on success uses: ./Xero-NetStandard/.github/actions/notify-slack with: - heading_text: "Publish job has succeeded !" + heading_text: "OAuth2 Package publish job has succeeded !" alert_type: "thumbsup" job_status: "Success" XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}} @@ -150,7 +149,7 @@ jobs: - name: Send slack notification on failure uses: ./Xero-NetStandard/.github/actions/notify-slack with: - heading_text: "Publish job has failed !" + heading_text: "OAuth2 Package publish job has failed !" alert_type: "alert" job_status: "Failed" XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}} diff --git a/.github/workflows/publish-Oauth2Client-package.yml b/.github/workflows/publish-Oauth2Client-package.yml new file mode 100644 index 00000000..9e1a050b --- /dev/null +++ b/.github/workflows/publish-Oauth2Client-package.yml @@ -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 '' ./Xero.NetStandard.OAuth2Client/Xero.NetStandard.OAuth2Client.csproj | sed 's/.*\(.*\)<\/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>/$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: 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: + 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}}