-
Notifications
You must be signed in to change notification settings - Fork 8
134 lines (115 loc) · 4.93 KB
/
update-zkevm-api-package.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
---
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.json https://imx-openapiv3-mr-sandbox.s3.us-east-2.amazonaws.com/openapi.json
- name: Ensure local openapi.yaml exists (if not, assume it's blank)
run: |
if [ ! -f ./src/Packages/ZkEvmApi/api~/openapi.yaml ]; then
echo "Creating empty openapi.yaml file..."
mkdir -p ./src/Packages/ZkEvmApi/api~
touch ./src/Packages/ZkEvmApi/api~/openapi.yaml
fi
- name: Compare openapi.json with openapi.yaml
id: comparison
run: |
if diff openapi.json ./src/Packages/ZkEvmApi/api~/openapi.yaml > /dev/null; then
echo "::set-output name=difference::false"
else
echo "::set-output name=difference::true"
fi
- name: Generate API if there are differences
if: steps.comparison.outputs.difference == 'true'
run: |
wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.8.0/openapi-generator-cli-7.8.0.jar -O openapi-generator-cli.jar
java -jar openapi-generator-cli.jar generate -i openapi.json -g csharp \
--library unityWebRequest -o ./ZkEvmApi \
--skip-validate-spec \
--additional-properties=apiName=ImmutableZkEvmApi,packageName=Immutable.Api.ZkEvm
- name: Copy generated files
if: steps.comparison.outputs.difference == 'true'
run: |
mkdir -p ./src/Packages/ZkEvmApi/api~
mkdir -p ./src/Packages/ZkEvmApi/Documentation~
mkdir -p ./src/Packages/ZkEvmApi/Runtime
# Clear contents while preserving .meta files
find ./src/Packages/ZkEvmApi/api~ -type f ! -name '*.meta' -exec rm {} +
find ./src/Packages/ZkEvmApi/Documentation~ -type f ! -name '*.meta' -exec rm {} +
find ./src/Packages/ZkEvmApi/Runtime -type f ! -name '*.meta' -exec rm {} +
cp -r ./ZkEvmApi/api/* ./src/Packages/ZkEvmApi/api~/
cp -r ./ZkEvmApi/docs/* ./src/Packages/ZkEvmApi/Documentation~/
cp -r ./ZkEvmApi/src/Immutable.Api.ZkEvm/* ./src/Packages/ZkEvmApi/Runtime/
# Remove .meta files that do not have corresponding files
for dir in ./src/Packages/ZkEvmApi/Runtime; do
for meta_file in "$dir"/*.meta; do
# Check if the corresponding file exists
base_file="${meta_file%.meta}"
if [ ! -e "$base_file" ]; then
echo "Deleting unmatched meta file: $meta_file"
rm "$meta_file"
fi
done
done
- name: Clean up
if: steps.comparison.outputs.difference == 'true'
run: |
rm -rf ./ZkEvmApi
rm openapi-generator-cli.jar
rm openapi.json
- name: Open sample app in Unity to generate .meta files
if: steps.comparison.outputs.difference == 'true'
uses: game-ci/unity-test-runner@v4
env:
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
with:
unityVersion: 2021.3.26f1
projectPath: './sample'
githubToken: ${{ secrets.GITHUB_TOKEN }}
testMode: 'EditMode'
- 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 ./src/Packages/ZkEvmApi/
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 }}