From 813c9c190d6932b08456732c084e5fe5e02415c8 Mon Sep 17 00:00:00 2001 From: Ethan Zimbelman Date: Fri, 17 Nov 2023 13:06:11 -0800 Subject: [PATCH] Add instructions for developing with a local version of the action (#250) --- .github/maintainers_guide.md | 5 +++++ .github/workflows/local/.env.example | 4 ++++ .github/workflows/local/.gitignore | 2 ++ .github/workflows/local/README.md | 25 +++++++++++++++++++++++++ .github/workflows/local/event.json | 9 +++++++++ .github/workflows/local/local.yml | 28 ++++++++++++++++++++++++++++ package.json | 1 + 7 files changed, 74 insertions(+) create mode 100644 .github/workflows/local/.env.example create mode 100644 .github/workflows/local/.gitignore create mode 100644 .github/workflows/local/README.md create mode 100644 .github/workflows/local/event.json create mode 100644 .github/workflows/local/local.yml diff --git a/.github/maintainers_guide.md b/.github/maintainers_guide.md index 6450a81..4511ebe 100644 --- a/.github/maintainers_guide.md +++ b/.github/maintainers_guide.md @@ -11,6 +11,11 @@ All you need to work with this project is a supported version of [Node.js](https ## Tasks +### Developing + +Iterate quickly by developing and testing a local version of this action using `npm run local`. +Information on setting up and configuring mocked events can be found in [`.github/workflows/local/README.md`](./workflows/local/README.md). + ### Testing When testing locally, ensure at least linting and unit tests pass by running `npm test`. diff --git a/.github/workflows/local/.env.example b/.github/workflows/local/.env.example new file mode 100644 index 0000000..c7b5cdf --- /dev/null +++ b/.github/workflows/local/.env.example @@ -0,0 +1,4 @@ +# Rename this file to .env and update any variables to get started + +SLACK_BOT_TOKEN=xoxb-01010101-abcdefgh +SLACK_WEBHOOK_URL=https://hooks.slack.com/services/T0123456789/B0123456789/abcdefghijklmnopqrstuvwxyz diff --git a/.github/workflows/local/.gitignore b/.github/workflows/local/.gitignore new file mode 100644 index 0000000..4ce635d --- /dev/null +++ b/.github/workflows/local/.gitignore @@ -0,0 +1,2 @@ +# Secret variables +.env diff --git a/.github/workflows/local/README.md b/.github/workflows/local/README.md new file mode 100644 index 0000000..1cdd9e5 --- /dev/null +++ b/.github/workflows/local/README.md @@ -0,0 +1,25 @@ +# Local runs + +For a simple development experience, a local version of this action can be used in experiments. + +**Requirements**: + +- An installation of [nektos/act](https://github.com/nektos/act) + +## Configuring secrets + +To use `${{ secrets.* }}` in the workflow, move `.env.example` to `.env` and update any variables. + +## Mocking event payloads + +Different event payloads can be mocked directly with changes to the `event.json` file. + +Reference: https://docs.github.com/en/webhooks/webhook-events-and-payloads + +## Updating the workflow + +The `local.yml` file contains the workflow used for testing. Updates to these steps can be made to test various functionalities. + +## Running an experiment + +Run the workflow using `npm run local`. The above configurations will be used to simulate an actual workflow run. diff --git a/.github/workflows/local/event.json b/.github/workflows/local/event.json new file mode 100644 index 0000000..383b814 --- /dev/null +++ b/.github/workflows/local/event.json @@ -0,0 +1,9 @@ +{ + "pull_request": { + "user": { + "login": "dependabot" + }, + "title": "Bump actions/checkout from 3 to 4", + "html_url": "https://github.com/slackapi/slack-github-action/pull/238" + } +} diff --git a/.github/workflows/local/local.yml b/.github/workflows/local/local.yml new file mode 100644 index 0000000..1518950 --- /dev/null +++ b/.github/workflows/local/local.yml @@ -0,0 +1,28 @@ +name: Local run + +# Requires mocking the "public" event to begin this workflow and avoid actual runs +# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows +on: + public: + +jobs: + run: + runs-on: ubuntu-latest + steps: + - name: Checkout action + uses: actions/checkout@v4 + - name: Build action + run: npm install && npm run build + - name: Send a message into channel + id: slack + uses: ./. + with: + payload: | + { + "repository": "${{ github.repository }}", + "pull_request_username": "${{ github.event.pull_request.user.login }}", + "pull_request_title": ${{ toJSON(github.event.pull_request.title) }}, + "pull_request_url": "${{ github.event.pull_request.html_url }}" + } + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/package.json b/package.json index d4b15a3..c80f84d 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "main": "dist/index.js", "scripts": { "lint": "eslint .", + "local": "act public --eventpath .github/workflows/local/event.json --secret-file .github/workflows/local/.env", "test:mocha": "nyc mocha --config .mocharc.json test/*-test.js", "test": "npm run lint && npm run test:mocha", "build": "npx @vercel/ncc build src/index.js --license licenses.txt"