Skip to content

One more polish

One more polish #36

Workflow file for this run

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
# Debugger
- uses: hmarr/debug-action@v2
- name: Debug
uses: raven-actions/debug@v1
with:
vars-context: ${{ toJson(vars) }} # optional
secrets-context: ${{ toJson(secrets) }} # optional
needs-context: ${{ toJson(needs) }} # optional
inputs-context: ${{ toJson(inputs) }} # optional
# - 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_template.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("./payload.json", json, { spaces: 2 });
# '
- name: Update footer
run: |
jq '.blocks += [{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "**${{ github.actor }}** started the process on *${{ github.ref_name }}*. Run #${{ github.run_number }}. [Job URL](${{ steps.context.outputs.job_log_url }})"
}
}]' payload_template.json > payload.json
# 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 }}
- name: Upload message file.
uses: actions/upload-artifact@v4
with:
name: message_payload
path: ./payload.json
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
- name: Download message Payload
uses: actions/download-artifact@v4
with:
name: message_payload
# 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 });
# '
- name: Check jq
run: |
jq '.blocks[3].elements[1].elements[0].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 }}
# - 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 });
# '
- name: Check jq
run: |
jq '.blocks[3].elements[1].elements[1].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 }}
- 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
- name: Download message Payload
uses: actions/download-artifact@v4
with:
name: message_payload
- 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: Download message Payload
uses: actions/download-artifact@v4
with:
name: message_payload
- 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=${MARKDOWN_CONTENTS2//&#x1F4DD;/}
echo ${MARKDOWN_CONTENTS2}
MARKDOWN_CONTENTS2=${MARKDOWN_CONTENTS2//&#x274C;/}
echo ${MARKDOWN_CONTENTS2}
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 }}