Skip to content

Commit

Permalink
Add support for 'webhook-url' action input
Browse files Browse the repository at this point in the history
Fixes #234
  • Loading branch information
satterly committed Jul 2, 2022
1 parent 3421aab commit 2c63b02
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/workflow.yml
Expand Up @@ -18,6 +18,7 @@ jobs:
- uses: actions/checkout@v2
- uses: ./
with:
webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
status: ${{ github.event.workflow_run.conclusion }}
channel: '#actions'
config: .github/slack-workflow.yml
Expand Down
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -29,6 +29,10 @@ when using a Slack App):

### Input Parameters (`with`)

#### `webhook-url` (optional)

Only required if the `SLACK_WEBHOOK_URL` environment variable is not set.

#### `status` (required)

The `status` must be defined. It can either be the current job status
Expand Down
7 changes: 5 additions & 2 deletions action.yml
Expand Up @@ -2,12 +2,15 @@ name: slack - GitHub Actions Slack integration
description: Notify Slack of GitHub Actions workflows, jobs and step status.
author: satterly
inputs:
webhook-url:
description: Specify Slack Incoming Webhook URL
required: false
config:
description: Configuration file
required: false
default: .github/slack.yml
status:
description: Specify success, failure, cancelled or a custom status.
description: Specify success, failure, cancelled or a custom status
required: true
steps:
description: Report on the status of individual steps
Expand All @@ -19,7 +22,7 @@ inputs:
description: Override message format for step
required: false
runs:
using: 'node12'
using: 'node16'
main: 'dist/index.js'
branding:
icon: alert-circle
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"build": "tsc",
"format": "prettier --write '**/*.ts'",
"format-check": "prettier --check '**/*.ts'",
"format-check": "prettier --check --loglevel debug '**/*.ts'",
"lint": "eslint src/**/*.ts",
"lint:fix": "eslint --fix src/**/*.ts",
"package": "ncc build --source-map --license licenses.txt",
Expand Down
6 changes: 3 additions & 3 deletions src/main.ts
Expand Up @@ -25,7 +25,7 @@ async function run(): Promise<void> {
}
core.debug(yaml.dump(config))

const url = process.env.SLACK_WEBHOOK_URL as string
const url = core.getInput('webhook-url', {required: false}) || (process.env.SLACK_WEBHOOK_URL as string)
const jobName = process.env.GITHUB_JOB as string
const jobStatus = core.getInput('status', {required: true}).toUpperCase()
const jobSteps = JSON.parse(core.getInput('steps', {required: false}) || '{}')
Expand All @@ -36,9 +36,9 @@ async function run(): Promise<void> {

if (url) {
await send(url, jobName, jobStatus, jobSteps, channel, message, config)
core.debug('Sent to Slack.')
core.info(`Sent ${jobName} status of ${jobStatus} to Slack!`)
} else {
core.info('No "SLACK_WEBHOOK_URL" secret configured. Skip.')
core.warning('No "SLACK_WEBHOOK_URL"s secret or "webhook-url" input configured. Skip.')
}
} catch (error) {
if (error instanceof Error) core.setFailed(error.message)
Expand Down

0 comments on commit 2c63b02

Please sign in to comment.