From 4fd7b46e2dae554fa58a2e9b9bfdcc1997755304 Mon Sep 17 00:00:00 2001 From: Chris Mitchell Date: Fri, 31 Oct 2025 15:35:03 +1300 Subject: [PATCH] [PETOSS-829] Increment version using script from exec hook instead of separate workflow --- .github/workflows/create-github-pr.yml | 107 -------------------- .github/workflows/create-github-release.yml | 11 +- .releaserc | 5 +- scripts/update-version.sh | 15 +++ 4 files changed, 27 insertions(+), 111 deletions(-) delete mode 100644 .github/workflows/create-github-pr.yml create mode 100755 scripts/update-version.sh diff --git a/.github/workflows/create-github-pr.yml b/.github/workflows/create-github-pr.yml deleted file mode 100644 index 8eb382d9b..000000000 --- a/.github/workflows/create-github-pr.yml +++ /dev/null @@ -1,107 +0,0 @@ -name: Create Github PR for OpenAPI Spec - -on: - release: - types: [published] - -jobs: - create-github-pr: - runs-on: ubuntu-latest - permissions: - contents: write - pull-requests: write - - steps: - - name: Checkout Repository - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Fetch Latest release number - id: get_latest_release_number - run: | - latest_version=$(gh release view --json tagName --jq '.tagName') - echo "Latest release version is - $latest_version" - echo "releaseVersion=$latest_version" >> $GITHUB_OUTPUT - env: - GH_TOKEN: ${{ github.token }} - - - name: Set up branch name - id: identify_branch_name - run: | - branch_name='OAS-version-update-${{steps.get_latest_release_number.outputs.releaseVersion}}' - echo "branchName=$branch_name" >> $GITHUB_OUTPUT - - - name: Checkout branch - run: | - if git ls-remote --heads origin ${{steps.identify_branch_name.outputs.branchName}} | grep -q "refs/heads/${{steps.identify_branch_name.outputs.branchName}}"; then - echo "checking out existing branch" - git fetch origin > /dev/null 2>&1 - git checkout ${{steps.identify_branch_name.outputs.branchName}} - else - echo "branch does not exists, creating new branch" - echo "branchName *****>> ${{steps.identify_branch_name.outputs.branchName}}" - git checkout -b ${{steps.identify_branch_name.outputs.branchName}} - fi - - - name: Update OAS version of the spec yaml files - run: | - for file in xero_accounting.yaml xero_assets.yaml xero_bankfeeds.yaml xero_files.yaml xero-app-store.yaml xero-finance.yaml xero-identity.yaml xero-payroll-au.yaml xero-payroll-nz.yaml xero-payroll-uk.yaml xero-projects.yaml; do - yq eval --no-colors --prettyPrint ".info.version = \"${{steps.get_latest_release_number.outputs.releaseVersion}}\"" -i "$file" - echo "updated version in $file" - done - - - name: Staging & commiting - id: detect-changes - run: | - CHANGES_DETECTED=$(git diff) - if [ -z "$CHANGES_DETECTED" ]; then - echo "no new changes, nothing to commit" - echo "changes_detected=false" >> $GITHUB_OUTPUT - else - echo "changes_detected=true" >> $GITHUB_OUTPUT - echo "running the git commands......" - - git branch - - echo "git status 1" - git status - - echo 'staging the changes' - git add --all - - echo 'git status' - git diff - - echo "git config setup" - git config --global user.name "Github Actions" - git config --global user.email "actions@github.com" - - echo 'commiting changes....' - git commit -m "chore: version update for all the yaml files" - fi - - - name: Pushing the Branch - run: | - if [ "${{steps.detect-changes.outputs.changes_detected}}" == "true" ]; then - echo "pushing the code to ${{steps.identify_branch_name.outputs.branchName}}" - git branch - git push origin ${{steps.identify_branch_name.outputs.branchName}} - else - echo "branch is already up to date" - fi - - - name: Create PR - run: | - if [ "${{steps.detect-changes.outputs.changes_detected}}" == "true" ]; then - echo "Creating PR in ${{steps.identify_branch_name.outputs.branchName}}" - gh pr create \ - --title "OAS version update - ${{steps.get_latest_release_number.outputs.releaseVersion}}" \ - --base master \ - --head ${{steps.identify_branch_name.outputs.branchName}} \ - --body "chore: version update for all the yaml files" - else - echo "PR is already up to date" - fi - env: - GH_TOKEN: ${{ github.token }} diff --git a/.github/workflows/create-github-release.yml b/.github/workflows/create-github-release.yml index 082668aca..d9c708054 100644 --- a/.github/workflows/create-github-release.yml +++ b/.github/workflows/create-github-release.yml @@ -22,7 +22,14 @@ jobs: with: node-version: 20 + - name: Get github app access token + id: get_access_token + uses: actions/create-github-app-token@v2 + with: + app-id: ${{ vars.XERO_PUBLIC_APP_ID }} + private-key: ${{ secrets.XERO_PUBLIC_BOT_KEY }} + - name: Perform release - run: npx semantic-release + run: npx --package @semantic-release/exec semantic-release env: - GH_TOKEN: ${{ github.token }} + GH_TOKEN: ${{ steps.get_access_token.outputs.token }} diff --git a/.releaserc b/.releaserc index 7e81f4c76..91507a549 100644 --- a/.releaserc +++ b/.releaserc @@ -15,11 +15,12 @@ } ], [ - "@semantic-release/github", + "@semantic-release/exec", { - "draftRelease": true + "prepareCmd": "./update-version.sh ${nextRelease.version}" } ], + "@semantic-release/github", "@semantic-release/commit-analyzer" ] } diff --git a/scripts/update-version.sh b/scripts/update-version.sh new file mode 100755 index 000000000..183b31e12 --- /dev/null +++ b/scripts/update-version.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +versionNumber=${1:?Version number is required as first argument} +branchName=${2:-master} + +git checkout "$branchName" + +for file in xero*.yaml; do + yq eval --no-colors --prettyPrint ".info.version = \"$versionNumber\"" -i "$file" + echo "updated version in $file to $versionNumber" +done + +git add xero*.yaml +git commit -m "chore: bump version to $versionNumber" +git push origin "$branchName" \ No newline at end of file