Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate the process of updating zkEVM repo when it's corresponding openapi changes (#3497) #163

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions .github/workflows/update-zkevm-api-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
name: Update zkEVM API Package

on:
workflow_dispatch:
schedule:
- cron: '0 10 * * *'

env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
update-api:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3

- name: Pull files from Git LFS
run: git lfs pull

- name: Get current date and time
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d-%H-%M-%S')"

- name: Download remote openapi.json
run: curl -o openapi_remote.json https://imx-openapiv3-mr-sandbox.s3.us-east-2.amazonaws.com/openapi.json

- name: Ensure local openapi.json exists (if not, assume it's blank)
run: |
if [ ! -f ./Source/ImmutablezkEVMAPI/openapi-generator/openapi.json ]; then
echo "Creating empty openapi.json file..."
mkdir -p ./Source/ImmutablezkEVMAPI/openapi-generator/
touch ./Source/ImmutablezkEVMAPI/openapi-generator/openapi.json
fi

- name: Compare remote openapi.json with local openapi.json
id: comparison
run: |
if diff openapi_remote.json ./Source/ImmutablezkEVMAPI/openapi-generator/openapi.json > /dev/null; then
echo "::set-output name=difference::false"
else
echo "::set-output name=difference::true"
fi

- name: NPM install OpenAPI Generator CLI globally
run: npm install -g @openapitools/openapi-generator-cli

- name: Set execute permission on generate.sh
run: chmod +x ./Source/ImmutablezkEVMAPI/openapi-generator/batch-files/generate.sh

- name: Convert line endings of generate.sh to Unix format
run: sed -i -e 's/\r$//' ./Source/ImmutablezkEVMAPI/openapi-generator/batch-files/generate.sh

- name: Generate API if there are differences
if: steps.comparison.outputs.difference == 'true'
run: |
cd ./Source/ImmutablezkEVMAPI/openapi-generator/batch-files
./generate.sh
cd ../../../../

- name: Clean up
if: steps.comparison.outputs.difference == 'true'
run: |
rm openapi_remote.json

- name: Create a new branch
if: steps.comparison.outputs.difference == 'true'
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Action"
git checkout -b feat/update-zkevm-api-${{ steps.date.outputs.date }}

- name: Commit changes
id: commit_changes
if: steps.comparison.outputs.difference == 'true'
run: |
git add ./Source/ImmutablezkEVMAPI/
if [ -n "$(git diff --cached)" ]; then
git commit -m "feat: update immutable zkEVM API package"
echo "commit=true" >> $GITHUB_ENV
else
echo "No changes to commit."
echo "commit=false" >> $GITHUB_ENV
fi

- name: Push changes
if: env.commit == 'true'
run: |
git push origin feat/update-zkevm-api-${{ steps.date.outputs.date }}

- name: Create pull request
if: env.commit == 'true'
run: |
gh pr create --title "feat: update immutable zkEVM API package" \
--body "Update Immutable zkEVM API package" \
--base main \
--head feat/update-zkevm-api-${{ steps.date.outputs.date }}
Loading