OAS version update - 6.3.0 #88
Workflow file for this run
This file contains 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
name: Update YAML version and raise PR | |
on: | |
release: | |
types: [published] | |
pull_request: | |
paths: | |
- '**' | |
jobs: | |
Update-yaml-version: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
with: | |
ref: 'PETOSS-588-auto-PR-logic' | |
- name: whats inside github workspace | |
run: | | |
ls -la | |
working-directory: ${{ github.workspace }} | |
- name: whats inside .github folder | |
run: | | |
ls -la | |
working-directory: ${{ github.workspace }}/.github | |
- name: Install octokit dependencies | |
run: npm i | |
working-directory: ${{ github.workspace }}/.github/octokit | |
- name: Get github app access token | |
id: get_access_token | |
env: | |
GITHUB_APP_ID: ${{ secrets.XERO_PUBLIC_BOT_APP_ID }} | |
GITHUB_APP_PRIVATE_KEY: ${{ secrets.XERO_PUBLIC_BOT_KEY }} | |
uses: actions/github-script@v7 | |
with: | |
result-encoding: string | |
script: | | |
const { getAccessToken } = await import('${{ github.workspace }}/.github/octokit/index.js') | |
const token = await getAccessToken() | |
return token | |
- 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: ${{steps.get_access_token.outputs.result}} | |
- 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 version of the 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 = \"10.1.0\"" -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 test-auto-merge \ | |
--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: ${{steps.get_access_token.outputs.result}} | |
- name: Auto Merge PR & deletes branch | |
run: | | |
BRANCH_NAME=${{steps.identify_branch_name.outputs.branchName}} | |
PR_NUMBER=$(gh pr list --head "$BRANCH_NAME" --json number --jq '. [0].number') | |
if [ -z "$PR_NUMBER" ]; then | |
echo "No PR found for branch: $BRANCH_NAME" | |
exit 1 | |
fi | |
echo "Merging the PR: $PR_NUMBER...." | |
gh pr merge $PR_NUMBER --merge --delete-branch --repo ${{github.repository}} | |
echo "PR #$PR_NUMBER has been merged & branch: $BRANCH_NAME has been deleted" | |
env: | |
GH_TOKEN: ${{steps.get_access_token.outputs.result}} | |