Skip to content

discord: embedded webhook for pretesters #2

discord: embedded webhook for pretesters

discord: embedded webhook for pretesters #2

Workflow file for this run

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,

Check failure on line 104 in .github/workflows/discord.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/discord.yml

Invalid workflow file

You have an error in your yaml syntax on line 104
"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 }}