-
Notifications
You must be signed in to change notification settings - Fork 32
103 lines (96 loc) · 3.66 KB
/
Copy pathsdk_generation.yaml
File metadata and controls
103 lines (96 loc) · 3.66 KB
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
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 }}