Merge pull request #189 from JohnsonMao/feature/signin-page-success-m… #1
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: Push Change to Discord Webhook URL | |
on: | |
push: | |
branches: | |
- dev | |
# Allow manual trigger | |
workflow_dispatch: | |
jobs: | |
send-to-discord-webhook-url: | |
runs-on: ubuntu-latest | |
steps: | |
- name: crawl-commit-message-headers | |
id: crawl-commit-message-headers | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const commits = context.payload.commits; | |
const messages = commits.map(commit => commit.message.split('\n')[0]); | |
console.log(commits, messages); | |
console.log('context: ', context) | |
core.exportVariable('messages', messages.join('\n')); | |
- name: build-discord-webhook-payload | |
id: build-discord-webhook-payload | |
uses: actions/github-script@v7 | |
env: | |
# sandbox webhook url | |
DISCORD_WEBHOOK_URL: ${{ secrets.SANDBOX_DISCORD_WEBHOOK_URL }} | |
# real webhook url | |
# DISCORD_WEBHOOK_URL: ${{ secrets.SPLIT_GAME_CHANNEL_DISCORD_WEBHOOK_URL }} | |
with: | |
script: | | |
const { messages } = process.env; | |
const discordWebhookPayload = { | |
content: '# 島島阿學前端更新' + '\n' + messages, | |
username: '島島阿學日誌' | |
}; | |
const req = new Request(process.env.DISCORD_WEBHOOK_URL, { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify(discordWebhookPayload) | |
}); | |
const res = await fetch(req); | |
if (!res.ok) { | |
throw new Error(`HTTP error! status: ${res.status}`); | |
} |