-
Notifications
You must be signed in to change notification settings - Fork 77
69 lines (61 loc) · 2.38 KB
/
update-openapi.yml
File metadata and controls
69 lines (61 loc) · 2.38 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
name: Update OpenAPI Specification
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *"
jobs:
update-openapi:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Update OpenAPI Spec
id: sync-openapi
uses: fern-api/sync-openapi@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: 'update-openapi-spec'
update_from_source: true
add_timestamp: true
- name: Auto-approve and enable auto-merge
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
APPROVE_TOKEN: ${{ secrets.AUTO_APPROVE_PAT }}
run: |
set -euo pipefail
# Retry loop to find the PR (handles timing issues)
PR_NUMBER=""
for i in {1..10}; do
echo "Attempt $i: Looking for PR..."
PR_JSON=$(gh pr list --state open --json number,headRefName,createdAt,author,baseRefName \
| jq 'map(select(.headRefName | startswith("update-openapi-spec-") and .baseRefName=="main" and .author.login=="github-actions[bot]"))
| sort_by(.createdAt) | last')
PR_NUMBER=$(echo "$PR_JSON" | jq -r '.number // empty')
if [ -n "$PR_NUMBER" ]; then
echo "Found PR #$PR_NUMBER"
break
fi
echo "PR not found yet, waiting 3 seconds..."
sleep 3
done
if [ -z "$PR_NUMBER" ]; then
echo "No matching PR found after retries"
echo "Open PRs:"
gh pr list --state open --json number,headRefName,author
exit 0
fi
# Auto-approve the PR using the PAT
if [ -n "${APPROVE_TOKEN:-}" ]; then
echo "Auto-approving PR #$PR_NUMBER..."
GH_TOKEN="$APPROVE_TOKEN" gh pr review "$PR_NUMBER" --approve --body "Auto-approved by workflow"
else
echo "Warning: AUTO_APPROVE_PAT secret not set. PR will require manual approval."
fi
# Enable auto-merge
echo "Enabling auto-merge for PR #$PR_NUMBER..."
gh pr merge "$PR_NUMBER" --auto --squash
echo "Auto-merge enabled. PR will merge automatically once all checks pass."