Quick test #26
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
name: Slack Notifications | |
on: | |
push: | |
jobs: | |
initial_msg: | |
runs-on: ubuntu-latest | |
outputs: | |
slack_msg_ts: ${{ steps.slack1.outputs.ts }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ref: ${{ github.head_ref || github.ref_name }} | |
- uses: qoomon/actions--context@v2 | |
id: context | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '16' | |
- name: Install dependencies | |
run: | | |
npm install fs-extra | |
# { | |
# "type": "section", | |
# "text": { | |
# "type": "mrkdwn", | |
# "text": "${{ github.actor }} started the process on ${{ github.ref_name }}. Run # ${{ github.ref_name }}. ${{ steps.context.outputs.job_log_url }}" | |
# } | |
# } | |
- name: Update footer. | |
run: | | |
node -e ' | |
const fs = require("fs-extra"); | |
const filePath = "./payload.json"; | |
const json = fs.readJSONSync(filePath); | |
json.blocks.push({ | |
"type": "section", | |
"text": { | |
"type": "mrkdwn", | |
"text": "${{ github.actor }} started the process on ${{ github.ref_name }}. Run # ${{ github.ref_name }}. ${{ steps.context.outputs.job_log_url }}" | |
} | |
}); | |
fs.writeJSONSync(filePath, json, { spaces: 2 }); | |
' | |
# C07MUHXPX97 | |
- name: Post to a Slack channel | |
id: slack1 | |
uses: slackapi/[email protected] | |
with: | |
# Slack channel id, channel name, or user id to post message. | |
# See also: https://api.slack.com/methods/chat.postMessage#channels | |
channel-id: 'C07MUHXPX97' | |
payload-file-path: "./payload.json" | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} | |
update_1: | |
runs-on: ubuntu-latest | |
needs: initial_msg | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ref: ${{ github.head_ref || github.ref_name }} | |
- uses: qoomon/actions--context@v2 | |
id: context | |
# Debugger | |
- uses: hmarr/debug-action@v2 | |
# - name: update payload | |
# run: | | |
# var data = JSON.parse(fs.readFileSync("./payload.json")); | |
# data.blocks[3].elements[1].elements[0].elements[0].name = 'red_circle'; | |
# echo JSON.stringify(data) > ./payload.json | |
# - uses: actions/github-script@v7 | |
# with: | |
# script: | | |
# const fs = require("fs"); | |
# var file_content = fs.readFileSync("./payload.json"); | |
# var data = JSON.parse(file_content); | |
# data.blocks[3].elements[1].elements[0].elements[0].name = 'red_circle'; | |
# # echo JSON.stringify(data) > ./payload.json | |
# fs.writeFileSync("./payload.json", data); | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '16' | |
- name: Install dependencies | |
run: | | |
npm install fs-extra | |
- name: update payload | |
run: | | |
node -e ' | |
const fs = require("fs-extra"); | |
const filePath = "./payload.json"; | |
const json = fs.readJSONSync(filePath); | |
json.blocks[3].elements[1].elements[0].elements[0].name = "red_circle"; | |
fs.writeJSONSync(filePath, json, { spaces: 2 }); | |
' | |
- uses: slackapi/[email protected] | |
with: | |
channel-id: "C07MUHXPX97" | |
update-ts: ${{ needs.initial_msg.outputs.slack_msg_ts }} | |
payload-file-path: "./payload.json" | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} | |
- name: update payload | |
run: | | |
node -e ' | |
const fs = require("fs-extra"); | |
const filePath = "./payload.json"; | |
const json = fs.readJSONSync(filePath); | |
json.blocks[3].elements[1].elements[1].elements[0].name = "large_green_circle"; | |
fs.writeJSONSync(filePath, json, { spaces: 2 }); | |
' | |
- uses: slackapi/[email protected] | |
with: | |
channel-id: "C07MUHXPX97" | |
update-ts: ${{ needs.initial_msg.outputs.slack_msg_ts }} | |
payload-file-path: "./payload.json" | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} | |
- uses: slackapi/[email protected] | |
with: | |
channel-id: "C07MUHXPX97" | |
update-ts: ${{ needs.initial_msg.outputs.slack_msg_ts }} | |
payload-file-path: "./payload.json" | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} | |
# - name: update payload | |
# run: | | |
# node -e ' | |
# const fs = require("fs-extra"); | |
# const filePath = "./payload.json"; | |
# const json = fs.readJSONSync(filePath); | |
# json.blocks[3].elements[1].elements[2].elements[0].name = "large_green_circle"; | |
# fs.writeJSONSync(filePath, json, { spaces: 2 }); | |
# ' | |
- name: Check jq | |
run: | | |
jq '.blocks[3].elements[1].elements[2].elements[0].name = "large_green_circle"' payload.json > temp.json | |
mv -- temp.json payload.json | |
rm -f -- temp.json | |
- uses: slackapi/[email protected] | |
with: | |
channel-id: "C07MUHXPX97" | |
update-ts: ${{ needs.initial_msg.outputs.slack_msg_ts }} | |
payload-file-path: "./payload.json" | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} | |
reply_1: | |
runs-on: ubuntu-latest | |
needs: initial_msg | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ref: ${{ github.head_ref || github.ref_name }} | |
- uses: qoomon/actions--context@v2 | |
id: context | |
- uses: slackapi/[email protected] | |
with: | |
channel-id: "C07MUHXPX97" | |
payload: | | |
{ | |
"thread_ts": "${{ needs.initial_msg.outputs.slack_msg_ts }}", | |
"blocks": [ | |
{ | |
"type": "section", | |
"text": { | |
"type": "mrkdwn", | |
"text": "PHPSTAN results" | |
}, | |
"accessory": { | |
"type": "button", | |
"text": { | |
"type": "plain_text", | |
"text": "Results", | |
"emoji": true | |
}, | |
"value": "phpstan_results", | |
"url": "${{ steps.context.outputs.job_log_url }}", | |
"action_id": "button-action" | |
} | |
} | |
] | |
} | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} | |
reply_2: | |
runs-on: ubuntu-latest | |
needs: initial_msg | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ref: ${{ github.head_ref || github.ref_name }} | |
- uses: qoomon/actions--context@v2 | |
id: context | |
- name: Messages to env var | |
run: | | |
MARKDOWN_CONTENTS=$(cat message.md) | |
echo "MARKDOWN_CONTENTS<<EOF" >> $GITHUB_ENV | |
echo "$MARKDOWN_CONTENTS" >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
MARKDOWN_CONTENTS2=${MARKDOWN_CONTENTS//$'\r\n'/} | |
echo "MARKDOWN_CONTENTS2=$MARKDOWN_CONTENTS2" >> $GITHUB_ENV | |
# Debugger | |
- uses: hmarr/debug-action@v2 | |
- uses: slackapi/[email protected] | |
with: | |
channel-id: "C07MUHXPX97" | |
payload: | | |
{ | |
"thread_ts": "${{ needs.initial_msg.outputs.slack_msg_ts }}", | |
"text": "Why do I have to have this text?", | |
"blocks": [ | |
{ | |
"type": "section", | |
"text": { | |
"type": "mrkdwn", | |
"text": "lol: ${{ env.MARKDOWN_CONTENTS }}" | |
}, | |
"accessory": { | |
"type": "button", | |
"text": { | |
"type": "plain_text", | |
"text": "Full Output", | |
"emoji": true | |
}, | |
"value": "phpstan_results", | |
"url": "${{ steps.context.outputs.job_log_url }}", | |
"action_id": "button-action" | |
} | |
} | |
] | |
} | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} |