Skip to content

Chore/origin field weight (#216) #223

Chore/origin field weight (#216)

Chore/origin field weight (#216) #223

Workflow file for this run

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 https://api.azion.com/v3 $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 }}"