mirror of
https://github.com/rebelonion/Dantotsu.git
synced 2026-01-28 23:31:02 +00:00
195 lines
6.9 KiB
YAML
195 lines
6.9 KiB
YAML
name: Build APK and Notify Discord
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- dev
|
|
paths-ignore:
|
|
- '**/README.md'
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
CI: true
|
|
SKIP_BUILD: false
|
|
|
|
steps:
|
|
- name: Checkout repo
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
|
|
- name: Download last SHA artifact
|
|
uses: dawidd6/action-download-artifact@v3
|
|
with:
|
|
workflow: beta.yml
|
|
name: last-sha
|
|
path: .
|
|
|
|
continue-on-error: true
|
|
|
|
- name: Get Commits Since Last Run
|
|
run: |
|
|
if [ -f last_sha.txt ]; then
|
|
LAST_SHA=$(cat last_sha.txt)
|
|
else
|
|
# Fallback to first commit if no previous SHA available
|
|
LAST_SHA=$(git rev-list --max-parents=0 HEAD)
|
|
fi
|
|
echo "Commits since $LAST_SHA:"
|
|
# Accumulate commit logs in a shell variable
|
|
COMMIT_LOGS=$(git log $LAST_SHA..HEAD --pretty=format:"● %s ~%an")
|
|
# Replace commit messages with pull request links
|
|
COMMIT_LOGS=$(echo "$COMMIT_LOGS" | sed -E 's/#([0-9]+)/[#\1](https:\/\/github.com\/rebelonion\/Dantotsu\/pull\/\1)/g')
|
|
# URL-encode the newline characters for GitHub Actions
|
|
COMMIT_LOGS="${COMMIT_LOGS//'%'/'%25'}"
|
|
COMMIT_LOGS="${COMMIT_LOGS//$'\n'/'%0A'}"
|
|
COMMIT_LOGS="${COMMIT_LOGS//$'\r'/'%0D'}"
|
|
# Append the encoded commit logs to the COMMIT_LOG environment variable
|
|
echo "COMMIT_LOG=${COMMIT_LOGS}" >> $GITHUB_ENV
|
|
# Debugging: Print the variable to check its content
|
|
echo "$COMMIT_LOGS"
|
|
echo "$COMMIT_LOGS" > commit_log.txt
|
|
shell: /usr/bin/bash -e {0}
|
|
env:
|
|
CI: true
|
|
continue-on-error: true
|
|
|
|
- name: Save Current SHA for Next Run
|
|
run: echo ${{ github.sha }} > last_sha.txt
|
|
|
|
- name: Set variables
|
|
run: |
|
|
VER=$(grep -E -o "versionName \".*\"" app/build.gradle | sed -e 's/versionName //g' | tr -d '"')
|
|
SHA=${{ github.sha }}
|
|
VERSION="$VER+${SHA:0:7}"
|
|
echo "Version $VERSION"
|
|
echo "VERSION=$VERSION" >> $GITHUB_ENV
|
|
|
|
- name: Setup JDK 17
|
|
uses: actions/setup-java@v4
|
|
with:
|
|
distribution: 'temurin'
|
|
java-version: 17
|
|
cache: gradle
|
|
|
|
- name: List files in the directory
|
|
run: ls -l
|
|
|
|
- name: Make gradlew executable
|
|
run: chmod +x ./gradlew
|
|
|
|
- name: Build with Gradle
|
|
if: ${{ env.SKIP_BUILD != 'true' }}
|
|
run: ./gradlew assembleGoogleAlpha
|
|
|
|
- name: Upload a Build Artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: Dantotsu
|
|
retention-days: 5
|
|
compression-level: 9
|
|
path: "app/build/outputs/apk/google/alpha/app-google-alpha.apk"
|
|
|
|
- name: Upload APK to Discord and Telegram
|
|
shell: bash
|
|
run: |
|
|
# Function to fetch user details
|
|
fetch_user_details() {
|
|
local login=$1
|
|
user_details=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
|
"https://api.github.com/users/$login")
|
|
name=$(echo "$user_details" | jq -r '.name // .login')
|
|
echo "$name|$login"
|
|
}
|
|
# Fetch contributors
|
|
contributors=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
|
"https://api.github.com/repos/rebelonion/Dantotsu/contributors")
|
|
# Process contributors
|
|
developers=""
|
|
while read -r login commits; do
|
|
user_info=$(fetch_user_details "$login")
|
|
name=$(echo "$user_info" | cut -d'|' -f1)
|
|
login=$(echo "$user_info" | cut -d'|' -f2)
|
|
developers="${developers}◗ **${name}**\n- Github: [${login}](https://github.com/${login})\n- Commits: ${commits}\n\n"
|
|
done < <(echo "$contributors" | jq -r '.[] | "\(.login) \(.contributions)"')
|
|
# Truncate developers if too long
|
|
max_length=1000
|
|
if [ ${#developers} -gt $max_length ]; then
|
|
developers="${developers:0:$max_length}... (truncated)"
|
|
fi
|
|
# Process commit messages
|
|
commit_messages=$(echo "$COMMIT_LOG" | sed 's/%0A/\n/g; s/^/\n/')
|
|
if [ ${#commit_messages} -gt $max_length ]; then
|
|
commit_messages="${commit_messages:0:$max_length}... (truncated)"
|
|
fi
|
|
# Construct Discord payload
|
|
discord_data=$(jq -nc \
|
|
--arg field_value "$commit_messages" \
|
|
--arg author_value "$developers" \
|
|
--arg footer_text "Version $VERSION" \
|
|
--arg timestamp "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)" \
|
|
--arg thumbnail_url "https://avatars.githubusercontent.com/u/41344259?v=4" \
|
|
'{
|
|
"content": "@here",
|
|
"embeds": [
|
|
{
|
|
"title": "New Alpha-Build dropped",
|
|
"color": 15532323,
|
|
"fields": [
|
|
{
|
|
"name": "Commits:",
|
|
"value": $field_value,
|
|
"inline": true
|
|
},
|
|
{
|
|
"name": "Developers:",
|
|
"value": $author_value,
|
|
"inline": false
|
|
}
|
|
],
|
|
"footer": {
|
|
"text": $footer_text
|
|
},
|
|
"timestamp": $timestamp,
|
|
"thumbnail": {
|
|
"url": $thumbnail_url
|
|
}
|
|
}
|
|
],
|
|
"attachments": []
|
|
}')
|
|
# Send Discord message
|
|
curl -H "Content-Type: application/json" \
|
|
-d "$discord_data" \
|
|
${{ secrets.DISCORD_WEBHOOK }}
|
|
|
|
# Upload APK to Discord
|
|
curl -F "payload_json=${contentbody}" \
|
|
-F "dantotsu_debug=@app/build/outputs/apk/google/alpha/app-google-alpha.apk" \
|
|
${{ secrets.DISCORD_WEBHOOK }}
|
|
|
|
# Send Telegram message and upload APK
|
|
curl -F "chat_id=${{ secrets.TELEGRAM_CHANNEL_ID }}" \
|
|
-F "document=@app/build/outputs/apk/google/alpha/app-google-alpha.apk" \
|
|
-F "caption=Alpha-Build: ${VERSION}: ${commit_messages}" \
|
|
https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendDocument
|
|
|
|
env:
|
|
COMMIT_LOG: ${{ env.COMMIT_LOG }}
|
|
VERSION: ${{ env.VERSION }}
|
|
|
|
- name: Upload Current SHA as Artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: last-sha
|
|
path: last_sha.txt
|
|
|
|
- name: Upload Commit log as Artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: commit-log
|
|
path: commit_log.txt
|