Checkout & Build App #109
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: Checkout & Build App | |
on: | |
schedule: | |
- cron: '0 0 * * *' | |
workflow_dispatch: | |
jobs: | |
check: | |
runs-on: ubuntu-22.04 | |
outputs: | |
should_build: ${{ steps.check-updates.outputs.has_changes }} | |
steps: | |
- name: Check for updates π | |
id: check-updates | |
run: | | |
last_run=$(curl -s "https://api.github.com/repos/${{ github.repository }}/actions/workflows/build.yml/runs?status=completed&per_page=1" | jq -r '.workflow_runs[0].created_at') | |
kotatsu_updated=$(curl -s "https://api.github.com/repos/KotatsuApp/Kotatsu/commits?since=$last_run" | jq '. | length') | |
parsers_updated=$(curl -s "https://api.github.com/repos/KotatsuApp/kotatsu-parsers/commits?since=$last_run" | jq '. | length') | |
if [ "$kotatsu_updated" -gt "0" ] || [ "$parsers_updated" -gt "0" ]; then | |
echo "has_changes=true" >> $GITHUB_OUTPUT | |
else | |
echo "has_changes=false" >> $GITHUB_OUTPUT | |
fi | |
build: | |
needs: check | |
if: needs.check.outputs.should_build == 'true' | |
runs-on: ubuntu-22.04 | |
outputs: | |
new_tag: ${{ steps.tagger.outputs.new_tag }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: base | |
- uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: '17' | |
cache: 'gradle' | |
- name: Setup Android SDK π» | |
uses: android-actions/setup-android@v3 | |
with: | |
android_sdk_version: '35.0.0' | |
android_build_tools_version: '35.0.0' | |
- name: Pull upstream π | |
run: | | |
git remote add upstream https://github.com/KotatsuApp/Kotatsu-Nightly.git | |
git fetch upstream base | |
git reset --hard upstream/base | |
- name: Grant permissions π» | |
run: chmod a+x gradlew | |
- name: Generate build number π | |
id: tagger | |
run: | | |
echo "new_tag=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT | |
echo "formatted_date=$(date +'%Y/%m/%d')" >> $GITHUB_OUTPUT | |
- name: Building new APK π» | |
run: >- | |
./gradlew assembleNightly | |
-DparsersVersionOverride=$(curl -s https://api.github.com/repos/kotatsuapp/kotatsu-parsers/commits/master -H "Accept: application/vnd.github.sha" | cut -c -10) | |
- name: Packaging new APK π» | |
uses: ilharp/sign-android-release@v1 | |
id: sign_app | |
with: | |
releaseDir: app/build/outputs/apk/nightly | |
signingKey: ${{ secrets.ANDROID_SIGNING_KEY }} | |
keyAlias: ${{ secrets.ANDROID_KEY_ALIAS }} | |
keyStorePassword: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }} | |
keyPassword: ${{ secrets.ANDROID_KEY_PASSWORD }} | |
buildToolsVersion: 35.0.0 | |
- name: Prepare to Upload π | |
run: | | |
mv ${{steps.sign_app.outputs.signedFile}} app/build/outputs/apk/nightly/release.apk | |
echo "SIGNED_APK=app/build/outputs/apk/nightly/release.apk" >> $GITHUB_ENV | |
- name: Get latest changes π | |
id: changelog | |
run: | | |
CHANGELOG=$(cat CHANGELOG.txt) | |
echo "content<<EOF" >> $GITHUB_OUTPUT | |
echo "$CHANGELOG" >> $GITHUB_OUTPUT | |
echo "EOF" >> $GITHUB_OUTPUT | |
- name: Create new GH Release + Uploading π | |
uses: softprops/action-gh-release@v2 | |
with: | |
tag_name: nightly-${{ steps.tagger.outputs.new_tag }} | |
name: "Nightly Build ${{ steps.tagger.outputs.new_tag }}" | |
body: | | |
Automated nightly build generated on ${{ steps.tagger.outputs.formatted_date }} | |
${{ steps.changelog.outputs.content }} | |
files: ${{ env.SIGNED_APK }} | |
prerelease: false | |
update: | |
needs: build | |
if: needs.check.outputs.should_build == 'true' | |
runs-on: ubuntu-22.04 | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: nightly | |
fetch-depth: 0 | |
- name: Update Build Number π | |
run: | | |
VERSION_NUMBER="${{ needs.build.outputs.new_tag }}" | |
COUNTER_LINKS="" | |
for (( i=0; i<${#VERSION_NUMBER}; i++ )); do | |
DIGIT="${VERSION_NUMBER:$i:1}" | |
COUNTER_LINKS+="[![Download](https://rule34.xxx/counter/$DIGIT.gif)](https://github.com/KotatsuApp/kotatsu-nightly/releases/latest) " | |
done | |
sed -i "/### <img src=\".\/.github\/app_icon.png\" alt=\"Kotatsu Logo\" width=\"16\" style=\"vertical-align: bottom;\"\/> Download <img src=\".\/.github\/app_icon.png\" alt=\"Kotatsu Logo\" width=\"16\" style=\"vertical-align: bottom;\"\/>/,/div>/c\### <img src=\".\/.github\/app_icon.png\" alt=\"Kotatsu Logo\" width=\"16\" style=\"vertical-align: bottom;\"\/> Download <img src=\".\/.github\/app_icon.png\" alt=\"Kotatsu Logo\" width=\"16\" style=\"vertical-align: bottom;\"\/>\n\n${COUNTER_LINKS}\n\n<div align=\"left\">\n\n* Nightly build can be downloaded from the [GitHub Releases](https://github.com/KotatsuApp/Kotatsu-Nightly/releases). Application has a built-in self-updating feature.\n* If you want to download a stable Kotatsu release please refer to the [main Kotatsu repository](https://github.com/KotatsuApp/Kotatsu?tab=readme-ov-file#download).\n\n</div>" README.md | |
- name: Update Docs + Commit π | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "Koitharu" | |
if [[ -n $(git status -s) ]]; then | |
git add README.md | |
git commit -m "Bump build number to ${{ needs.build.outputs.new_tag }}" | |
git push origin nightly | |
else | |
echo "No changes to push!" | |
fi |