Skip to content

Commit

Permalink
Add instructions for developing with a local version of the action (#250
Browse files Browse the repository at this point in the history
)
  • Loading branch information
zimeg committed Nov 17, 2023
1 parent d240824 commit 813c9c1
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/maintainers_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/local/.env.example
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .github/workflows/local/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Secret variables
.env
25 changes: 25 additions & 0 deletions .github/workflows/local/README.md
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 9 additions & 0 deletions .github/workflows/local/event.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
28 changes: 28 additions & 0 deletions .github/workflows/local/local.yml
Original file line number Diff line number Diff line change
@@ -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 }}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 813c9c1

Please sign in to comment.