Skip to content

Commit

Permalink
ci: migrate pack PR action to github-script (#6897)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone authored Jun 6, 2024
1 parent 835e40d commit 8cffeea
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 40 deletions.
19 changes: 0 additions & 19 deletions .github/actions/zwave-js-bot/action.yml

This file was deleted.

1 change: 1 addition & 0 deletions .github/bot-scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ module.exports = {
importConfigCreatePR: (...args) =>
require("./importConfigCreatePR")(...args),
shouldAutomerge: (...args) => require("./shouldAutomerge")(...args),
packPr: (...args) => require("./packPr")(...args),
};
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
// 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 npmToken = core.getInput("npmToken");
const task = core.getInput("task");
const octokit = github.getOctokit(githubToken).rest;
const semver = require("semver");

const options = {
owner: "zwave-js",
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,
});
Expand Down Expand Up @@ -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.
Expand All @@ -78,11 +77,13 @@ yarn add zwave-js@${newVersion}
\`\`\``,
});
} else {
octokit.issues.createComment({
github.rest.issues.createComment({
...options,
issue_number: pr,
body:
`😥 Unfortunately I could not publish the new packages. Check out the logs to see what went wrong.`,
});
}
}

module.exports = main;
15 changes: 9 additions & 6 deletions .github/workflows/zwave-js-bot_comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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});
# #########################################################################
Expand Down

0 comments on commit 8cffeea

Please sign in to comment.