Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: migrate docs generation to github-script #6734

Merged
merged 1 commit into from
Apr 8, 2024
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
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 checkPaths = ["docs/", "packages/*/api.md"];

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

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused variable context.

// 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 @@
));

// 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 @@

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 @@
}
// 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});
Loading