diff --git a/.github/actions/generateTypedDocs/main.js b/.github/action-scripts/generateTypedDocs.js similarity index 87% rename from .github/actions/generateTypedDocs/main.js rename to .github/action-scripts/generateTypedDocs.js index d9470e1f8ea4..24240ace447e 100644 --- a/.github/actions/generateTypedDocs/main.js +++ b/.github/action-scripts/generateTypedDocs.js @@ -1,11 +1,9 @@ +// Creates or updates a PR with a documentation update + // @ts-check +/// 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", @@ -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", @@ -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}`, @@ -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", @@ -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; diff --git a/.github/actions/generateTypedDocs/action.yml b/.github/actions/generateTypedDocs/action.yml deleted file mode 100644 index d39198d9088f..000000000000 --- a/.github/actions/generateTypedDocs/action.yml +++ /dev/null @@ -1,10 +0,0 @@ -name: 'Update typed documentation' -description: 'Creates or updates a PR with a documentation update' -author: 'AlCalzone' -inputs: - githubToken: - description: 'The github token to use for authentication' - required: true -runs: - using: 'node20' - main: 'main.js' diff --git a/.github/workflows/generate-docs.yml b/.github/workflows/generate-docs.yml index 3ed907098236..0846535d879d 100644 --- a/.github/workflows/generate-docs.yml +++ b/.github/workflows/generate-docs.yml @@ -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 @@ -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});