Skip to content

Dev (#43)

Dev (#43) #20

Workflow file for this run

name: Android CI
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
inputs:
tag_prefix:
description: "Tag prefix for the release"
required: false
default: "v"
permissions:
contents: write
packages: write
issues: write
deployments: write
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
issues: write
deployments: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up JDK 21 (Zulu)
uses: actions/setup-java@v2
with:
distribution: "zulu"
java-version: "21"
- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Set execute permission for gradlew
run: chmod +x ./gradlew
- name: Create local.properties
run: |
echo "PRODUCTION_MODE=${{ secrets.PRODUCTION_MODE }}" >> $GITHUB_WORKSPACE/local.properties
echo "API_URL=${{ secrets.API_URL }}" >> $GITHUB_WORKSPACE/local.properties
echo "API_URL_PROD=${{ secrets.API_URL_PROD }}" >> $GITHUB_WORKSPACE/local.properties
echo "ARTICLE_URL=${{ secrets.ARTICLE_URL }}" >> $GITHUB_WORKSPACE/local.properties
- name: Decode and save keystore
run: |
echo "${{ secrets.KEYSTORE_BASE64 }}" | base64 --decode > $GITHUB_WORKSPACE/keystore.jks
- name: Set environment variables for signing
run: |
echo "KEYSTORE_PATH=$GITHUB_WORKSPACE/keystore.jks" >> $GITHUB_ENV
echo "KEY_ALIAS=${{ secrets.KEY_ALIAS }}" >> $GITHUB_ENV
echo "KEY_PASSWORD=${{ secrets.KEY_PASSWORD }}" >> $GITHUB_ENV
echo "KEYSTORE_PASSWORD=${{ secrets.KEYSTORE_PASSWORD }}" >> $GITHUB_ENV
- name: Build with Gradle
run: ./gradlew assembleRelease
- name: List output directory
run: ls -R app/build/outputs/apk/release
- name: Upload APK
if: success()
uses: actions/upload-artifact@v2
with:
name: apk-files
path: app/build/outputs/apk/release/app-release.apk
release:
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
issues: write
deployments: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0 # Ensures full history is fetched
- name: Download APKs
uses: actions/download-artifact@v2
with:
name: apk-files
path: .
- name: Get latest tag
id: get_latest_tag
run: |
latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null || echo "${{ github.event.inputs.tag_prefix }}0.0.0")
echo "latest_tag=$latest_tag" >> $GITHUB_ENV
shell: bash
- name: Generate new version
id: generate_version
run: |
latest_tag=${{ env.latest_tag }}
IFS='.' read -r -a version_parts <<< "${latest_tag#${{ github.event.inputs.tag_prefix }}}"
major=${version_parts[0]}
minor=${version_parts[1]}
patch=${version_parts[2]}
new_patch=$((patch + 1))
if [ $new_patch -ge 10 ]; then
new_minor=$((minor + 1))
new_patch=0
new_version="${{ github.event.inputs.tag_prefix }}$major.$new_minor.$new_patch"
else
new_version="${{ github.event.inputs.tag_prefix }}$major.$minor.$new_patch"
fi
echo "new_version=$new_version" >> $GITHUB_ENV
shell: bash
- name: Create new Git tag
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git tag ${{ env.new_version }}
git push origin ${{ env.new_version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
- name: Get commit title
id: get_commit_title
run: |
COMMIT_TITLE=$(git log -1 --pretty=%s)
echo "COMMIT_TITLE=$(echo $COMMIT_TITLE | tr -d '\n' | tr -d '\r')" >> $GITHUB_ENV
shell: bash
- name: Generate commit history
id: generate_commit_history
run: |
git log --oneline --decorate --no-merges | cut -d ' ' -f 2- > commit_history.txt
COMMIT_HISTORY=$(cat commit_history.txt)
echo "COMMIT_HISTORY<<EOF" >> $GITHUB_ENV
echo "$COMMIT_HISTORY" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
shell: bash
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_HISTORY: ${{ steps.generate_commit_history.outputs.COMMIT_HISTORY }}
with:
tag_name: ${{ env.new_version }}
release_name: Release ${{ env.new_version }}
body: |
${{ env.COMMIT_TITLE }}
## Commit History
${{ env.COMMIT_HISTORY }}
draft: false
prerelease: false
- name: Upload APK to Release
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./app-release.apk
asset_name: app-release.apk
asset_content_type: application/vnd.android.package-archive
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}