Skip to content

Commit cf7d09c

Browse files
committed
[misc] release API release correction
1 parent 723b1be commit cf7d09c

File tree

1 file changed

+88
-17
lines changed

1 file changed

+88
-17
lines changed

.github/workflows/release.yml

Lines changed: 88 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,55 @@ jobs:
4848
run: |
4949
sphinx-build -b markdown docs/source docs/_build/markdown
5050
51-
- name: Checkout documentation repository
51+
- name: Ensure fork exists and is up to date
52+
uses: actions/github-script@v7
53+
with:
54+
github-token: ${{ secrets.SPHINX_TOKEN }}
55+
script: |
56+
const owner = 'rusher';
57+
const repo = 'mariadb-docs';
58+
const upstream = 'mariadb-corporation';
59+
const upstreamRepo = 'mariadb-docs';
60+
// Check if fork exists
61+
let forkExists = false;
62+
try {
63+
await github.rest.repos.get({ owner, repo });
64+
forkExists = true;
65+
} catch (e) {
66+
forkExists = false;
67+
}
68+
// Create fork if not exists
69+
if (!forkExists) {
70+
await github.rest.repos.createFork({ owner: upstream, repo: upstreamRepo });
71+
// Wait for fork to be ready
72+
let ready = false;
73+
for (let i = 0; i < 10; i++) {
74+
try {
75+
await github.rest.repos.get({ owner, repo });
76+
ready = true;
77+
break;
78+
} catch (e) {
79+
await new Promise(res => setTimeout(res, 5000));
80+
}
81+
}
82+
if (!ready) throw new Error('Fork not ready after waiting.');
83+
}
84+
85+
- name: Checkout documentation repository (fork)
5286
uses: actions/checkout@v4
5387
with:
54-
repository: mariadb-corporation/mariadb-docs # Replace with actual repo
88+
repository: rusher/mariadb-docs
5589
token: ${{ secrets.SPHINX_TOKEN }}
5690
path: mariadb-docs
91+
ref: main
92+
93+
- name: Add upstream and fetch latest main
94+
run: |
95+
cd mariadb-docs
96+
git remote add upstream https://github.com/mariadb-corporation/mariadb-docs.git || true
97+
git fetch upstream
98+
git checkout main
99+
git pull upstream main
57100
58101
- name: Update documentation subdirectory
59102
run: |
@@ -67,19 +110,47 @@ jobs:
67110
# Optional: Add any additional processing here
68111
# e.g., update index files, fix relative links, etc.
69112
70-
- name: Create Pull Request
71-
uses: peter-evans/create-pull-request@v5
113+
- name: Commit and push changes to fork
114+
run: |
115+
cd mariadb-docs
116+
git config user.name "github-actions[bot]"
117+
git config user.email "github-actions[bot]@users.noreply.github.com"
118+
git checkout -b auto-docs-update-${{ github.run_number }}
119+
git add connectors/mariadb-connector-python/api/
120+
git commit -m "Update API documentation from ${{ github.repository }}"
121+
git push https://x-access-token:${{ secrets.SPHINX_TOKEN }}@github.com/rusher/mariadb-docs.git auto-docs-update-${{ github.run_number }}
122+
123+
- name: Create Pull Request to Upstream
124+
uses: actions/github-script@v7
72125
with:
73-
token: ${{ secrets.SPHINX_TOKEN }}
74-
path: mariadb-docs
75-
commit-message: "Update API documentation from ${{ github.repository }}"
76-
title: "Auto-update: API Documentation from ${{ github.repository }}"
77-
body: |
78-
This PR automatically updates the documentation subdirectory with the latest Sphinx-generated markdown from [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}).
79-
80-
**Changes:**
81-
- Updated documentation generated from commit ${{ github.sha }}
82-
- Generated on: ${{ github.run_id }}
83-
84-
branch: auto-docs-update-${{ github.run_number }}
85-
delete-branch: true
126+
github-token: ${{ secrets.SPHINX_TOKEN }}
127+
script: |
128+
const branch = `auto-docs-update-${{ github.run_number }}`;
129+
const prTitle = "Auto-update: API Documentation from ${{ github.repository }}";
130+
const prBody = `This PR automatically updates the documentation subdirectory with the latest Sphinx-generated markdown from [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}).\n**Changes:**\n- Updated documentation generated from commit ${{ github.sha }}\n- Generated on: ${{ github.run_id }}`;
131+
try {
132+
// Check if a PR already exists for this branch
133+
const { data: pulls } = await github.rest.pulls.list({
134+
owner: 'mariadb-corporation',
135+
repo: 'mariadb-docs',
136+
head: `rusher:${branch}`,
137+
base: 'main',
138+
state: 'open',
139+
});
140+
if (pulls.length === 0) {
141+
const pr = await github.rest.pulls.create({
142+
owner: 'mariadb-corporation',
143+
repo: 'mariadb-docs',
144+
title: prTitle,
145+
head: `rusher:${branch}`,
146+
base: 'main',
147+
body: prBody,
148+
maintainer_can_modify: false
149+
});
150+
console.log('PR created: ', pr.data.html_url);
151+
} else {
152+
console.log('PR already exists: ', pulls[0].html_url);
153+
}
154+
} catch (error) {
155+
core.setFailed(`Failed to create PR: ${error.message}`);
156+
}

0 commit comments

Comments
 (0)