Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 198 additions & 0 deletions .github/scripts/quickstart_py/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .github/scripts/quickstart_py/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "update_quickstart_py",
"version": "1.0.0",
"description": "Scrapes readme's hopefully",
"main": "update_quickstart_py.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"run": "node update_quickstart_py.js"
},
"author": "Memphis",
"license": "ISC",
"type": "module",
"dependencies": {
"@octokit/request": "^8.1.1",
"@octokit/rest": "^20.0.1"
}
}
85 changes: 85 additions & 0 deletions .github/scripts/quickstart_py/update_quickstart_py.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
const git_token = process.env.DOCS_ACTION_TOKEN

import { Octokit } from "@octokit/rest";

const octokit = new Octokit({
auth: git_token
})

const repos = [
{
repo_name: 'memphis.py',
doc_path: 'docs/sdk/client-libraries/python/quick-start.md',
language_name: 'Python'
}
]

let did_error = false;
const failed_languages = [];
for (let repo of repos){
try {
await update_file(repo.repo_name, repo.doc_path, repo.language_name)
} catch (error) {
console.log();(error);
did_error = true;
failed_languages.push(repo.language_name)
}
}

if (did_error){
throw new Error(`Failed to update one or more languages. \n Failed Languages: ${failed_languages.join(', ')}`)
}

async function update_file(repo_name, doc_path, language_name){
console.log(`Updating ${language_name} Quickstart`);
console.log(`Repo: ${repo_name}`);

console.log(`Getting ${language_name} README`);
let req = await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
owner: 'memphisdev',
repo: repo_name,
path: 'README.md',
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
})

console.log(`Getting ${language_name} Quickstart SHA`);
let quick_start = await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
owner: 'memphisdev',
repo: 'documentation',
path: doc_path,
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
})

const quick_start_sha = quick_start.data.sha;

console.log(`Quickstart SHA: ${quick_start_sha}`);

const readme_content = atob(req.data.content)
const readme_h3_to_h2 = readme_content.replace(/###/g, '##')
const commit_string = `---
title: ${language_name} Quickstart
description: A quickstart on how to use the ${language_name} client library
---`+ '\n' + readme_h3_to_h2

console.log(`Updating ${language_name} Quickstart`);
await octokit.request('PUT /repos/{owner}/{repo}/contents/{path}', {
owner: 'memphisdev',
repo: 'documentation',
path: doc_path,
message: `Updating ${language_name} SDK Quick-Start`,
committer: {
name: 'Automated Workflow',
email: 'john@memphis.dev'
},
content: btoa(commit_string),
headers: {
'X-GitHub-Api-Version': '2022-11-28'
},
sha: quick_start_sha
})
}

25 changes: 25 additions & 0 deletions .github/workflows/auto_update_quick_start.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Auto-Update Py Quickstart Page
on:
push:
branches:
- latest
jobs:
update:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
sparse-checkout: .github
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 'latest'
- name: Run quickstart script
env:
REPO_TOKEN: ${{ secrets.DOCS_ACTION_TOKEN }}
run: |
cd ./.github/scripts/quickstart_py
ls
npm ci
node update_quickstart_py.js