Merge pull request #244 from wxxsfxyzm/dev #160
This file contains hidden or 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: Automatic Alpha Pre-Release (Latest Only) | |
on: | |
push: | |
branches: [ "main" ] | |
jobs: | |
build_and_prerelease: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
# Step 1: Check out the code | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
# Step 2: Get the short commit SHA | |
- name: Get commit short SHA | |
id: commit_sha | |
run: echo "SHORT_SHA=$(git rev-parse --short=7 HEAD)" >> $GITHUB_OUTPUT | |
# Step 3: Set up the JDK environment | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'zulu' | |
java-version: '21' | |
cache: gradle | |
# Step 4: Update the versionName in build file to format A.B.C.hash | |
- name: Update versionName format | |
id: version | |
run: | | |
# Extract A.B.C from build.gradle.kts | |
VERSION=$(grep -oP 'versionName = "\K([0-9]+\.[0-9]+\.[0-9]+)' app/build.gradle.kts) | |
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT | |
A=$(echo $VERSION | cut -d. -f1) | |
B=$(echo $VERSION | cut -d. -f2) | |
C=$(echo $VERSION | cut -d. -f3) | |
C_NEW=$((C + 1)) | |
# The new version name written to the gradle file | |
NEW_VERSION="${A}.${B}.${C_NEW}.${{ steps.commit_sha.outputs.SHORT_SHA }}" | |
sed -i "s/versionName = \".*\"/versionName = \"${NEW_VERSION}\"/" app/build.gradle.kts | |
# The new version tag for the release (e.g., v1.2.4) | |
echo "VNEW_VERSION=v${A}.${B}.${C_NEW}" >> $GITHUB_OUTPUT | |
# Step 5: Grant execute permission for gradlew | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./gradlew | |
# Step 6: Decode and set up the signing key | |
- name: Decode and set up signing key | |
run: | | |
mkdir -p keystore | |
echo "${{ secrets.SIGNING_KEY_STORE_BASE64 }}" | base64 --decode > keystore/carlyu.jks | |
echo "storeFile=keystore/carlyu.jks" > keystore.properties | |
echo "keyAlias=${{ secrets.SIGNING_KEY_ALIAS }}" >> keystore.properties | |
echo "keyPassword=${{ secrets.SIGNING_KEY_PASSWORD }}" >> keystore.properties | |
echo "storePassword=${{ secrets.SIGNING_STORE_PASSWORD }}" >> keystore.properties | |
# Step 7: Build both Preview Release APKs | |
- name: Build Preview Release APKs | |
run: ./gradlew assembleOnlinePreviewRelease assembleOfflinePreviewRelease | |
# Step 8: Find and Rename Preview APKs | |
- name: Find and Rename Preview APKs | |
id: rename_apks | |
run: | | |
PROJECT_NAME="InstallerX-Revived" | |
VERSION_TAG="${{ steps.version.outputs.VNEW_VERSION }}.${{ steps.commit_sha.outputs.SHORT_SHA }}" | |
ONLINE_APK_DIR="app/build/outputs/apk/onlinePreview/release/" | |
OFFLINE_APK_DIR="app/build/outputs/apk/offlinePreview/release/" | |
ONLINE_APK_PATH=$(find "$ONLINE_APK_DIR" -maxdepth 1 -type f -name "*.apk" | head -n 1) | |
OFFLINE_APK_PATH=$(find "$OFFLINE_APK_DIR" -maxdepth 1 -type f -name "*.apk" | head -n 1) | |
if [ -z "$ONLINE_APK_PATH" ] || [ -z "$OFFLINE_APK_PATH" ]; then | |
echo "ERROR: Could not find both APKs!" | |
ls -R app/build/outputs/apk | |
exit 1 | |
fi | |
NEW_ONLINE_APK_NAME="${PROJECT_NAME}-online-${VERSION_TAG}.apk" | |
NEW_OFFLINE_APK_NAME="${PROJECT_NAME}-offline-${VERSION_TAG}.apk" | |
NEW_ONLINE_APK_PATH="${ONLINE_APK_DIR}${NEW_ONLINE_APK_NAME}" | |
NEW_OFFLINE_APK_PATH="${OFFLINE_APK_DIR}${NEW_OFFLINE_APK_NAME}" | |
mv "$ONLINE_APK_PATH" "$NEW_ONLINE_APK_PATH" | |
mv "$OFFLINE_APK_PATH" "$NEW_OFFLINE_APK_PATH" | |
echo "online_apk=${NEW_ONLINE_APK_PATH}" >> $GITHUB_OUTPUT | |
echo "offline_apk=${NEW_OFFLINE_APK_PATH}" >> $GITHUB_OUTPUT | |
# Step 9: Delete the old alpha release and its corresponding git tag | |
- name: Delete old alpha release and tag | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
LATEST_TAG=$(git tag --list "*-alpha-latest" | sort -Vr | head -n 1) | |
if [[ -n "$LATEST_TAG" ]]; then | |
gh release delete "$LATEST_TAG" --yes || echo "No previous alpha release found to delete." | |
git push origin --delete "$LATEST_TAG" || echo "No previous alpha tag found to delete." | |
else | |
echo "No alpha-latest tag to delete." | |
fi | |
# Step 10: Automatically generate changelog from commit history | |
- name: Generate changelog | |
id: changelog | |
run: | | |
PREV_TAG=$(git tag --list | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -Vr | head -n 1) | |
CURR_TAG="${{ steps.version.outputs.VNEW_VERSION }}-alpha-latest" | |
if [ -z "$PREV_TAG" ]; then | |
LOG_RANGE="" | |
else | |
LOG_RANGE="$PREV_TAG..HEAD" | |
fi | |
# Get the last 5 commits, excluding merge commits | |
CHANGELOG_LIST=$(git log $LOG_RANGE --pretty=format:"- %s (%an)" | grep -v '^-\s*Merge' | head -n 5) | |
CHANGELOG_COUNT=$(git log $LOG_RANGE --pretty=format:"- %s (%an)" | grep -v '^-\s*Merge' | wc -l) | |
CHANGELOG_BODY_OUTPUT="" | |
if [ -z "$CHANGELOG_LIST" ]; then | |
CHANGELOG_BODY_OUTPUT="No changes since the last stable release." | |
else | |
CHANGELOG_BODY_OUTPUT="$CHANGELOG_LIST" | |
fi | |
CHANGELOG_LINK_OUTPUT="" | |
if [ "$CHANGELOG_COUNT" -gt 5 ]; then | |
if [ -z "$PREV_TAG" ]; then | |
COMPARE_URL="https://github.com/${{ github.repository }}/commits/main" | |
else | |
COMPARE_URL="https://github.com/${{ github.repository }}/compare/${PREV_TAG}...${CURR_TAG}" | |
fi | |
# Store the link in its own variable. Note the \n\n for markdown formatting. | |
CHANGELOG_LINK_OUTPUT="\n\n**Full Changelog:** [\`${PREV_TAG}...${CURR_TAG}\`]($COMPARE_URL)" | |
fi | |
{ | |
echo "changelog_body<<EOF" | |
echo -e "$CHANGELOG_BODY_OUTPUT" | |
echo "EOF" | |
} >> $GITHUB_OUTPUT | |
{ | |
echo "changelog_full_link<<EOF" | |
echo -e "$CHANGELOG_LINK_OUTPUT" | |
echo "EOF" | |
} >> $GITHUB_OUTPUT | |
echo "--- Generated Changelog for Release Body ---" | |
echo -e "${CHANGELOG_BODY_OUTPUT}${CHANGELOG_LINK_OUTPUT}" | |
# Step 11: Create Latest Alpha Pre-Release with two APKs | |
- name: Create Latest Alpha Pre-Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
name: "InstallerX Revived Alpha (${{ steps.commit_sha.outputs.SHORT_SHA }})" | |
tag_name: "${{ steps.version.outputs.VNEW_VERSION }}-alpha-latest" | |
target_commitish: ${{ github.sha }} | |
body: | | |
## 这是自动构建的最新 Alpha 测试版。 | |
- **这是一个预发布版本,并非为生产环境准备就绪。** | |
- 我们非常鼓励您分享您的看法! | |
## This is an automatically built latest Alpha pre-release. | |
- **This is a pre-release version and is not intended for production use.** | |
- We appreciate any feedback! | |
**更新日志(Changelog):** | |
${{ steps.changelog.outputs.changelog_body }}${{ steps.changelog.outputs.changelog_full_link }} | |
prerelease: true | |
files: | | |
${{ steps.rename_apks.outputs.online_apk }} | |
${{ steps.rename_apks.outputs.offline_apk }} | |
# Step 12: Upload the APK to Telegram | |
- name: Upload to Telegram | |
env: | |
API_ID: ${{ secrets.API_ID }} | |
API_HASH: ${{ secrets.API_HASH }} | |
BOT_TOKEN: ${{ secrets.BOT_TOKEN }} | |
CHAT_ID: ${{ secrets.CHAT_ID }} | |
BOT_CI_SESSION: ${{ secrets.BOT_CI_SESSION }} | |
run: | | |
pip3 install telethon | |
python3 .github/bot.py "${{ steps.rename_apks.outputs.online_apk }}" "${{ steps.rename_apks.outputs.offline_apk }}" |