-
Notifications
You must be signed in to change notification settings - Fork 2
172 lines (153 loc) · 6.27 KB
/
generate.yml
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
name: Generate
on:
push:
branches:
- main
jobs:
generate_job:
name: generate SDK and push to repositories
runs-on: ubuntu-latest
container:
image: ubuntu:22.04
strategy:
matrix:
types: [ "go", "php", "csharp", "typescript-node", "java", "rust", "python", "javascript" ]
steps:
- name: Setup Env
run: apt-get update && apt-get install -y npm curl git
shell: bash
- name: install gh cli
run: |
type -p curl >/dev/null || (apt update && apt install curl -y)
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& apt update \
&& apt install gh -y
shell: bash
- name: Git config
run: git config --global --add safe.directory /__w/azionapi-openapi/azionapi-openapi
shell: bash
- uses: actions/setup-node@v3
with:
node-version: 18
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
- name: install openapi-generator
run: npm install @openapitools/openapi-generator-cli -g
shell: bash
- name: Setting GIT
run: git config --global url."https://${{ secrets.GLOBAL_TOKEN }}:[email protected]/aziontech".insteadOf "https://github.com/aziontech"
shell: bash
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Checkout SDK repo
uses: actions/checkout@v3
with:
fetch-depth: 0
repository: aziontech/azionapi-${{ matrix.types }}-sdk
path: ${{ matrix.types }}
token: ${{ secrets.REPO_ACCESS_TOKEN }}
#get all .yaml files which were added/modified
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v35
with:
files: |
**/*.yaml
ignore: |
**/*spectral*.yaml
- name: Run openapi-generator for changed files
run: |
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
removed=$(echo ${file} | cut -d. -f1);
npx @openapitools/openapi-generator-cli generate -i $file -g ${{ matrix.types }} -o ./${{ matrix.types }}/${removed} --package-name ${removed};\
echo 'go.mod' >> ./${{ matrix.types }}/${removed}/.gitignore
echo 'go.sum' >> ./${{ matrix.types }}/${removed}/.gitignore
done
- name: push changes
run: |
cd ${{ matrix.types }}
git config user.email "[email protected]"
git config user.name "PatrickMenoti"
git checkout -b generated-sdk
git add .
if git diff-index --quiet HEAD --; then
echo "::warning::No changes to commit for ${{ matrix.types }}. Skipping opening a PR for it."
else
git commit -m "Auto-Generated SDK"
git push origin generated-sdk
gh pr create --body "Auto-generated SDK" --title "Auto-generated SDK"
fi
env:
GH_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
update_merged_yaml:
name: update merged yaml file
runs-on: ubuntu-latest
container:
image: python:3.9-alpine3.18
steps:
- name: install gh cli
run: |
apk add github-cli git
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: merge files
env:
TOKEN_REPO_INTEGRATION: ${{ secrets.TOKEN_REPO_INTEGRATION }}
TARGET_REPO: ${{ secrets.MERGER_REPO }}
run: |
OLD_PWD=`pwd`
TEMP_DIR=`mktemp -d`
cd $TEMP_DIR
git clone https://$TOKEN_REPO_INTEGRATION:[email protected]/aziontech/$TARGET_REPO.git .
cd openapi
pip install -r ./requirements.txt
python processor.py $OLD_PWD/edgefunctions.yaml $OLD_PWD/idns.yaml
cp ./output/merged.yaml $OLD_PWD/openapi.yaml
cd $OLD_PWD
- name: create update PR
id: create-pull-request
env:
TOKEN_REPO_INTEGRATION: ${{ secrets.TOKEN_REPO_INTEGRATION }}
GH_TOKEN: ${{ secrets.TOKEN_REPO_INTEGRATION }}
TARGET_REPO: ${{ secrets.OPEN_API_MERGED_YAML_REPO}}
TARGET_MERGED_YAML_PATH: ${{ secrets.OPEN_API_MERGED_YAML_PATH }}
run: |
OLD_PWD=`pwd`
TEMP_DIR=`mktemp -d`
MERGED_YAML="$OLD_PWD/openapi.yaml"
cd $TEMP_DIR
git clone https://$TOKEN_REPO_INTEGRATION:[email protected]/aziontech/$TARGET_REPO.git .
git checkout -b auto-update-openapi-merged-yaml
cp -f $MERGED_YAML $TARGET_MERGED_YAML_PATH
if [ -z "`git diff`" ]; then
echo "merged file was not changed"
exit 0
fi
git config user.name "Azion Github Automation"
git config user.email "[email protected]"
git add $TARGET_MERGED_YAML_PATH
git commit -m 'chore: ChatGPT pluggin - update merged OpenAPI yaml file'
git push --force origin auto-update-openapi-merged-yaml
PR_BRANCH="auto-update-openapi-merged-yaml"
PR_TITLE="ChatGPT pluggin - update merged OpenAPI yaml file"
PR_BODY="ChatGPT pluggin - update merged OpenAPI yaml file"
PR_LINK=`gh pr create --body "$PR_BODY" --title "chore: ChatGPT pluggin - update merged OpenAPI yaml file" || echo "Cannot create PR. Possibly PR already exists"`
echo "::add-mask::$PR_LINK"
echo "pr-link=$PR_LINK" >> "$GITHUB_OUTPUT"
- name: notify merged yaml update
if: false
# if: ${{ steps.create-pull-request.outputs.pr-link }} - TODO: add secret for slack_webhook
id: slack
uses: slackapi/[email protected]
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
with:
payload: "${{ steps.create-pull-request.outputs.pr-link }}"