Dev #35
@@ -2,24 +2,22 @@ name: Build and Release APK
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
tags:
|
||||||
|
- 'v*'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
ANDROID_HOME: ${{ runner.tool_cache }}/android-sdk
|
ANDROID_HOME: ${{ runner.tool_cache }}/android-sdk
|
||||||
ANDROID_SDK_ROOT: ${{ runner.tool_cache }}/android-sdk
|
ANDROID_SDK_ROOT: ${{ runner.tool_cache }}/android-sdk
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
|
||||||
apk-path: ${{ steps.upload-apk.outputs.path }}
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Set up Node
|
- name: Set up Node
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
@@ -43,7 +41,6 @@ jobs:
|
|||||||
unzip -q /tmp/cmdtools.zip -d "$ANDROID_HOME/cmdline-tools"
|
unzip -q /tmp/cmdtools.zip -d "$ANDROID_HOME/cmdline-tools"
|
||||||
mv "$ANDROID_HOME/cmdline-tools/cmdline-tools" "$ANDROID_HOME/cmdline-tools/latest"
|
mv "$ANDROID_HOME/cmdline-tools/cmdline-tools" "$ANDROID_HOME/cmdline-tools/latest"
|
||||||
fi
|
fi
|
||||||
# Accept all licenses by writing known license hashes
|
|
||||||
mkdir -p "$ANDROID_HOME/licenses"
|
mkdir -p "$ANDROID_HOME/licenses"
|
||||||
echo "8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
|
echo "8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
|
||||||
echo "d56f5187479451eabf01fb78af6dfcb131a6481e" >> "$ANDROID_HOME/licenses/android-sdk-license"
|
echo "d56f5187479451eabf01fb78af6dfcb131a6481e" >> "$ANDROID_HOME/licenses/android-sdk-license"
|
||||||
@@ -78,63 +75,47 @@ jobs:
|
|||||||
cd carry-your-live/android
|
cd carry-your-live/android
|
||||||
./gradlew assembleRelease
|
./gradlew assembleRelease
|
||||||
|
|
||||||
- name: Upload APK
|
- name: Find APK
|
||||||
id: upload-apk
|
id: find-apk
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: carry-your-live-release
|
|
||||||
path: carry-your-live/android/app/build/outputs/release/app-release.apk
|
|
||||||
|
|
||||||
release:
|
|
||||||
needs: build
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Download APK artifact
|
|
||||||
uses: actions/download-artifact@v3
|
|
||||||
with:
|
|
||||||
name: carry-your-live-release
|
|
||||||
path: .
|
|
||||||
|
|
||||||
- name: Compute next version
|
|
||||||
id: version
|
|
||||||
run: |
|
run: |
|
||||||
latest=$(git tag --list 'v[0-9]*' --sort=-v:refname | head -n 1)
|
APK_PATH=$(find carry-your-live/android/app/build/outputs -name "*.apk" -type f | head -n 1)
|
||||||
if [ -z "$latest" ]; then
|
echo "apk_path=$APK_PATH" >> "$GITHUB_OUTPUT"
|
||||||
next="v1.0.0"
|
echo "Found APK at: $APK_PATH"
|
||||||
else
|
|
||||||
latest=${latest#v}
|
|
||||||
IFS='.' read -r major minor patch <<< "$latest"
|
|
||||||
next="v${major}.${minor}.$((patch + 1))"
|
|
||||||
fi
|
|
||||||
echo "next=${next}" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
- name: Build changelog
|
- name: Create Gitea Release and Upload APK
|
||||||
id: changelog
|
if: startsWith(github.ref, 'refs/tags/v')
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
prev_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
|
TAG_NAME="${GITHUB_REF#refs/tags/}"
|
||||||
if [ -z "$prev_tag" ]; then
|
REPO_OWNER="${GITHUB_REPOSITORY%/*}"
|
||||||
log=$(git log --oneline --no-merges main | head -n 40)
|
REPO_NAME="${GITHUB_REPOSITORY#*/}"
|
||||||
else
|
APK_PATH="${{ steps.find-apk.outputs.apk_path }}"
|
||||||
log=$(git log --oneline --no-merges "$prev_tag"..main | head -n 40)
|
APK_NAME="carry-your-live-${TAG_NAME}.apk"
|
||||||
|
|
||||||
|
# Create release using Gitea API
|
||||||
|
RESPONSE=$(curl -s -X POST "https://techmos.gitea.org/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases" \
|
||||||
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "{
|
||||||
|
\"tag_name\": \"${TAG_NAME}\",
|
||||||
|
\"name\": \"${TAG_NAME}\",
|
||||||
|
\"body\": \"Automated release for ${TAG_NAME}\",
|
||||||
|
\"draft\": false,
|
||||||
|
\"prerelease\": false
|
||||||
|
}")
|
||||||
|
|
||||||
|
RELEASE_ID=$(echo "$RESPONSE" | jq -r '.id')
|
||||||
|
|
||||||
|
if [ "$RELEASE_ID" = "null" ] || [ -z "$RELEASE_ID" ]; then
|
||||||
|
echo "Release might already exist, fetching existing release..."
|
||||||
|
RELEASE_ID=$(curl -s -H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
|
"https://techmos.gitea.org/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases/tags/${TAG_NAME}" | jq -r '.id')
|
||||||
fi
|
fi
|
||||||
{
|
|
||||||
echo "body<<EOF"
|
# Upload APK as attachment
|
||||||
echo "## What's new in this release"
|
curl -s -X POST "https://techmos.gitea.org/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases/${RELEASE_ID}/assets" \
|
||||||
echo ""
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
echo "$log" | sed 's/^/- /'
|
-F "attachment=@${APK_PATH};filename=${APK_NAME}"
|
||||||
echo "EOF"
|
|
||||||
} >> "$GITHUB_OUTPUT"
|
echo "APK uploaded to release ${TAG_NAME}"
|
||||||
|
|
||||||
- name: Create release
|
|
||||||
uses: softprops/action-gh-release@v2
|
|
||||||
with:
|
|
||||||
tag_name: ${{ steps.version.outputs.next }}
|
|
||||||
name: ${{ steps.version.outputs.next }}
|
|
||||||
body: ${{ steps.changelog.outputs.body }}
|
|
||||||
files: ./app-release.apk
|
|
||||||
generate_release_notes: false
|
|
||||||
Reference in New Issue
Block a user