From a54f85980e40b6b67efb78374ebdb863ea443d52 Mon Sep 17 00:00:00 2001 From: Adam Millerchip Date: Sat, 17 Oct 2020 17:50:59 +0900 Subject: [PATCH] Add initial orb config. --- CHANGELOG.md | 14 +++++ LICENSE | 21 +++++++ README.md | 3 + slack-webhook-orb.yml | 140 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 178 insertions(+) create mode 100644 CHANGELOG.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 slack-webhook-orb.yml diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..af74b4a --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,14 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + - Current development changes [ to be moved to release ] + +## [0.0.1] - 2020-10-17 + - Initial Release + + +[1.0.0]: https://github.com/adamu/slack-webhook-orb/releases/tag/0.0.1:w diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..7332bec --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Adam Millerchip + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..9a1dcb0 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Slack Webhook CircleCI Orb [![CircleCI Orb Version](https://img.shields.io/badge/endpoint.svg?url=https://badges.circleci.io/orb/adamu/slack-webhook)](https://circleci.com/orbs/registry/orb/adamu/slack-webhook) + + diff --git a/slack-webhook-orb.yml b/slack-webhook-orb.yml new file mode 100644 index 0000000..f45d3ce --- /dev/null +++ b/slack-webhook-orb.yml @@ -0,0 +1,140 @@ +version: 2.1 + +description: A simple orb to send fully-customized Slack messages via Slack webhooks. + +display: + source_url: "https://github.com/adamu/slack-webhook-orb" + +commands: + send-message: + description: Send a message to slack via a webhook. + parameters: + json-payload: + type: string + description: The Slack JSON Payload. + webhook-url: + type: string + default: '' + description: The URL of the Slack webhook. + webhook-url-env-var: + type: string + default: SLACK_WEBHOOK + description: | + The name of the environment variable configured in CircleCI that contains the Slack webhook URL + steps: + - run: + name: Send a message to Slack via a webhook + command: | + # Put the json payload into a slack.json file to avoid interpeting it + cat > slack.json \<<'SLACK-PAYLOAD-4FC4D2195631E5-EOF' + << parameters.json-payload >> + SLACK-PAYLOAD-4FC4D2195631E5-EOF + + # The directly-specified URL overrides the environment variable, if supplied + if [[ "<< parameters.webhook-url >>" ]]; then + << parameters.webhook-url-env-var >>=<< parameters.webhook-url >> + fi + + if [[ -z "$<< parameters.webhook-url-env-var >>" ]]; then + 1>&2 echo "Webhook URL is not defined. + Please supply webhook-url or webhook-url-env-var arguments to slack-webhook orb, + or set the SLACK_WEBHOOK environment vairable." + exit 1 + fi + + # Call the webhook + curl -H 'Content-type: application/json' --data-binary @slack.json $<< parameters.webhook-url-env-var >> + +examples: + webhook-url: + description: | + Provide the webhook URL directly in the webhook-url parameter. + Note that this leaks the Webhook URL in your CircleCI config and the CircleCI logs, + so using one of the environment variable option is preferred. + Provide the Slack JSON payload in the json-payload parameter. + The payload can be generated with the Slack Block Kit Builder: https://app.slack.com/block-kit-builder + usage: + version: 2.1 + + orbs: + slack-webhook: adamu/slack-webhook@1.0.0 + + jobs: + build: + docker: + - image: cimg/base:stable + steps: + - slack-webhook/send-message: + webhook-url: https://hooks.slack.com/... + json-payload: | + { + "blocks": [ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "Hello from 's `slack-webhook` CircleCi orb! 👋" + } + } + ] + } + environment-variable: + description: | + Provide the webhook URL in the SLACK_WEBHOOK environment variable on CircleCI. + When using this method, only the json-payload parameter needs to be supplied. + The payload can be generated with the Slack Block Kit Builder: https://app.slack.com/block-kit-builder + usage: + version: 2.1 + + orbs: + slack-webhook: adamu/slack-webhook@1.0.0 + + jobs: + build: + docker: + - image: cimg/base:stable + steps: + - slack-webhook/send-message: + json-payload: | + { + "blocks": [ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "Hello from 's `slack-webhook` CircleCi orb! 👋" + } + } + ] + } + custom-environment-variable: + description: | + Supply the webhook URL in a custom environment variable configured on CircleCI, + and provide the name of the environment variable in the webhook-url-env-var parameter. + Provide the Slack JSON payload in the json-payload parameter. + The payload can be generated with the Slack Block Kit Builder: https://app.slack.com/block-kit-builder + usage: + version: 2.1 + + orbs: + slack-webhook: adamu/slack-webhook@1.0.0 + + jobs: + build: + docker: + - image: cimg/base:stable + steps: + - slack-webhook/send-message: + webhook-url-env-var: CUSTOM_SLACK_WEBHOOK_VARIABLE + json-payload: | + { + "blocks": [ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "Hello from 's `slack-webhook` CircleCi orb! 👋" + } + } + ] + }