Skip to content

Commit

Permalink
ci: migrate docs generation to github-script (#6734)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone authored Apr 8, 2024
1 parent 3c4ddcd commit 64caa72
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// Creates or updates a PR with a documentation update

// @ts-check
/// <reference path="../bot-scripts/types.d.ts" />

const exec = require("@actions/exec");
const github = require("@actions/github");
const core = require("@actions/core");

const githubToken = core.getInput("githubToken");
const octokit = github.getOctokit(githubToken).rest;

const options = {
owner: "zwave-js",
Expand All @@ -17,7 +15,12 @@ const assignees = [];

const checkPaths = ["docs/", "packages/*/api.md"];

(async function main() {
/**
* @param {{github: Github, context: Context}} param
*/
async function main(param) {
const { github, context } = param;

// check if our local working copy has any changes in the docs directory
const isChanged = !!(await exec.exec(
"git",
Expand All @@ -28,7 +31,7 @@ const checkPaths = ["docs/", "packages/*/api.md"];
));

// Check if a PR already exists
const PRs = await octokit.pulls.list({
const PRs = await github.rest.pulls.list({
...options,
state: "open",
head: `zwave-js:${branchName}`,
Expand Down Expand Up @@ -118,7 +121,7 @@ const checkPaths = ["docs/", "packages/*/api.md"];

if (!prNumber) {
// no PR exists, create one
const pr = await octokit.pulls.create({
const pr = await github.rest.pulls.create({
...options,
head: branchName,
base: "master",
Expand All @@ -131,20 +134,18 @@ const checkPaths = ["docs/", "packages/*/api.md"];
}
// Request review and add assignee
if (reviewers.length) {
await octokit.pulls.requestReviewers({
await github.rest.pulls.requestReviewers({
...options,
pull_number: prNumber,
reviewers,
});
}
if (assignees.length) {
await octokit.issues.addAssignees({
await github.rest.issues.addAssignees({
...options,
issue_number: prNumber,
assignees,
});
}
})().catch((e) => {
console.error(e);
process.exit(1);
});
}
module.exports = main;
10 changes: 0 additions & 10 deletions .github/actions/generateTypedDocs/action.yml

This file was deleted.

13 changes: 6 additions & 7 deletions .github/workflows/generate-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ jobs:
matrix:
node-version: [18] # This should be LTS

outputs:
CHANGES: ${{ steps.changes.outputs.CHANGES }}

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -58,8 +55,10 @@ jobs:
if: |
github.event_name == 'push' &&
github.ref == 'refs/heads/master'
uses: ./.github/actions/generateTypedDocs
uses: actions/github-script@v7
with:
githubToken: ${{ secrets.BOT_TOKEN }}
env:
CI: true
github-token: ${{secrets.BOT_TOKEN}}
result-encoding: string
script: |
const main = require(`${process.env.GITHUB_WORKSPACE}/.github/action-scripts/generateTypedDocs.js`);
return main({github, context});

0 comments on commit 64caa72

Please sign in to comment.