Generate Code Samples #102
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: Generate Code Samples | |
| on: | |
| workflow_dispatch: | |
| # Run every 4 hours to check if all client releases are ready | |
| schedule: | |
| - cron: '0 */4 * * *' | |
| permissions: | |
| contents: write | |
| jobs: | |
| check-and-generate-samples: | |
| runs-on: macos-latest | |
| steps: | |
| - name: Generate App Token | |
| id: app-token | |
| uses: actions/create-github-app-token@v2 | |
| with: | |
| app-id: ${{ secrets.APP_ID }} | |
| private-key: ${{ secrets.APP_PRIVATE_KEY }} | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ steps.app-token.outputs.token }} | |
| - name: Set up mise | |
| uses: jdx/mise-action@v2 | |
| with: | |
| cache: true | |
| env: | |
| GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Check if all client releases have matching SHAs | |
| id: check | |
| run: | | |
| if pnpm run check-client-releases; then | |
| echo "clients_ready=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "clients_ready=false" >> $GITHUB_OUTPUT | |
| fi | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| - name: Generate client code samples | |
| if: github.event_name == 'workflow_dispatch' || steps.check.outputs.clients_ready == 'true' | |
| run: speakeasy run -s glean-client-merged-code-samples-spec | |
| env: | |
| SPEAKEASY_API_KEY: ${{ secrets.SPEAKEASY_API_KEY }} | |
| - name: Generate indexing code samples | |
| if: github.event_name == 'workflow_dispatch' || steps.check.outputs.clients_ready == 'true' | |
| run: speakeasy run -s glean-index-merged-code-samples-spec | |
| env: | |
| SPEAKEASY_API_KEY: ${{ secrets.SPEAKEASY_API_KEY }} | |
| - name: Running code sample transformers | |
| if: github.event_name == 'workflow_dispatch' || steps.check.outputs.clients_ready == 'true' | |
| run: pnpm transform:merged_code_samples_specs | |
| - name: Copy specs into final_specs | |
| if: github.event_name == 'workflow_dispatch' || steps.check.outputs.clients_ready == 'true' | |
| run: | | |
| cp -r ./modified_code_samples_specs/client_rest.yaml ./final_specs/client_rest.yaml | |
| cp -r ./modified_code_samples_specs/indexing.yaml ./final_specs/indexing.yaml | |
| - name: Commit changes | |
| if: github.event_name == 'workflow_dispatch' || steps.check.outputs.clients_ready == 'true' | |
| uses: ./.github/actions/git-commit | |
| with: | |
| commit_message: 'Update code samples' | |
| file_patterns: 'merged_code_samples_specs/* modified_code_samples_specs/* final_specs/* .speakeasy/*' | |
| github_token: ${{ steps.app-token.outputs.token }} |