diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 9501e089..509887c5 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -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 diff --git a/README.md b/README.md index a0b17a04..34472a6b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.yml b/action.yml index 773a7139..70bb2f5b 100644 --- a/action.yml +++ b/action.yml @@ -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 diff --git a/package.json b/package.json index 37bb21a2..ebf0e666 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/main.ts b/src/main.ts index 5710592f..a66ed698 100644 --- a/src/main.ts +++ b/src/main.ts @@ -25,7 +25,7 @@ async function run(): Promise { } 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}) || '{}') @@ -36,9 +36,9 @@ async function run(): Promise { 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)