Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 'webhook-url' action input #242

Merged
merged 1 commit into from Jul 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
5 changes: 4 additions & 1 deletion 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 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