Generate #330
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 | |
| permissions: | |
| checks: write | |
| contents: write | |
| pull-requests: write | |
| statuses: write | |
| id-token: write | |
| "on": | |
| workflow_dispatch: | |
| inputs: | |
| force: | |
| description: Force generation of SDKs | |
| type: boolean | |
| default: false | |
| set_version: | |
| description: optionally set a specific SDK version | |
| type: string | |
| schedule: | |
| - cron: 0 0 * * * | |
| pull_request: | |
| types: | |
| - labeled | |
| - unlabeled | |
| concurrency: | |
| group: speakeasy-generate | |
| cancel-in-progress: false | |
| jobs: | |
| generate: | |
| uses: speakeasy-api/sdk-generation-action/.github/workflows/workflow-executor.yaml@v15 | |
| with: | |
| force: ${{ github.event.inputs.force }} | |
| mode: pr | |
| set_version: ${{ github.event.inputs.set_version }} | |
| secrets: | |
| github_access_token: ${{ secrets.GITHUB_TOKEN }} | |
| pypi_token: ${{ secrets.PYPI_TOKEN }} | |
| speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }} | |
| resolve-branch: | |
| needs: generate | |
| if: ${{ !cancelled() && needs.generate.result == 'success' }} | |
| runs-on: ubuntu-latest | |
| outputs: | |
| branch_name: ${{ steps.branch.outputs.branch_name }} | |
| run_started_at: ${{ steps.branch.outputs.run_started_at }} | |
| steps: | |
| - name: Extract branch from Generate logs | |
| id: branch | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| set -euo pipefail | |
| REPO="${{ github.repository }}" | |
| RUN_ID="${{ github.run_id }}" | |
| RUN_STARTED="${{ github.run_started_at }}" | |
| if [ -z "$RUN_STARTED" ]; then | |
| RUN_STARTED=$(gh run view "$RUN_ID" --repo "$REPO" --json startedAt --jq '.startedAt') | |
| echo "Resolved run_started_at from API: $RUN_STARTED" | |
| fi | |
| echo "run_started_at=$RUN_STARTED" >> "$GITHUB_OUTPUT" | |
| # Full-run logs are unavailable while the workflow is in progress; | |
| # fetch logs from the completed generate job instead. | |
| JOB_ID=$(gh run view "$RUN_ID" --repo "$REPO" --json jobs --jq \ | |
| '[.jobs[] | select(.name == "generate / Generate Target")] | .[0].databaseId // empty') | |
| BRANCH="" | |
| if [ -z "$JOB_ID" ]; then | |
| echo "::warning::Could not find generate job id — auto-merge will use run_started_at fallback" | |
| else | |
| MAX_ATTEMPTS=12 | |
| INTERVAL=10 | |
| for attempt in $(seq 1 "$MAX_ATTEMPTS"); do | |
| BRANCH=$(gh run view "$RUN_ID" --repo "$REPO" --job "$JOB_ID" --log 2>/dev/null \ | |
| | grep -oE 'branch_name=speakeasy-sdk-regen-[0-9]+' | tail -1 | cut -d= -f2 || true) | |
| if [ -n "$BRANCH" ]; then | |
| echo "Extracted branch_name=$BRANCH (attempt $attempt)" | |
| break | |
| fi | |
| if [ "$attempt" -lt "$MAX_ATTEMPTS" ]; then | |
| echo "Job logs not ready — waiting ${INTERVAL}s (attempt $attempt/$MAX_ATTEMPTS)..." | |
| sleep "$INTERVAL" | |
| fi | |
| done | |
| if [ -z "$BRANCH" ]; then | |
| echo "::warning::Could not extract branch_name from Generate logs after ${MAX_ATTEMPTS} attempts — auto-merge will use run_started_at fallback" | |
| fi | |
| fi | |
| echo "branch_name=$BRANCH" >> "$GITHUB_OUTPUT" | |
| auto-merge: | |
| needs: [generate, resolve-branch] | |
| if: ${{ !cancelled() && needs.generate.result == 'success' }} | |
| uses: ./.github/workflows/auto-merge-speakeasy-pr.yaml | |
| with: | |
| run_started_at: ${{ needs.resolve-branch.outputs.run_started_at }} | |
| branch_name: ${{ needs.resolve-branch.outputs.branch_name }} | |
| secrets: | |
| GH_DOCS_SYNC_APP_ID: ${{ secrets.GH_DOCS_SYNC_APP_ID }} | |
| GH_DOCS_SYNC_APP_PRIVATE_KEY: ${{ secrets.GH_DOCS_SYNC_APP_PRIVATE_KEY }} |