Skip to content

Commit 0c9141e

Browse files
authored
[Docs Site] Add workflow to update api-schemas pinned commit (#21416)
* [Docs Site] Add workflow to update api-schemas pinned commit * wording
1 parent 7ead684 commit 0c9141e

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Update api-schemas pinned commit
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * *"
6+
workflow_dispatch:
7+
8+
jobs:
9+
check-and-update:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
15+
steps:
16+
- name: Checkout docs repository
17+
uses: actions/checkout@v4
18+
19+
- name: Get latest api-schemas commit
20+
id: get-commit
21+
run: |
22+
LATEST_COMMIT=$(curl -s -H "Accept: application/vnd.github.v3+json" \
23+
https://api.github.com/repos/cloudflare/api-schemas/commits/main | \
24+
jq -r '.sha')
25+
echo "latest_commit=$LATEST_COMMIT" >> $GITHUB_OUTPUT
26+
27+
- name: Check current commit reference
28+
id: check-current
29+
run: |
30+
CURRENT_COMMIT=$(grep 'const COMMIT = ' src/util/api.ts | sed 's/.*"\(.*\)".*/\1/')
31+
echo "current_commit=$CURRENT_COMMIT" >> $GITHUB_OUTPUT
32+
33+
- name: Create PR if needed
34+
if: steps.get-commit.outputs.latest_commit != steps.check-current.outputs.current_commit
35+
run: |
36+
# Create a new branch
37+
git config --global user.name 'github-actions[bot]'
38+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
39+
BRANCH_NAME="update-api-schemas-$(date +%Y%m%d-%H%M%S)"
40+
git checkout -b $BRANCH_NAME
41+
42+
# Update the commit reference
43+
NEW_COMMIT="${{ steps.get-commit.outputs.latest_commit }}"
44+
sed -i "s/const COMMIT = \".*\"/const COMMIT = \"$NEW_COMMIT\"/" src/util/api.ts
45+
46+
# Commit and push changes
47+
git add src/util/api.ts
48+
git commit -m "[Docs Site] Update pinned api-schemas commit to $NEW_COMMIT"
49+
git push origin $BRANCH_NAME
50+
51+
# Create pull request
52+
gh pr create \
53+
--title "[Docs Site] Update pinned api-schemas commit" \
54+
--body "This PR updates the api-schemas commit reference to the latest version ($NEW_COMMIT)." \
55+
--base main \
56+
--head $BRANCH_NAME
57+
env:
58+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

src/util/api.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import SwaggerParser from "@apidevtools/swagger-parser";
22
import type { OpenAPI } from "openapi-types";
33

4+
const COMMIT = "f6c9d752f31f2e9dea3a9659fefab1b97b6042e9";
5+
46
let schema: OpenAPI.Document | undefined;
57

68
export const getSchema = async () => {
79
if (!schema) {
810
const response = await fetch(
9-
"https://gh-code.developers.cloudflare.com/cloudflare/api-schemas/f6c9d752f31f2e9dea3a9659fefab1b97b6042e9/openapi.json",
11+
`https://gh-code.developers.cloudflare.com/cloudflare/api-schemas/${COMMIT}/openapi.json`,
1012
);
1113
const obj = await response.json();
1214

0 commit comments

Comments
 (0)