beta @ 52e1c2616282bc529b58a6f055c6f7438c933c99 #65
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 All | |
run-name: ${{ inputs.release_type }} @ ${{ github.sha }} | |
permissions: | |
contents: write | |
concurrency: ${{ github.ref }} | |
on: | |
workflow_dispatch: | |
inputs: | |
release_type: | |
description: Release type | |
default: beta | |
type: choice | |
options: | |
- beta | |
- prod | |
build_foss: | |
description: Build FOSS | |
type: boolean | |
default: true | |
publish: | |
description: Publish in Google Play | |
type: boolean | |
default: true | |
changelog_1: | |
description: Changelog line 1 | |
changelog_2: | |
description: Changelog line 2 | |
changelog_3: | |
description: Changelog line 3 | |
changelog_4: | |
description: Changelog line 4 | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.PA_TOKEN }} | |
fetch-depth: 0 | |
- name: Setup Java | |
uses: actions/setup-java@v3 | |
with: | |
distribution: temurin | |
java-version: 18 | |
- name: Install dependencies | |
run: | | |
sudo apt-get update -y | |
sudo apt-get install -y optipng | |
sudo pip install -r resources/utilities/requirements.txt | |
- name: Restore configs from secrets | |
run: | | |
echo "LICENSE_KEY=${{ secrets.LICENSE_KEY }}" > local.properties | |
- name: Bump version | |
run: | | |
python - << EOF >> $GITHUB_ENV | |
import re | |
target = 'app/build.gradle' | |
regexp_version_code = re.compile('versionCode (\d+)') | |
regexp_version_name = re.compile('versionName "((\d+\.\d+\.\d+)(-beta(\d+))?)"') | |
is_beta = 'true' if '${{ inputs.release_type }}' == 'beta' else 'false' | |
with open(target, 'r+') as file: | |
content = file.read() | |
latest_version = re.search(regexp_version_name, content) | |
full_version = latest_version.group(1) | |
base_version = latest_version.group(2) | |
beta_version = str(int(latest_version.group(4) if latest_version.group(4) else '-1') + 1) | |
build_number = str(int(re.search(regexp_version_code, content).group(1)[-3:]) + 1) | |
if '${{ inputs.release_type }}' == 'prod': | |
if not 'beta' in full_version: | |
base_version = list(map(int, base_version.split('.'))) | |
base_version[2] += 1 | |
for n in range(2): | |
if base_version[2-n] > 9: | |
base_version[2-n] = 0 | |
base_version[1-n] += 1 | |
new_version = '.'.join(str(x) for x in base_version) | |
build_number = '0' | |
else: | |
new_version = base_version | |
version_code = new_version.replace('.', '') + build_number.rjust(3, '0') | |
version_name = new_version | |
else: | |
base_version = list(map(int, base_version.split('.'))) | |
if not 'beta' in full_version: | |
build_number = '0' | |
base_version[2] += 1 | |
for n in range(2): | |
if base_version[2-n] > 9: | |
base_version[2-n] = 0 | |
base_version[1-n] += 1 | |
new_version = '.'.join(str(x) for x in base_version) | |
version_code = new_version.replace('.', '') + build_number.rjust(3, '0') | |
version_name = new_version + '-beta' + beta_version | |
content = re.sub(regexp_version_code, f'versionCode {version_code}', content) | |
content = re.sub(regexp_version_name, f'versionName "{version_name}"', content) | |
file.seek(0) | |
file.write(content) | |
file.truncate() | |
print(f'is_beta={is_beta}') | |
print(f'filename=delta-v{version_name}') | |
print(f'version=v{version_name}') | |
print(f'version_code={version_code}') | |
print(f'version_name={version_name}') | |
EOF | |
- name: Add new icons | |
run: | | |
python -u resources/utilities/add_icons_wrapper.py | |
- name: Create a changelog and set custom icons count | |
run: | | |
mkdir changelog | |
changelog_txt=metadata/en-US/changelogs/${{ env.version_code }}.txt | |
changelog_tmp=changelog/whatsnew-en-US | |
changelog_xml=app/src/main/res/values/changelog.xml | |
drawable_xml=app/src/main/res/xml/drawable.xml | |
drawable_lines=$(grep '<item' $drawable_xml | sort) | |
summary=$(echo "$drawable_lines" | wc -l) | |
amount_all=$(echo "$drawable_lines" | uniq | wc -l) | |
amount_new=$(( $summary - $amount_all )) | |
candybar_play=app/src/play/java/website/leifs/delta/applications/CandyBar.java | |
candybar_foss=app/src/foss/java/website/leifs/delta/applications/CandyBar.java | |
sed -i "s|setCustomIconsCount\(.*\);|setCustomIconsCount\($amount_all\);|" $candybar_play | |
sed -i "s|setCustomIconsCount\(.*\);|setCustomIconsCount\($amount_all\);|" $candybar_foss | |
changelog_1='${{ inputs.changelog_1 }}' | |
changelog_2='${{ inputs.changelog_2 }}' | |
changelog_3='${{ inputs.changelog_3 }}' | |
changelog_4='${{ inputs.changelog_4 }}' | |
echo "- $amount_new new icons, $amount_all in total" > $changelog_txt | |
cat << EOF > $changelog_xml | |
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<string name="changelog_date"></string> | |
<string-array name="changelog"> | |
<item><![CDATA[<font color=#ff837d>$amount_new</font> new icons, <font color=#ff837d>$amount_all</font> in total]]></item> | |
EOF | |
if [[ '${{ inputs.release_type }}' == 'prod' ]]; then | |
echo "- Fixed icons not applying properly" >> $changelog_txt | |
echo " <item>Fixed icons not applying properly</item>" >> $changelog_xml | |
for n in $(seq 1 4); do | |
changelog="changelog_${n}" | |
if [ ! -z "${!changelog}" ]; then | |
echo "- ${!changelog}" >> $changelog_txt | |
echo " <item>${!changelog}</item>" >> $changelog_xml | |
fi | |
done | |
fi | |
if [[ '${{ inputs.release_type }}' == 'beta' ]]; then | |
message="Full changelog will be published upon release!" | |
echo "- $message" >> $changelog_txt | |
echo " <item>$message</item>" >> $changelog_xml | |
fi | |
cat << EOF >> $changelog_xml | |
</string-array> | |
</resources> | |
EOF | |
cp $changelog_txt $changelog_tmp | |
cat $changelog_xml | |
echo "changelog=$changelog_tmp" >> $GITHUB_ENV | |
- name: Optimize PNGs | |
continue-on-error: true | |
run: | | |
latest_tag=$(git tag --sort version:refname | grep -v "beta" | tail -n 1) | |
echo "Latest tag is $latest_tag" | |
if [[ $latest_tag ]]; then | |
echo "Optimizing PNGs since last release" | |
optipng $(git diff --name-only $latest_tag -- "***.png") | |
else | |
echo 'No release found, skip optimizing' | |
fi | |
- name: Sort drawables | |
run: | | |
python resources/utilities/sort_drawable.py app/src/main/assets/drawable.xml | |
cp -v new_drawable.xml app/src/main/assets/drawable.xml | |
cp -v new_drawable.xml app/src/main/res/xml/drawable.xml | |
- name: Build APK | |
run: bash gradlew assemblePlay | |
- name: Build AAB | |
if: inputs.publish == true | |
run: bash gradlew bundlePlay | |
- name: Build APK FOSS | |
if: inputs.build_foss == true | |
run: bash gradlew assembleFoss | |
- name: Move unsigned builds | |
run: | | |
mv -v app/build/outputs/apk/play/release/*.apk delta-play.apk | |
if [[ ${{ inputs.build_foss }} == true ]]; then | |
mv -v app/build/outputs/apk/foss/release/*.apk delta-foss.apk | |
fi | |
if [[ ${{ inputs.publish }} == true ]]; then | |
mv -v app/build/outputs/bundle/playRelease/*.aab delta-play.aab | |
fi | |
- name: Sign builds | |
uses: kevin-david/[email protected] | |
with: | |
releaseDirectory: . | |
signingKeyBase64: ${{ secrets.KEYSTORE_BASE64 }} | |
keyStorePassword: ${{ secrets.KEYSTORE_PASSWORD }} | |
keyPassword: ${{ secrets.KEYSTORE_KEY_PASSWORD }} | |
alias: ${{ secrets.KEYSTORE_KEY_ALIAS }} | |
- name: Rename signed builds | |
run: | | |
mv -v delta-play-signed.apk ${{ env.filename }}.apk | |
if [[ ${{ inputs.build_foss }} == true ]]; then | |
mv -v delta-foss-signed.apk ${{ env.filename }}-foss.apk | |
fi | |
if [[ ${{ inputs.publish }} == true ]]; then | |
mv -v delta-play.aab ${{ env.filename }}.aab | |
fi | |
- name: Upload APK to Artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.filename }} | |
path: ${{ env.filename }}.apk | |
retention-days: 90 | |
- name: Upload APK FOSS to Artifacts | |
uses: actions/upload-artifact@v3 | |
if: inputs.build_foss == true | |
with: | |
name: ${{ env.filename }}-foss | |
path: ${{ env.filename }}-foss.apk | |
retention-days: 90 | |
- name: Upload AAB to Google Play beta channel | |
uses: r0adkll/[email protected] | |
if: inputs.publish == true | |
with: | |
track: beta | |
status: completed | |
releaseFiles: ${{ env.filename }}.aab | |
serviceAccountJsonPlainText: ${{ secrets.SERVICE_ACCOUNT }} | |
packageName: ${{ vars.PACKAGE_NAME }} | |
mappingFile: app/build/outputs/mapping/playRelease/mapping.txt | |
whatsNewDirectory: changelog | |
inAppUpdatePriority: 5 | |
- name: Promote beta build to production channel | |
uses: kevin-david/[email protected] | |
if: ${{ (inputs.release_type == 'prod') && (inputs.publish == true) }} | |
with: | |
service-account-json-raw: ${{ secrets.SERVICE_ACCOUNT }} | |
package-name: ${{ vars.PACKAGE_NAME }} | |
inapp-update-priority: 5 | |
user-fraction: 1.0 | |
- name: Commit pre-release changes | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
commit_message: 'New ${{ inputs.release_type }} release: ${{ env.version }}' | |
file_pattern: 'app/build.gradle app/src/main/* app/src/foss/* app/src/play/* metadata resources/' | |
- name: Create a GitHub release | |
uses: softprops/[email protected] | |
with: | |
prerelease: ${{ env.is_beta }} | |
files: '${{ env.filename }}*.apk' | |
name: ${{ env.version }} | |
tag_name: ${{ env.version }} | |
body_path: ${{ env.changelog }} | |
- name: Clear category 'New' | |
if: inputs.release_type == 'prod' | |
run: | | |
sed -i '7,/^$/c\\' new_drawable.xml | |
cp -v new_drawable.xml app/src/main/assets/drawable.xml | |
cp -v new_drawable.xml app/src/main/res/xml/drawable.xml | |
- name: Commit post-release changes | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
if: inputs.release_type == 'prod' | |
with: | |
commit_message: 'Post-release cleanup' | |
file_pattern: 'app/src/main/*' | |
- name: Update the website | |
uses: benc-uk/workflow-dispatch@v1 | |
with: | |
workflow: deploy.yml | |
repo: ${{ github.repository_owner }}/delta-icons.github.io | |
token: ${{ secrets.PA_TOKEN }} |