diff --git a/.github/actions/bot/action.yaml b/.github/actions/bot/action.yaml new file mode 100644 index 0000000..b1f060f --- /dev/null +++ b/.github/actions/bot/action.yaml @@ -0,0 +1,10 @@ +name: "Bot" +description: "🤖 beep boop" +runs: + using: "composite" + steps: + - uses: actions/github-script@v7 + with: + script: | + const bot = require('./.github/actions/bot/index.js'); + await bot(core, github, context); diff --git a/.github/actions/bot/index.js b/.github/actions/bot/index.js new file mode 100644 index 0000000..4a1be3a --- /dev/null +++ b/.github/actions/bot/index.js @@ -0,0 +1,56 @@ +async function bot(core, github, context) { + const payload = context.payload; + + if (!payload.comment) { + console.log("No comment found"); + return; + } + + const author = payload.comment.user.login; + const authorized = ["OWNER", "MEMBER"].includes(payload.comment.author_association); + if (!authorized) { + console.log(`Not authorized: ${author}`); + return; + } + + const body = payload.comment.body.trim(); + + // Check for /ci test command + if (body === "/ci test") { + console.log("Dispatching ci-test workflow"); + + // Get PR details + const pr = await github.rest.pulls.get({ + owner: payload.repository.owner.login, + repo: payload.repository.name, + pull_number: payload.issue.number + }); + + // Reply to the comment + await github.rest.issues.createComment({ + owner: payload.repository.owner.login, + repo: payload.repository.name, + issue_number: payload.issue.number, + body: `@${author} I've triggered the e2e testing workflow! 🚀` + }); + + // Dispatch the workflow + await github.rest.actions.createWorkflowDispatch({ + owner: payload.repository.owner.login, + repo: payload.repository.name, + workflow_id: 'ci-test.yaml', + ref: 'main', + inputs: { + pr_number: payload.issue.number.toString(), + git_sha: pr.data.head.sha, + requester: author + } + }); + } +} + +module.exports = async (core, github, context) => { + await bot(core, github, context).catch((error) => { + core.setFailed(error); + }); +} diff --git a/.github/workflows/bot-trigger.yaml b/.github/workflows/bot-trigger.yaml new file mode 100644 index 0000000..20f6091 --- /dev/null +++ b/.github/workflows/bot-trigger.yaml @@ -0,0 +1,14 @@ +name: Bot +run-name: 🤖 beep boop +on: + issue_comment: + types: + - created +jobs: + bot: + if: ${{ github.event.issue.pull_request }} + runs-on: ubuntu-latest + permissions: write-all + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/bot