diff --git a/.github/actions/zwave-js-bot/action.yml b/.github/actions/zwave-js-bot/action.yml deleted file mode 100644 index 1c5a9397f54..00000000000 --- a/.github/actions/zwave-js-bot/action.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: 'Z-Wave JS Bot' -description: 'Contains the actions the Bot can execute' -author: 'AlCalzone' -inputs: - githubToken: - description: 'The github token to use for authentication' - required: true - npmToken: - description: 'The token used to publish to npm' - required: true - task: - description: 'What the bot is supposed to do' - required: true - pr: - description: '(publish-pr task only) The PR that should be published' - required: false -runs: - using: 'node20' - main: 'main.js' diff --git a/.github/bot-scripts/index.js b/.github/bot-scripts/index.js index ac79a6b5582..0a545da1f60 100644 --- a/.github/bot-scripts/index.js +++ b/.github/bot-scripts/index.js @@ -21,4 +21,5 @@ module.exports = { importConfigCreatePR: (...args) => require("./importConfigCreatePR")(...args), shouldAutomerge: (...args) => require("./shouldAutomerge")(...args), + packPr: (...args) => require("./packPr")(...args), }; diff --git a/.github/actions/zwave-js-bot/main.js b/.github/bot-scripts/packPr.js similarity index 74% rename from .github/actions/zwave-js-bot/main.js rename to .github/bot-scripts/packPr.js index 8a8e8a46e32..4d702dbacb0 100644 --- a/.github/actions/zwave-js-bot/main.js +++ b/.github/bot-scripts/packPr.js @@ -1,13 +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 npmToken = core.getInput("npmToken"); -const task = core.getInput("task"); -const octokit = github.getOctokit(githubToken).rest; const semver = require("semver"); const options = { @@ -15,13 +11,16 @@ const options = { repo: "node-zwave-js", }; -if (task === "publish-pr") { - publishPr().catch(() => process.exit(1)); -} +/** + * @param {{github: Github, context: Context}} param + */ +async function main(param) { + const { github, context } = param; -async function publishPr() { - const pr = parseInt(core.getInput("pr")); - const { data: pull } = await octokit.pulls.get({ + const npmToken = /** @type {string} */ (process.env.NPM_TOKEN); + const pr = context.issue.number; + + const { data: pull } = await github.rest.pulls.get({ ...options, pull_number: pr, }); @@ -68,7 +67,7 @@ async function publishPr() { } if (success) { - octokit.issues.createComment({ + github.rest.issues.createComment({ ...options, issue_number: pr, body: `🎉 The packages have been published. @@ -78,7 +77,7 @@ yarn add zwave-js@${newVersion} \`\`\``, }); } else { - octokit.issues.createComment({ + github.rest.issues.createComment({ ...options, issue_number: pr, body: @@ -86,3 +85,5 @@ yarn add zwave-js@${newVersion} }); } } + +module.exports = main; diff --git a/.github/workflows/zwave-js-bot_comment.yml b/.github/workflows/zwave-js-bot_comment.yml index 772c015b35f..1e3034b8948 100644 --- a/.github/workflows/zwave-js-bot_comment.yml +++ b/.github/workflows/zwave-js-bot_comment.yml @@ -67,13 +67,16 @@ jobs: - name: Install dependencies run: yarn install --immutable - - name: Let the bot do its thing - uses: ./.github/actions/zwave-js-bot + - name: Publish PR build to npm + uses: actions/github-script@v7 + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} with: - githubToken: ${{ secrets.BOT_TOKEN }} - npmToken: ${{ secrets.NPM_TOKEN }} - task: publish-pr - pr: ${{ github.event.issue.number }} + github-token: ${{ secrets.BOT_TOKEN }} + result-encoding: string + script: | + const bot = require(`${process.env.GITHUB_WORKSPACE}/.github/bot-scripts/index.js`); + return bot.packPr({github, context}); # #########################################################################