-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 950d7b9
Showing
15 changed files
with
13,845 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"env": { | ||
"commonjs": true, | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"globals": { | ||
"Atomics": "readonly", | ||
"SharedArrayBuffer": "readonly" | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2018 | ||
}, | ||
"rules": { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Container image that runs your code | ||
FROM node:12-slim | ||
|
||
# Copies your code file from your action repository to the filesystem path `/` of the container | ||
COPY entrypoint.sh /entrypoint.sh | ||
|
||
# Code file to execute when the docker container starts up (`entrypoint.sh`) | ||
ENTRYPOINT ["/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: 'Private Github Action' | ||
description: 'Download a private github action' | ||
inputs: | ||
package: | ||
description: 'Name of the Github Package' | ||
required: true | ||
token: | ||
description: 'Personal Access Token with permission for Github Packages' | ||
required: true | ||
path: | ||
description: 'Location within the path to put the ' | ||
required: true | ||
default: .gh-private-actions | ||
runs: | ||
using: 'docker' | ||
image: 'Dockerfile' | ||
args: | ||
- ${{ inputs.package }} | ||
- ${{ inputs.path }} | ||
- ${{ inputs.token }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/sh | ||
############################################################## | ||
# entrypoint.sh | ||
# | ||
set -e | ||
|
||
package_name=$1 | ||
directory=$2 | ||
token=$3 | ||
|
||
usage() { | ||
echo "entrypoint.sh package_name directory token" | ||
echo " package_name - Github package name" | ||
echo " directory - directory to install package" | ||
echo " token - Github Access Token with permissions for Github Packages" | ||
} | ||
|
||
test_param() { | ||
name=$1 | ||
param=$2 | ||
if test -z "${param}"; then | ||
echo "ERROR: Missing arg ${name}" | ||
usage | ||
exit 1 | ||
fi | ||
} | ||
|
||
test_param "package_name" "${package_name}" | ||
test_param "directory" "${directory}" | ||
test_param "token" "${token}" | ||
|
||
# ------------ # | ||
|
||
install_directory=${GITHUB_WORKSPACE}/${directory} | ||
|
||
GITHUB_PACKAGE_TOKEN=${token} | ||
export GITHUB_PACKAGE_TOKEN | ||
|
||
mkdir -p ${install_directory} && cd ${install_directory} | ||
echo '@wpmedia:registry=https://npm.pkg.github.com' >> .npmrc | ||
echo '//npm.pkg.github.com/:_authToken=${GITHUB_PACKAGE_TOKEN}' >> .npmrc | ||
npm install ${package_name} | ||
cp -R node_modules/* ${install_directory} | ||
|
||
echo "install_directory" $(ls -l ${install_directory}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Publish | ||
on: | ||
push: | ||
tags: | ||
- v* | ||
|
||
jobs: | ||
# unit tests | ||
github-packages: | ||
name: Publish Github Packages | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v1 | ||
- name: Checkout Git-Version | ||
uses: ./.github/actions/github-private-action | ||
with: | ||
package: '@wpmedia/[email protected]' | ||
token: ${{ secrets.GITHUB_PACKAGE_TOKEN }} | ||
- name: Get Git Metadata | ||
uses: ./.gh-private-actions/@wpmedia/git-version-action | ||
- name: Package | ||
env: | ||
PACKAGE_VERSION: ${{steps.get-git-metadata.outputs.git_version}} | ||
run: | | ||
npm install | ||
npm version ${PACKAGE_VERSION} | ||
npm run package | ||
- name: Publish | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
npm config set '//npm.pkg.github.com/:_authToken' '${GITHUB_TOKEN}' | ||
npm publish --registry https://npm.pkg.github.com | ||
- name: Slack Notify | ||
if: success() | ||
uses: ./ | ||
with: | ||
token: ${{ secrets.SLACK_BOT_TOKEN }} | ||
payload: '{ "channel": "#pun-unleashed-ops", text: "Build `${{ github.repository }}@${{ steps.get-git-metadata.outputs.git_version }}` was successful" }' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: "units-test" | ||
on: | ||
pull_request: | ||
push: | ||
|
||
jobs: | ||
# test action works running with actions/checkout@v2 | ||
test-v2: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Checkout Git-Version | ||
uses: ./.github/actions/github-private-action | ||
with: | ||
package: '@wpmedia/[email protected]' | ||
token: ${{ secrets.GITHUB_PACKAGE_TOKEN }} | ||
- name: Get Git Metadata | ||
uses: ./.gh-private-actions/@wpmedia/git-version-action | ||
- uses: ./ | ||
with: | ||
token: ${{ secrets.SLACK_BOT_TOKEN }} | ||
payload: '{ "channel": "#pun-unleashed-ops", text: "Test for `${{ steps.get-git-metadata.outputs.git_version }}` of `${{ github.repository }}`" }' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
node_modules/ | ||
|
||
# Editors | ||
.vscode | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Other Dependency directories | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
# next.js build output | ||
.next |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Copyright © 2020 The Washington Post. All rights reserved. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Post Slack messages | ||
|
||
This action wraps the Slack [chat.postMessage](https://api.slack.com/methods/chat.postMessage) API method for posting to channels, private groups, and DMs. This action sends messages using [Slack bot tokens](https://api.slack.com/docs/token-types), which have two main advantages compared to user tokens and incoming webhooks: (1) Bots can't be disabled inadvertently when a Slack user is disabled or removed. Slack has written about this in a [recent announcement](https://medium.com/slack-developer-blog/the-latest-with-app-tokens-fe878d44130c), and (2) Bots offer a [powerful range of capabilities](https://api.slack.com/bot-users) that can be leveraged to perform more functions. | ||
|
||
## Usage: | ||
|
||
```yaml | ||
- name: Notify slack | ||
uses: wpmedia/slack-action@master | ||
with: | ||
token: ${{ secrets.SLACK_BOT_TOKEN }} | ||
payload: '{\"channel\":\"C1234567890\",\"text\":\"Hello world\"}' | ||
``` | ||
## Setup | ||
To use this GitHub Action you'll first need to create a Slack App and install it to your Slack workspace. | ||
### Creating a Slack App | ||
1. **Create a Slack App**. Go to [Slack's developer site](https://api.slack.com/apps) then click "Create an app". Name the app "GitHub Action" (you can change this later) and make sure your team's Slack workspace is selected under "Development Slack Workspace" ([see screenshot](docs/images/slack-app.png)). | ||
2. **Add a Bot user**. Browse to the "Bot users" page listed in the sidebar. Name your bot "GitHub Action" (you can change this later) and leave the other default settings as-is | ||
3. **Set an icon for your bot.** Browse to the "Basic information" page listed in the sidebar. Scroll down to the section titled "Display information" to set an icon. Feel free to use one of the | ||
4. **Install your app to your workspace.** At the top of the "Basic information" page you can find a section titled "Install your app to your workspace". Click on it, then use the button to complete the installation | ||
## Using the action | ||
To use this GitHub Action, you'll need to set a `token` secret on GitHub. To get your Slack bot token, browse to the "OAuth & Permissions" page listed in Slack and copy the "Bot User OAuth Access Token" beginning in `xoxb-`. | ||
|
||
### Posting messages | ||
|
||
Slack's [chat.postMessage](https://api.slack.com/methods/chat.postMessage) method accepts a JSON payload containing options — this JSON payload should be supplied as the argument in your GitHub Action. At a bare minimum, your payload must include a channel ID and the message. Here's what a basic message might look like: | ||
|
||
```yaml | ||
- name: Notify slack | ||
uses: wpmedia/slack-action@master | ||
with: | ||
token: ${{ secrets.SLACK_BOT_TOKEN }} | ||
payload: '{\"channel\":\"C1234567890\",\"text\":\"Hello world\"}' | ||
``` | ||
|
||
Please note that if you are using the visual editor you should not escape quotes because GitHub will automatically escape them for you. | ||
|
||
#### Channel IDs | ||
|
||
A "channel ID" can be the ID of a channel, private group, or user you would like to post a message to. Your bot can message any user in your Slack workspace but needs to be invited into channels and private groups before it can post to them. | ||
|
||
If you open Slack in your web browser, you can find channel IDs at the end of the URL when viewing channels and private groups. Note that this doesn't work for direct messages. | ||
|
||
``` | ||
https://myworkspace.slack.com/messages/CHANNEL_ID/ | ||
``` | ||
You can also find channel IDs using the Slack API. Get a list of channels that your bot is a member of via Slack's [users.conversations](https://api.slack.com/methods/users.conversations) endpoint. Get user IDs for direct messages using Slack's [users.lookupByEmail](https://api.slack.com/methods/users.lookupByEmail) endpoint | ||
If the channel is private, you'll need to install the App in that channel. | ||
#### Formatting messages | ||
Please refer to [Slack's documentation](https://api.slack.com/docs/messages) on message formatting. They also have a [message builder](https://api.slack.com/docs/messages/builder) that's great for playing around and previewing messages. Your messages can contain attachments, markdown, buttons, and more. | ||
## License | ||
The Dockerfile and associated scripts and documentation in this project are released under the [MIT License](LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: 'Git Version' | ||
description: 'Output a deterministic semantic version' | ||
outputs: | ||
slack_token: | ||
payload: | ||
runs: | ||
using: 'node12' | ||
main: 'dist/index.js' |
Oops, something went wrong.