Skip to content

mockup: 切圖使用2x大小 #16

mockup: 切圖使用2x大小

mockup: 切圖使用2x大小 #16

name: Push Change to Discord Webhook URL
on:
push:
branches:
- main
# 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 iconMessages = messages.split('\n').map(m => {
const [commitType, message, ...rest]= m.split(': ');
if (commitType !== 'feat' && commitType !== 'fix' && commitType !== 'mockup') {
return;
}
const icon = commitType === 'feat' ? '<:thumb:1239951662832156752>' : commitType === 'fix' ? ':construction_site:' : ':womans_clothes:';
return icon + ' ' + message;
}).filter(Boolean);
const availableAvatarUrls = [
'https://media.discordapp.net/attachments/808663045109710898/1277146864906407988/image.png?ex=66ce1574&is=66ccc3f4&hm=f8dbff1de3b493dcdd0c8844a848efaa3c36b7296466d6709b9fe1c610561fa5&=&format=webp&quality=lossless',
'https://media.discordapp.net/attachments/808663045109710898/1277146864659070976/image.png?ex=66ce1574&is=66ccc3f4&hm=92594dbcba8a33e7505364f787b4893cf332e92aa5824a1646bf944be57c3655&=&format=webp&quality=lossless',
'https://media.discordapp.net/attachments/808663045109710898/1277146865158328331/image.png?ex=66ce1574&is=66ccc3f4&hm=dfa1646736b9ad59e297f10c0cf83a52fc99eba24615c6e5f6507ece9032a180&=&format=webp&quality=lossless',
'https://media.discordapp.net/attachments/808663045109710898/1277146865351262249/image.png?ex=66ce1574&is=66ccc3f4&hm=0241c136973320980b25d3a87138c30f875800e690b3eee028d5e44fbba2af2b&=&format=webp&quality=lossless'
]
const discordWebhookPayload = {
content: '# 企鵝搶地前端 update' + '\n' + iconMessages.join('\n'),
username: '企鵝探險日誌',
avatar_url: availableAvatarUrls.sort(() => Math.random() - 0.5)[0]
};
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}`);
}