From 6f94912a33168052b1b7b25ee20c414f52b3e56f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=B3=E7=BA=A2=E7=A6=8F?= Date: Wed, 11 Sep 2019 11:56:17 +0800 Subject: [PATCH] init --- .editorconfig | 20 ++++++++++++++++++++ .github/workflows/main.yml | 31 ++++++++++++++++++++----------- .gitignore | 1 + Dockerfile | 17 +++++++++++++++++ LICENSE | 21 +++++++++++++++++++++ README.md | 26 +++++++++++++++++++++++++- entrypoint.js | 31 +++++++++++++++++++++++++++++++ package.json | 19 +++++++++++++++++++ 8 files changed, 154 insertions(+), 12 deletions(-) create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 entrypoint.js create mode 100644 package.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..efb3367 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,20 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# http://editorconfig.org + +root = true + +[*] + +# Change these settings to your own preference +indent_style = space +indent_size = 2 + +# We recommend you to keep these unchanged +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5baabd1..6a5fbf7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,12 +1,21 @@ -workflow "Send notification on push" { - on = "push" - resolves = [ - "WeChat Work notification", - ] -} +name: Send notification on push +on: [push] + +jobs: + send-msg: + runs-on: ubuntu-latest + steps: + - name: WeChat Work notification by text + uses: chf007/action-wechat-work@master + env: + WECHAT_WORK_BOT_WEBHOOK: ${{secrets.WECHAT_WORK_BOT_WEBHOOK}} + with: + msgtype: text + content: 广州今日天气:29度,大部分多云,降雨概率:60% + mentioned_list: + - '@all' + - andreiguan + mentioned_mobile_list: + - '@all' + - 15002085767 -action "WeChat Work notification" { - uses = "chf007/action-wechat-work@master" - secrets = ["WECHAT_WORK_WEBHOOK"] - args = "A new commit has been pushed to chf007/action-wechat-work." -} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e10ea40 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM mhart/alpine-node:10.15.1 + +LABEL "com.github.actions.name"="GitHub Action for WeChat Work" +LABEL "com.github.actions.description"="Outputs a message to WeChat Work." +LABEL "com.github.actions.icon"="hash" +LABEL "com.github.actions.color"="red" + +LABEL "repository"="https://github.com/chf007/action-wechat-work" +LABEL "homepage"="https://github.com/chf007/action-wechat-work" +LABEL "maintainer"="chf007 " +LABEL "version"="0.0.1" + +ADD entrypoint.js package.json package-lock.json / +RUN npm ci +RUN chmod +x /entrypoint.js + +ENTRYPOINT ["node", "/entrypoint.js"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..90e1189 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Nicolas Coutin + +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 index 2cab97e..9ba0213 100644 --- a/README.md +++ b/README.md @@ -1 +1,25 @@ -# action-wechat-work \ No newline at end of file +# WeChat Work for GitHub Actions + +Sends a WeChat Work notification. Simple as that. + +![WeChat Work Logo](wechat-work-logo.png "WeChat Work Logo") + +*Appearance on WeChat Work :* + +![WeChat Work message](action-message.png "WeChat Work message") + +
+ +## Usage + +```hcl +action "WeChat Work notification" { + uses = "chf007/action-wechat-work@master" + secrets = ["WECHAT_WORK_BOT_WEBHOOK"] +} +``` + +### Secrets + +* **`WECHAT_WORK_BOT_WEBHOOK`**: the WeChat Work webhook URL (**required**, see https://work.weixin.qq.com/api/doc#90000/90136/91770). +* That's all. diff --git a/entrypoint.js b/entrypoint.js new file mode 100644 index 0000000..69d1601 --- /dev/null +++ b/entrypoint.js @@ -0,0 +1,31 @@ +const axios = require('axios'); +const _ = require('lodash'); +const { argv } = require('yargs'); + +const payload = { + msgtype: 'text', + text: { + content: `${process.env.GITHUB_REPOSITORY}/${process.env.GITHUB_WORKFLOW} triggered by ${process.env.GITHUB_ACTOR} (${process.env.GITHUB_EVENT_NAME})`, + } +}; + +console.log('The message content in JSON format...'); +console.log(JSON.stringify(payload)); + +const url = process.env.WECHAT_WORK_BOT_WEBHOOK; + +(async () => { + console.log('Sending message ...'); + await axios.post(url, JSON.stringify(payload), { + headers: { + 'Content-Type': 'application/json' + }, + }); + console.log('Message sent ! Shutting down ...'); + process.exit(0); +})() + .catch((err) => { + console.error(err.message); + console.error('Message :', err.response.data); + process.exit(1); + }); diff --git a/package.json b/package.json new file mode 100644 index 0000000..4acbc7d --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "action-wechat-work", + "version": "0.0.1", + "description": "Sends a WeChat Work notification. Simple as that.", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/chf007/action-wechat-work.git" + }, + "author": "chf007 ", + "license": "MIT", + "bugs": { + "url": "https://github.com/chf007/action-wechat-work/issues" + }, + "homepage": "https://github.com/chf007/action-wechat-work#readme" +}