-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
"Added js script to update go file when latest gets a push" (#120)
Co-authored-by: FriendlyBandit <[email protected]>
- Loading branch information
1 parent
ea519eb
commit 092e93f
Showing
4 changed files
with
325 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "update_quickstart_go", | ||
"version": "1.0.0", | ||
"description": "Scrapes readme's hopefully", | ||
"main": "update_quickstart_go.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"run": "node update_quickstart_go.js" | ||
}, | ||
"author": "Memphis", | ||
"license": "ISC", | ||
"type": "module", | ||
"dependencies": { | ||
"@octokit/request": "^8.1.1", | ||
"@octokit/rest": "^20.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.go', | ||
doc_path: 'docs/sdk/client-libraries/go/quick-start.md', | ||
language_name: 'Go' | ||
}, | ||
] | ||
|
||
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: '[email protected]' | ||
}, | ||
content: btoa(commit_string), | ||
headers: { | ||
'X-GitHub-Api-Version': '2022-11-28' | ||
}, | ||
sha: quick_start_sha | ||
}) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Auto-Update Go 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_go | ||
ls | ||
npm ci | ||
node update_quickstart_go.js |