Files
sure/.github/workflows/update-docs.yml
T

73 lines
2.6 KiB
YAML

name: Update Docs
on:
push:
branches:
- main
jobs:
update-docs:
if: github.repository == 'we-promise/sure'
permissions: {}
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
MINTLIFY_API_KEY: ${{ secrets.MINTLIFY_API_KEY }}
PROJECT_ID: ${{ secrets.MINTLIFY_PROJECT_ID }}
with:
script: |
const { owner, repo } = context.repo;
const projectId = process.env.PROJECT_ID;
const apiKey = process.env.MINTLIFY_API_KEY;
if (!projectId || !apiKey) {
core.setFailed('Missing MINTLIFY_PROJECT_ID or MINTLIFY_API_KEY secrets');
return;
}
const url = `https://api.mintlify.com/v2/agent/${projectId}/job`;
const prompt = [
'You are an action runner that updates documentation based on code changes. You should never ask questions. If you are not able to access the repository, report the error and exit.',
`Update the documentation for our recent pushes to main:\n\nRepository: ${owner}/${repo}`,
'Open a pull request when files are edited.'
].join('\n\n');
const payload = {
prompt
};
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
});
if (!response.ok) {
throw new Error(`API request failed with status ${response.status}: ${await response.text()}`);
}
const body = await response.text();
const job = JSON.parse(body);
if (!job.id) {
throw new Error(`API response did not include a job id: ${body}`);
}
if (job.status === 'failed') {
throw new Error(`Mintlify job ${job.id} failed immediately`);
}
console.log(`Mintlify documentation update job ${job.id} created with status: ${job.status}`);
if (job.prLink) {
console.log(`Mintlify pull request: ${job.prLink}`);
}
core.notice(`Documentation update job ${job.id} triggered for ${owner}/${repo}`);
} catch (error) {
core.setFailed(`Failed to create documentation update job: ${error.message}`);
}