This commit is contained in:
关红福 2019-09-11 11:56:17 +08:00
parent fcc3b78bbc
commit 6f94912a33
8 changed files with 154 additions and 12 deletions

20
.editorconfig Normal file
View File

@ -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

View File

@ -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."
}

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

17
Dockerfile Normal file
View File

@ -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 <chf007server@gmail.com>"
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"]

21
LICENSE Normal file
View File

@ -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.

View File

@ -1 +1,25 @@
# action-wechat-work
# 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")
<hr/>
## 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.

31
entrypoint.js Normal file
View File

@ -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);
});

19
package.json Normal file
View File

@ -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 <chf007server@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/chf007/action-wechat-work/issues"
},
"homepage": "https://github.com/chf007/action-wechat-work#readme"
}