Skip to content

Build Release App

Build Release App #136

Workflow file for this run

name: Build Release App
on:
# Every Saturday at 21:00 UTC
# schedule:
# - cron: '0 21 * * 6'
# Manual triggers
workflow_dispatch:
env:
JAVA_VERSION: 21
JAVA_DISTRO: 'temurin'
jobs:
build-app:
runs-on: macos-latest
outputs:
CREATE_RELEASE: ${{ steps.prepare_changelog.outputs.CREATE_RELEASE }}
CHANGELOG: ${{ steps.prepare_changelog.outputs.CHANGELOG }}
COMMIT_COUNT_OUTPUT: ${{ steps.prepare_build.outputs.COMMIT_COUNT_OUTPUT }}
env:
commit_count_diff: 0
PREV_RELEASE_SHA: ''
CURRENT_SHA: ''
COMMIT_COUNT: 0
FGA_VERSION_CODE: 0
FGA_VERSION_NAME: ''
COMMIT_LOGS: ''
TAG_NAME: ''
permissions:
contents: write
discussions: write
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
repository: 'ArthurKun21/FGA-Preview'
token: ${{ secrets.PAT }}
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
path: 'preview'
- name: Get previous release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd preview
OUTPUT=$(gh release list --exclude-drafts --exclude-pre-releases --json tagName --limit 1 --jq 'select(length > 0) | .[0].tagName')
if [ -n "$OUTPUT" ]; then
echo "TAG_NAME=$OUTPUT" >> $GITHUB_ENV
echo "Latest Tag: $OUTPUT"
else
echo "Failed to get repository information"
exit 1
fi
- name: Prepare build
id: prepare_build
run: |
commit_count=$(git rev-list --count HEAD)
echo "COMMIT_COUNT=$commit_count" >> $GITHUB_ENV
echo "COMMIT_COUNT_OUTPUT=$commit_count" >> $GITHUB_OUTPUT
current_sha=$(git rev-parse --short HEAD)
echo "CURRENT_SHA=$current_sha" >> $GITHUB_ENV
echo "FGA_VERSION_CODE=$commit_count" >>${GITHUB_ENV}
echo "FGA_VERSION_NAME=$current_sha" >>${GITHUB_ENV}
prev_commit_count=$(echo "${{ env.TAG_NAME }}" | sed -e "s/^pre-//")
commit_count_diff=$(($commit_count - $prev_commit_count))
echo "commit_count_diff=$commit_count_diff" >> $GITHUB_ENV
prev_release_sha=$(git rev-parse --short HEAD~$commit_count_diff)
echo "PREV_RELEASE_SHA=$prev_release_sha" >> $GITHUB_ENV
echo "COMMIT_LOGS<<{delimiter}
$(curl -H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${{ secrets.PAT }}" \
"https://api.github.com/repos/Arthurkun21/fga-preview/compare/$prev_release_sha...$current_sha" \
| jq '[.commits[]|{message:(.commit.message | split("\n")), username:.author.login}]' \
| jq -r '.[]|"- \(.message | first) (@\(.username))"')
{delimiter}" >> $GITHUB_ENV
- name: Prepare changelog
id: prepare_changelog
if: ${{ env.commit_count_diff > 0 }}
run: |
# Get the current date
CURRENT_DATE=$(date +"%Y-%m-%d")
CHANGELOG="# ${COMMIT_COUNT}\n\n$CURRENT_DATE\n\n${COMMIT_LOGS}"
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
echo -e "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "CREATE_RELEASE=true" >> $GITHUB_OUTPUT
- name: Validate Gradle Wrapper
if: ${{ env.commit_count_diff > 0 }}
uses: gradle/actions/wrapper-validation@v5
- name: Set up JDK 21
if: ${{ env.commit_count_diff > 0 }}
uses: actions/setup-java@v5
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DISTRO }}
- name: Set up gradle
if: ${{ env.commit_count_diff > 0 }}
uses: gradle/actions/setup-gradle@v5
- name: Build Android Package
if: ${{ env.commit_count_diff > 0 }}
run: |
./gradlew assemblepreview --parallel --no-daemon
- name: Clean up build artifacts
if: ${{ env.commit_count_diff > 0 }}
run: |
cp app/build/outputs/apk/preview/app-universal-preview.apk fga-preview-${{ env.COMMIT_COUNT }}.apk
cp app/build/outputs/apk/preview/app-arm64-v8a-preview.apk fga-preview-arm64-v8a-${{ env.COMMIT_COUNT }}.apk
cp app/build/outputs/apk/preview/app-armeabi-v7a-preview.apk fga-preview-armeabi-v7a-${{ env.COMMIT_COUNT }}.apk
cp app/build/outputs/apk/preview/app-x86_64-preview.apk fga-preview-x86_64-${{ env.COMMIT_COUNT }}.apk
cp app/build/outputs/apk/preview/app-x86-preview.apk fga-preview-x86-${{ env.COMMIT_COUNT }}.apk
- name: Create release on forked repo
uses: softprops/action-gh-release@153bb8e04406b158c6c84fc1615b65b24149a1fe # v2.6.1
if: ${{ env.commit_count_diff > 0 }}
with:
tag_name: pre-${{ env.COMMIT_COUNT }}
name: FGA Preview ${{ env.COMMIT_COUNT }}
repository: ArthurKun21/FGA
body: |
# Preview-${{ env.COMMIT_COUNT }}
Check out our documentation website: https://arthurkun21.github.io/FGA-Preview-Build/
> [!TIP]
> Check out our [CHANGELOG](https://github.com/ArthurKun21/FGA-Preview-Build/blob/main/CHANGELOG.md) for some of the past releases.
> [!TIP]
>
> If you are unsure which version to download then go with `fga-preview-${{ env.COMMIT_COUNT }}.apk`
files: |
fga-preview-${{ env.COMMIT_COUNT }}.apk
fga-preview-arm64-v8a-${{ env.COMMIT_COUNT }}.apk
fga-preview-armeabi-v7a-${{ env.COMMIT_COUNT }}.apk
fga-preview-x86_64-${{ env.COMMIT_COUNT }}.apk
fga-preview-x86-${{ env.COMMIT_COUNT }}.apk
prerelease: false
draft: false
token: ${{ secrets.RELEASE_ON_ANOTHER_REPO }}
- name: Create release
uses: softprops/action-gh-release@153bb8e04406b158c6c84fc1615b65b24149a1fe # v2.6.1
if: ${{ env.commit_count_diff > 0 }}
with:
tag_name: pre-${{ env.COMMIT_COUNT }}
name: FGA Preview ${{ env.COMMIT_COUNT }}
body: |
# Pre-${{ env.COMMIT_COUNT }}
Check out our documentation website: https://arthurkun21.github.io/FGA-Preview-Build/
> [!TIP]
> Check out our [CHANGELOG](https://github.com/ArthurKun21/FGA-Preview-Build/blob/main/CHANGELOG.md) for some of the past releases.
> [!TIP]
>
> If you are unsure which version to download then go with `fga-preview-${{ env.COMMIT_COUNT }}.apk`
files: |
fga-preview-${{ env.COMMIT_COUNT }}.apk
fga-preview-arm64-v8a-${{ env.COMMIT_COUNT }}.apk
fga-preview-armeabi-v7a-${{ env.COMMIT_COUNT }}.apk
fga-preview-x86_64-${{ env.COMMIT_COUNT }}.apk
fga-preview-x86-${{ env.COMMIT_COUNT }}.apk
prerelease: false
draft: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# - name: Prune old releases
# uses: dev-drprasad/delete-older-releases@dfbe6be2a006e9475dfcbe5b8d201f1824c2a9fe # v0.3.4
# if: ${{ env.commit_count_diff > 0 }}
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# keep_latest: 28
# delete_tags: true
changelog:
runs-on: macos-latest
needs: build-app
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Update CHANGELOG.md
if: ${{ needs.build-app.outputs.CREATE_RELEASE == 'true' }}
run: |
git switch -c update-release-${{ needs.build-app.outputs.COMMIT_COUNT_OUTPUT }}
echo -e "${{ needs.build-app.outputs.CHANGELOG }}\n\n$(cat CHANGELOG.md)" > CHANGELOG.md
git config --global user.name 'github-actions[bot]'
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
# Use ISO-8601 format for consistency
CURRENT_DATE_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
# Check if docs/changelog directory exists, create if not
mkdir -p docs/changelog
if ! touch docs/changelog/pre-${{ needs.build-app.outputs.COMMIT_COUNT_OUTPUT }}.md; then
echo "Failed to create changelog file. Please check directory permissions or existence."
exit 1
fi
echo -e "${{ needs.build-app.outputs.CHANGELOG }}" > docs/changelog/pre-${{ needs.build-app.outputs.COMMIT_COUNT_OUTPUT }}.md
git add CHANGELOG.md docs/changelog/pre-${{ needs.build-app.outputs.COMMIT_COUNT_OUTPUT }}.md
git commit -m "Update CHANGELOG.md @ ${CURRENT_DATE_TIME}"
git push -u origin update-release-${{ needs.build-app.outputs.COMMIT_COUNT_OUTPUT }}
- name: Create pull request
if: ${{ needs.build-app.outputs.CREATE_RELEASE == 'true' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pr_title="Release pre-${{ needs.build-app.outputs.COMMIT_COUNT_OUTPUT }}"
pr_body="This PR creates a draft release for version pre-${{ needs.build-app.outputs.COMMIT_COUNT_OUTPUT }}."
pr_branch="update-release-${{ needs.build-app.outputs.COMMIT_COUNT_OUTPUT }}"
if ! gh pr create --head "${pr_branch}" --title "${pr_title}" --body "${pr_body}" --label release --draft; then
echo "Failed to create pull request. Please check branch existence, authentication, or network connectivity."
exit 1
fi