Generate API #330
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Generate API | |
# TODO: eventually, we want this job to trigger based on perforce pushes | |
on: | |
schedule: | |
# this cron string runs at 00:00, only on Monday | |
- cron: 0 0 * * 1 | |
workflow_dispatch: | |
jobs: | |
generate: | |
timeout-minutes: 10 | |
runs-on: ubuntu-latest | |
concurrency: | |
group: generate-${{ github.head_ref }} | |
cancel-in-progress: true | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
persist-credentials: true | |
token: ${{ secrets.BOT_TOKEN }} | |
path: gen_api/ | |
- uses: actions/checkout@v4 | |
with: | |
repository: beamable/BeamableProduct | |
fetch-depth: 0 | |
path: BeamableProduct/ | |
- name: Setup .NET Core SDK | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: 8.0.x | |
- name: Cache | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/.cargo/bin/ | |
~/.cargo/registry/index/ | |
~/.cargo/registry/cache/ | |
~/.cargo/git/db/ | |
gen_api/target/ | |
key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.toml') }} | |
- name: Install stable toolchain | |
uses: dtolnay/rust-toolchain@stable | |
- name: Build CLI | |
run: | | |
dotnet build ./BeamableProduct/cli/cli | |
- name: Generate API | |
working-directory: gen_api | |
run: | | |
dotnet run --project ../BeamableProduct/cli/cli -- oapi download --output . --combine-into-one-document | |
- name: Update OpenAPI from script | |
working-directory: gen_api | |
run: bash updateOpenApi.sh | |
- name: Generate code | |
working-directory: gen_api | |
run: docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate -i /local/combinedOpenApi.json -g rust -c /local/package_oapi_config.json -o /local/ | |
- name: Test build | |
working-directory: gen_api | |
run: cargo build | |
- name: Check for Changes | |
working-directory: gen_api | |
run: | | |
lines=$(git status --porcelain | grep -v 'README.md' | wc -l) | |
if [ "$lines" -eq 0 ]; then | |
echo "::set-output name=any::false" | |
else | |
echo "::set-output name=any::true" | |
fi | |
id: changes | |
- name: Create Pull Request | |
working-directory: gen_api | |
if: ${{ steps.changes.outputs.any == 'true' }} | |
env: | |
GH_TOKEN: ${{ secrets.BOT_TOKEN }} | |
run: | | |
git config user.email "[email protected]" | |
git config user.name "Piotr" | |
branch="update-openapi-$(date +%s)" | |
git checkout -b $branch | |
git add . | |
git commit -m "syncing sdk from openapi" | |
git push origin $branch | |
gh pr create --title "Auto generate SDK from openAPI" --body "The CLI autogenerated these changes to the SDK" --head $branch --base main |