11name : Create Github PR for OpenAPI Spec
22
33on :
4- release :
5- types : [published]
4+ release :
5+ types : [published]
66
77jobs :
8- create-github-pr :
9- runs-on : ubuntu-latest
10- permissions :
11- contents : write
12- pull-requests : write
13-
14- steps :
15- - name : Checkout Repository
16- uses : actions/checkout@v4
17- with :
18- ref : ' master'
19-
20- - name : Install get-access-token dependencies
21- run : npm ci
22- working-directory : ${{ github.workspace }}/.github/get-access-token
23-
24- - name : Get github app access token
25- id : get_access_token
26- env :
27- GITHUB_APP_ID : ${{ secrets.XERO_GITHUB_APP_ID }}
28- GITHUB_APP_PRIVATE_KEY : ${{ secrets.XERO_GITHUB_APPLICATION_KEY }}
29- uses : actions/github-script@v7
30- with :
31- result-encoding : string
32- script : |
33- const { getAccessToken } = await import('${{ github.workspace }}/.github/get-access-token/index.js')
34- const token = await getAccessToken()
35- return token
8+ create-github-pr :
9+ runs-on : ubuntu-latest
10+ permissions :
11+ contents : write
12+ pull-requests : write
3613
37- - name : Fetch Latest release number
38- id : get_latest_release_number
39- run : |
40- latest_version=$(gh release view --json tagName --jq '.tagName')
41- echo "Latest release version is - $latest_version"
42- echo "releaseVersion=$latest_version" >> $GITHUB_OUTPUT
43- env :
44- GH_TOKEN : ${{steps.get_access_token.outputs.result}}
14+ steps :
15+ - name : Checkout Repository
16+ uses : actions/checkout@v4
17+ with :
18+ ref : " master"
4519
20+ - name : Install get-access-token dependencies
21+ run : npm ci
22+ working-directory : ${{ github.workspace }}/.github/get-access-token
4623
47- - name : Set up branch name
48- id : identify_branch_name
49- run : |
50- branch_name='OAS-version-update-${{steps.get_latest_release_number.outputs.releaseVersion}}'
51- echo "branchName=$branch_name" >> $GITHUB_OUTPUT
24+ - name : Get github app access token
25+ id : get_access_token
26+ env :
27+ GITHUB_APP_ID : ${{ secrets.XERO_GITHUB_APP_ID }}
28+ GITHUB_APP_PRIVATE_KEY : ${{ secrets.XERO_GITHUB_APPLICATION_KEY }}
29+ uses : actions/github-script@v7
30+ with :
31+ result-encoding : string
32+ script : |
33+ const { getAccessToken } = await import('${{ github.workspace }}/.github/get-access-token/index.js')
34+ const token = await getAccessToken()
35+ return token
5236
53- - name : Checkout branch
54- run : |
55- if git ls-remote --heads origin ${{steps.identify_branch_name.outputs.branchName}} | grep -q "refs/heads/${{steps.identify_branch_name.outputs.branchName}}"; then
56- echo "checking out existing branch"
57- git fetch origin > /dev/null 2>&1
58- git checkout ${{steps.identify_branch_name.outputs.branchName}}
59- else
60- echo "branch does not exists, creating new branch"
61- echo "branchName *****>> ${{steps.identify_branch_name.outputs.branchName}}"
62- git checkout -b ${{steps.identify_branch_name.outputs.branchName}}
63- fi
37+ - name : Fetch Latest release number
38+ id : get_latest_release_number
39+ run : |
40+ latest_version=$(gh release view --json tagName --jq '.tagName')
41+ echo "Latest release version is - $latest_version"
42+ echo "releaseVersion=$latest_version" >> $GITHUB_OUTPUT
43+ env :
44+ GH_TOKEN : ${{steps.get_access_token.outputs.result}}
6445
65- - name : Update OAS version of the spec yaml files
66- run : |
67- 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
68- yq eval --no-colors --prettyPrint ".info.version = \"${{steps.get_latest_release_number.outputs.releaseVersion}}\"" -i "$file"
69- echo "updated version in $file"
70- done
46+ - name : Set up branch name
47+ id : identify_branch_name
48+ run : |
49+ branch_name='OAS-version-update-${{steps.get_latest_release_number.outputs.releaseVersion}}'
50+ echo "branchName=$branch_name" >> $GITHUB_OUTPUT
7151
72- - name : Staging & commiting
73- id : detect-changes
74- run : |
75- CHANGES_DETECTED=$(git diff)
76- if [ -z "$CHANGES_DETECTED" ]; then
77- echo "no new changes, nothing to commit"
78- echo "changes_detected=false" >> $GITHUB_OUTPUT
79- else
80- echo "changes_detected=true" >> $GITHUB_OUTPUT
81- echo "running the git commands......"
52+ - name : Checkout branch
53+ run : |
54+ if git ls-remote --heads origin ${{steps.identify_branch_name.outputs.branchName}} | grep -q "refs/heads/${{steps.identify_branch_name.outputs.branchName}}"; then
55+ echo "checking out existing branch"
56+ git fetch origin > /dev/null 2>&1
57+ git checkout ${{steps.identify_branch_name.outputs.branchName}}
58+ else
59+ echo "branch does not exists, creating new branch"
60+ echo "branchName *****>> ${{steps.identify_branch_name.outputs.branchName}}"
61+ git checkout -b ${{steps.identify_branch_name.outputs.branchName}}
62+ fi
8263
83- git branch
64+ - name : Update OAS version of the spec yaml files
65+ run : |
66+ 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
67+ yq eval --no-colors --prettyPrint ".info.version = \"${{steps.get_latest_release_number.outputs.releaseVersion}}\"" -i "$file"
68+ echo "updated version in $file"
69+ done
8470
85- echo "git status 1"
86- git status
87-
88- echo 'staging the changes'
89- git add --all
90-
91- echo 'git status'
92- git diff
93-
94- echo "git config setup"
95- git config --global user.name "Github Actions"
96- git config --global user.email "[email protected] " 97-
98- echo 'commiting changes....'
99- git commit -m "chore: version update for all the yaml files"
100- fi
71+ - name : Staging & commiting
72+ id : detect-changes
73+ run : |
74+ CHANGES_DETECTED=$(git diff)
75+ if [ -z "$CHANGES_DETECTED" ]; then
76+ echo "no new changes, nothing to commit"
77+ echo "changes_detected=false" >> $GITHUB_OUTPUT
78+ else
79+ echo "changes_detected=true" >> $GITHUB_OUTPUT
80+ echo "running the git commands......"
10181
102- - name : Pushing the Branch
103- run : |
104- if [ "${{steps.detect-changes.outputs.changes_detected}}" == "true" ]; then
105- echo "pushing the code to ${{steps.identify_branch_name.outputs.branchName}}"
106- git branch
107- git push origin ${{steps.identify_branch_name.outputs.branchName}}
108- else
109- echo "branch is already up to date"
110- fi
82+ git branch
11183
112- - name : Create PR
113- run : |
114- if [ "${{steps.detect-changes.outputs.changes_detected}}" == "true" ]; then
115- echo "Creating PR in ${{steps.identify_branch_name.outputs.branchName}}"
116- gh pr create \
117- --title "OAS version update - ${{steps.get_latest_release_number.outputs.releaseVersion}}" \
118- --base master \
119- --head ${{steps.identify_branch_name.outputs.branchName}} \
120- --body "chore: version update for all the yaml files"
121- else
122- echo "PR is already up to date"
123- fi
124- env :
125- GH_TOKEN : ${{steps.get_access_token.outputs.result}}
84+ echo "git status 1"
85+ git status
86+
87+ echo 'staging the changes'
88+ git add --all
89+
90+ echo 'git status'
91+ git diff
92+
93+ echo "git config setup"
94+ git config --global user.name "Github Actions"
95+ git config --global user.email "[email protected] " 96+
97+ echo 'commiting changes....'
98+ git commit -m "chore: version update for all the yaml files"
99+ fi
126100
127-
101+ - name : Pushing the Branch
102+ run : |
103+ if [ "${{steps.detect-changes.outputs.changes_detected}}" == "true" ]; then
104+ echo "pushing the code to ${{steps.identify_branch_name.outputs.branchName}}"
105+ git branch
106+ git push origin ${{steps.identify_branch_name.outputs.branchName}}
107+ else
108+ echo "branch is already up to date"
109+ fi
110+
111+ - name : Create PR
112+ run : |
113+ if [ "${{steps.detect-changes.outputs.changes_detected}}" == "true" ]; then
114+ echo "Creating PR in ${{steps.identify_branch_name.outputs.branchName}}"
115+ gh pr create \
116+ --title "OAS version update - ${{steps.get_latest_release_number.outputs.releaseVersion}}" \
117+ --base master \
118+ --head ${{steps.identify_branch_name.outputs.branchName}} \
119+ --body "chore: version update for all the yaml files"
120+ else
121+ echo "PR is already up to date"
122+ fi
123+ env :
124+ GH_TOKEN : ${{steps.get_access_token.outputs.result}}
0 commit comments