Fixing apk download section. #27
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: EAS Android Build & Release | |
on: | |
push: | |
branches: [main] | |
workflow_dispatch: | |
env: | |
EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
jobs: | |
build-android: | |
name: Build Android APK | |
runs-on: ubuntu-latest | |
outputs: | |
build_id: ${{ steps.build.outputs.BUILD_ID }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20.x | |
cache: "npm" | |
- name: Install dependencies | |
run: npm ci | |
- name: Install EAS CLI | |
run: npm install -g eas-cli@latest | |
- name: Debug Expo Authentication | |
run: | | |
echo "Checking Expo authentication..." | |
npx eas whoami --token $EXPO_TOKEN || echo "Expo token is invalid!" | |
- name: Start EAS Build (With Logs) | |
id: build | |
run: | | |
echo "Starting EAS build..." | |
# Ensure jq is installed | |
if ! command -v jq &> /dev/null; then | |
echo "jq could not be found" | |
exit 1 | |
fi | |
BUILD_ID=$(npx eas build -p android --profile production --non-interactive --json | jq -r '.[0].id') | |
if [[ -z "$BUILD_ID" || "$BUILD_ID" == "null" ]]; then | |
echo "Error: Failed to retrieve BUILD_ID!" | |
exit 1 | |
fi | |
echo "EAS Build started with ID: $BUILD_ID" | |
echo "BUILD_ID=$BUILD_ID" >> $GITHUB_ENV | |
echo "BUILD_ID=$BUILD_ID" >> $GITHUB_OUTPUT | |
env: | |
EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }} | |
download-apk: | |
name: Download APK | |
runs-on: ubuntu-latest | |
needs: build-android | |
outputs: | |
apk_path: ${{ steps.download.outputs.APK_PATH }} | |
steps: | |
- name: Wait for EAS Build to Complete | |
run: | | |
BUILD_ID=${{ needs.build-android.outputs.build_id }} | |
if [[ -z "$BUILD_ID" || "$BUILD_ID" == "null" ]]; then | |
echo "Error: BUILD_ID is missing or invalid!" | |
exit 1 | |
fi | |
echo "Waiting for EAS Build to complete..." | |
echo "BUILD_ID: $BUILD_ID" | |
RETRY_COUNT=0 | |
MAX_RETRIES=100 | |
SLEEP_TIME=30 | |
while [[ $RETRY_COUNT -lt $MAX_RETRIES ]]; do | |
BUILD_STATUS_JSON=$(npx eas build:view --json 2>/dev/null) | |
echo "Build status raw response: $BUILD_STATUS_JSON" | |
if [[ -z "$BUILD_STATUS_JSON" || "$BUILD_STATUS_JSON" == "null" ]]; then | |
echo "Error: Failed to fetch build status! Retrying in $SLEEP_TIME seconds..." | |
RETRY_COUNT=$((RETRY_COUNT+1)) | |
sleep $SLEEP_TIME | |
continue | |
fi | |
BUILD_STATUS=$(echo "$BUILD_STATUS_JSON" | jq -r '.status' 2>/dev/null) | |
if [[ -z "$BUILD_STATUS" || "$BUILD_STATUS" == "null" ]]; then | |
echo "Error: Build status is empty! Retrying..." | |
RETRY_COUNT=$((RETRY_COUNT+1)) | |
sleep $SLEEP_TIME | |
continue | |
fi | |
echo "Current Build Status: $BUILD_STATUS" | |
if [[ "$BUILD_STATUS" == "FINISHED" ]]; then | |
APK_URL=$(echo "$BUILD_STATUS_JSON" | jq -r '.artifacts.buildUrl' 2>/dev/null) | |
if [[ -z "$APK_URL" || "$APK_URL" == "null" ]]; then | |
echo "Error: APK URL not found!" | |
exit 1 | |
fi | |
echo "APK_URL=$APK_URL" >> $GITHUB_ENV | |
break | |
elif [[ "$BUILD_STATUS" == "errored" ]]; then | |
echo "EAS build failed." | |
exit 1 | |
fi | |
RETRY_COUNT=$((RETRY_COUNT+1)) | |
sleep $SLEEP_TIME | |
done | |
if [[ $RETRY_COUNT -eq $MAX_RETRIES ]]; then | |
echo "Error: Build did not complete within the expected time!" | |
exit 1 | |
fi | |
env: | |
EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }} | |
- name: Download APK | |
id: download | |
run: | | |
echo "Downloading APK from: $APK_URL" | |
curl -L $APK_URL -o app-release.apk | |
ls -lh app-release.apk | |
echo "APK_PATH=app-release.apk" >> $GITHUB_OUTPUT | |
- name: Upload APK as artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: android-apk | |
path: app-release.apk | |
generate-changelog: | |
name: Generate Changelog | |
runs-on: ubuntu-latest | |
needs: build-android | |
outputs: | |
changelog: ${{ steps.changelog.outputs.CHANGELOG }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Generate Changelog | |
id: changelog | |
run: | | |
echo "Generating changelog..." | |
echo "## Changelog" > changelog.txt | |
echo "" >> changelog.txt | |
git log --pretty=format:"- %s (%h) by %an" $(git rev-parse HEAD^)..HEAD >> changelog.txt | |
cat changelog.txt | |
echo "CHANGELOG<<EOF" >> $GITHUB_ENV | |
cat changelog.txt >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
echo "CHANGELOG=$GITHUB_ENV" >> $GITHUB_OUTPUT | |
- name: Upload Changelog as artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: changelog | |
path: changelog.txt | |
create-release: | |
name: Create GitHub Release | |
runs-on: ubuntu-latest | |
needs: [download-apk, generate-changelog] | |
steps: | |
- name: Download APK artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: android-apk | |
- name: Download Changelog artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: changelog | |
- name: Create GitHub Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
tag_name: v1.0.${{ github.run_number }} | |
name: Release v1.0.${{ github.run_number }} | |
body_path: changelog.txt | |
draft: false | |
prerelease: false | |
files: app-release.apk |