build app #43
This file contains 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: build app | |
on: | |
# Every Saturday at 21:00 UTC | |
schedule: | |
- cron: '0 21 * * 6' | |
# Manual triggers | |
workflow_dispatch: | |
env: | |
JAVA_VERSION: 17 | |
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 }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
repository: 'ArthurKun21/FGA-Preview' | |
token: ${{ secrets.PAT }} | |
- name: Get previous release | |
id: last_release | |
uses: InsonusK/get-latest-release@7a9ff16c8c6b7ead5d71c0f1cc61f2703170eade # v1.1.0 | |
with: | |
myToken: ${{ github.token }} | |
exclude_types: "draft|prerelease" | |
view_top: 1 | |
- name: Prepare build | |
run: | | |
commit_count=$(git rev-list --count HEAD) | |
echo "COMMIT_COUNT=$commit_count" >> $GITHUB_ENV | |
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 "${{ steps.last_release.outputs.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") | |
COMPARISON_LINK="https://github.com/ArthurKun21/fga-preview/compare/${PREV_RELEASE_SHA}...${CURRENT_SHA}" | |
CHANGELOG="\n## $CURRENT_DATE\n${COMMIT_LOGS}\n\n[Compare changes]($COMPARISON_LINK)\n" | |
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@v4 | |
- name: Set up JDK 17 | |
if: ${{ env.commit_count_diff > 0 }} | |
uses: actions/setup-java@v4 | |
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@v4 | |
- name: Build Android Package | |
if: ${{ env.commit_count_diff > 0 }} | |
run: | | |
./gradlew assemblepreview --scan --parallel --no-daemon | |
- name: Clean up build artifacts | |
if: ${{ env.commit_count_diff > 0 }} | |
run: | | |
cp app/build/outputs/apk/preview/app-preview.apk fga-preview-${{ env.COMMIT_COUNT }}.apk | |
sha=`shasum -a 256 fga-preview-${{ env.COMMIT_COUNT }}.apk | awk '{ print $1 }'` | |
echo "APK_UNIVERSAL_SHA=$sha" >> $GITHUB_ENV | |
- name: Create release | |
uses: softprops/action-gh-release@01570a1f39cb168c169c802c3bceb9e93fb10974 # v2.1.0 | |
if: ${{ env.commit_count_diff > 0 }} | |
with: | |
tag_name: pre-${{ env.COMMIT_COUNT }} | |
name: FGA Preview ${{ env.COMMIT_COUNT }} | |
body: | | |
### Commits | |
https://github.com/ArthurKun21/fga-preview/compare/${{ env.PREV_RELEASE_SHA }}...${{ env.CURRENT_SHA }} | |
${{ env.COMMIT_LOGS }} | |
--- | |
### Checksums | |
| Variant | SHA-256 | | |
| ------- | ------- | | |
| Universal APK | ${{ env.APK_UNIVERSAL_SHA }} | | |
files: | | |
fga-preview-${{ env.COMMIT_COUNT }}.apk | |
prerelease: false | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
changelog: | |
runs-on: macos-latest | |
needs: build-app | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Update CHANGELOG.md | |
if: ${{ needs.build-app.outputs.CREATE_RELEASE == 'true' }} | |
run: | | |
echo -e "${{ needs.build-app.outputs.CHANGELOG }}" >> 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") | |
git add CHANGELOG.md | |
git commit -m "Update CHANGELOG.md @ ${CURRENT_DATE_TIME}" | |
git push |