-
Notifications
You must be signed in to change notification settings - Fork 156
107 lines (91 loc) · 3.99 KB
/
create-github-pr.yml
File metadata and controls
107 lines (91 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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 }}