TypeScript client generation #100
This file contains hidden or 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: TypeScript client generation | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| openapi_short_sha: | |
| description: "The short commit sha that triggered the workflow" | |
| required: true | |
| type: string | |
| env: | |
| NEW_BRANCH: openapi-${{ github.event.inputs.openapi_short_sha }}/clientgen | |
| jobs: | |
| Generate-TypeScript-Client: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set secure environment variables | |
| run: | | |
| echo "OPENAPI_SHA=${{ github.event.inputs.openapi_short_sha }}" >> $GITHUB_ENV | |
| echo "NEW_BRANCH=openapi-${{ github.event.inputs.openapi_short_sha }}/clientgen" >> $GITHUB_ENV | |
| - name: Make openapi_changelist.sh executable | |
| run: chmod +x scripts/openapi_changelist.sh | |
| - name: OpenAPI Changelist | |
| env: | |
| GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }} | |
| TARGET_SHA: ${{ github.event.inputs.openapi_short_sha }} | |
| run: | | |
| current_sha=$(cat DO_OPENAPI_COMMIT_SHA.txt) | |
| echo "current_sha=$current_sha" >> $GITHUB_ENV | |
| target_sha=${TARGET_SHA} | |
| scripts/openapi_changelist.sh $current_sha $target_sha > changelist.md | |
| - name: Removes all generated code | |
| run: make clean | |
| - name: Removes generated documentation | |
| run: make docs_clean | |
| - name: Download spec file and update DO_OPENAPI_COMMIT_SHA.txt | |
| env: | |
| GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }} | |
| TARGET_SHA: ${{ github.event.inputs.openapi_short_sha }} | |
| run: | | |
| curl --fail "https://api-engineering.nyc3.digitaloceanspaces.com/spec-ci/DigitalOcean-public-${TARGET_SHA}.v2.yaml" -o DigitalOcean-public.v2.yaml | |
| echo "$TARGET_SHA" > DO_OPENAPI_COMMIT_SHA.txt | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: DigitalOcean-public.v2 | |
| path: ./DigitalOcean-public.v2.yaml | |
| - name: Checkout new Branch | |
| run: git checkout -b ${{ env.NEW_BRANCH }} | |
| env: | |
| GH_TOKEN: ${{secrets.WORKFLOW_TOKEN}} | |
| - name: Install Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: 18 | |
| - name: Install Dependencies | |
| run: npm install | |
| - uses: microsoft/setup-kiota@v0.5.0 | |
| - name: Check Kiota version | |
| run: kiota --version | |
| - name: Generate TypeScript client | |
| run: make generate | |
| - name: Generate TypeScript client documentation | |
| run: make generate-docs | |
| - name: Add and commit changes | |
| id: add-commit-changes | |
| continue-on-error: true | |
| run: | | |
| git config --global user.email "api-engineering@digitalocean.com" | |
| git config --global user.name "API Engineering" | |
| git add . | |
| git commit -m "[bot] Updated client based on ${{ env.NEW_BRANCH }}" | |
| git push --set-upstream origin ${{ env.NEW_BRANCH }} | |
| env: | |
| GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }} | |
| - name: Check if branch existed | |
| # If steps.create-pr was anything but successful, it's possible that | |
| # the branch was created in previous pipeline runs so it should be manually deleted. | |
| if: steps.add-commit-changes.outcome != 'success' | |
| run: | | |
| echo "Add and commit changes step failed. It's possible the branch ${{ env.NEW_BRANCH }} already existed. Please delete the branch and re-run the pipeline." | |
| exit 1 | |
| - name: Set pr_title outputs | |
| id: pr_title_var | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| SEARCH_SHA: ${{ github.event.inputs.openapi_short_sha }} | |
| run: | | |
| PR_TITLE=$(gh pr list --search "$SEARCH_SHA" --json title --jq '.[0].title' --repo digitalocean/openapi --state merged) | |
| echo "PR_TITLE=$PR_TITLE" >> $GITHUB_OUTPUT | |
| - name: Check pr_title outputs | |
| run: echo "${{ steps.pr_title_var.outputs.PR_TITLE }}" | |
| - name: Create Pull Request | |
| id: create-pr | |
| if: steps.add-commit-changes.outcome == 'success' | |
| env: | |
| GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }} | |
| TITLE: ${{ steps.pr_title_var.outputs.PR_TITLE }} | |
| run: | | |
| export CURRENT="$(cat DO_OPENAPI_COMMIT_SHA.txt)" | |
| export TARGET="$OPENAPI_SHA" | |
| export TITLE="$TITLE" | |
| envsubst < scripts/pr_body.md_tmpl > pr_body.md | |
| cat changelist.md >> pr_body.md | |
| echo "PR BODY:" | |
| cat pr_body.md | |
| gh pr create \ | |
| --title "[bot] $TITLE: Re-Generated From digitalocean/openapi@$TARGET" \ | |
| --body-file pr_body.md \ | |
| --head "$NEW_BRANCH" \ | |
| -r digitalocean/api-cli |