discord: embedded webhook for pretesters #3
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: Upload to Discord | ||
on: | ||
workflow_call: | ||
inputs: | ||
commit_log: | ||
required: true | ||
type: string | ||
version: | ||
required: true | ||
type: string | ||
jobs: | ||
upload: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Upload APK to Discord | ||
shell: bash | ||
run: | | ||
# Author information map (replace with your own values) | ||
declare -A author_map=( | ||
["ibo"]="951737931159187457|takarealist112" | ||
["aayush262"]="918825160654598224|aayush262" | ||
) | ||
function get_author_info() { | ||
local commits=$1 | ||
local author_info=() | ||
while read -r line; do | ||
if [[ $line =~ ^●\ .* ~(.*)$ ]]; then | ||
author=${BASH_REMATCH[1]} | ||
author_name=$(echo "$author" | cut -d'<' -f1 | xargs) | ||
author_login=$(echo "$author" | cut -d'<' -f2 | cut -d'>' -f1 | xargs) | ||
# Check if author information is provided | ||
if [[ -n "${author_map[$author_name]}" ]]; then | ||
author_info+=("$author_name|$author_login|${author_map[$author_name]}") | ||
else | ||
author_info+=("$author_name|$author_login") | ||
fi | ||
fi | ||
done <<< "$commits" | ||
if [ "${#authors[@]}" -gt 0 ]; then | ||
echo "Missing information for the following authors: ${authors[*]}" | ||
echo "Please provide their Discord IDs and AniList usernames in the author_map variable." | ||
return 1 | ||
fi | ||
if [ "${#author_info[@]}" -eq 1 ]; then | ||
IFS='|' read -ra author_data <<< "${author_info[0]}" | ||
author_name=${author_data[0]} | ||
author_login=${author_data[1]} | ||
if [ "${#author_data[@]}" -eq 3 ]; then | ||
discord_id=${author_data[2]%|*} | ||
anilist_username=${author_data[2]#*|} | ||
thumbnail_url="https://avatars.githubusercontent.com/u/$author_login" | ||
developer_field="◗ **$author_name**\n- Discord: <@$discord_id>\n- Github: [$author_name](<https://github.com/$author_login>)\n- Anilist: [$anilist_username](<https://anilist.co/user/$anilist_username>)" | ||
else | ||
thumbnail_url="https://avatars.githubusercontent.com/u/$author_login" | ||
developer_field="◗ **$author_name**\n- Github: [$author_name](<https://github.com/$author_login>)" | ||
fi | ||
else | ||
thumbnail_url="https://i.imgur.com/5o3Y9Jb.gif" | ||
developer_field="" | ||
for author_data in "${author_info[@]}"; do | ||
IFS='|' read -ra author_data <<< "$author_data" | ||
author_name=${author_data[0]} | ||
author_login=${author_data[1]} | ||
if [ "${#author_data[@]}" -eq 3 ]; then | ||
discord_id=${author_data[2]%|*} | ||
anilist_username=${author_data[2]#*|} | ||
developer_field+="◗ **$author_name**\n- Discord: <@$discord_id>\n- Github: [$author_name](<https://github.com/$author_login>)\n- Anilist: [$anilist_username](<https://anilist.co/user/$anilist_username>)\n" | ||
else | ||
developer_field+="◗ **$author_name**\n- Github: [$author_name](<https://github.com/$author_login>)\n" | ||
fi | ||
done | ||
fi | ||
echo "$thumbnail_url" | ||
echo "$developer_field" | ||
} | ||
commit_messages=$(echo "${{ inputs.commit_log }}" | sed 's/%0A/\n/g; s/^/\n/') | ||
max_length=1000 | ||
if [ ${#commit_messages} -gt $max_length ]; then | ||
commit_messages="${commit_messages:0:$max_length}... (truncated)" | ||
fi | ||
read -r thumbnail_url developer_field < <(get_author_info "$commit_messages") | ||
if [ $? -ne 0 ]; then | ||
exit 1 | ||
fi | ||
discord_data=$(jq -nc \ | ||
--arg field_value "$commit_messages" \ | ||
--arg footer_text "Version ${{ inputs.version }}" \ | ||
--arg timestamp "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)" \ | ||
--arg thumbnail_url "$thumbnail_url" \ | ||
--arg developer_field "$developer_field" \ | ||
'{ | ||
"content": null, | ||
"embeds": [ | ||
{ | ||
"title": "New Alpha-Build dropped", | ||
"description": "<@&1225347048321191996>", | ||
"color": 15532323, | ||
"fields": [ | ||
{ | ||
"name": "Commits:", | ||
"value": $field_value, | ||
"inline": true | ||
}, | ||
{ | ||
"name": "Developers:", | ||
"value": $developer_field, | ||
"inline": true | ||
} | ||
], | ||
"footer": { | ||
"text": $footer_text | ||
}, | ||
"timestamp": $timestamp, | ||
"thumbnail": { | ||
"url": $thumbnail_url | ||
} | ||
} | ||
], | ||
"attachments": [] | ||
}') | ||
echo "$discord_data" | ||
curl -H "Content-Type: application/json" \ | ||
-d "$discord_data" \ | ||
${{ secrets.DISCORD_WEBHOOK }} | ||
echo "$response_headers" | ||
curl -F "dantotsu_debug=@app/build/outputs/apk/google/alpha/app-google-alpha.apk" \ | ||
${{ secrets.DISCORD_WEBHOOK }} |