Sync + Trigger Build+Release Infinity-For-Reddit #483
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: Sync + Trigger Build+Release Infinity-For-Reddit | |
# Controls when the workflow will run | |
on: | |
schedule: | |
# * is a special character in YAML so you have to quote this string | |
- cron: '0 0 * * *' | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
jobs: | |
get_version: | |
runs-on: ubuntu-latest | |
# https://lannonbr.com/blog/2020-04-16-gh-actions-job-outputs | |
outputs: | |
REMOTE: ${{ steps.commits.outputs.SETREMOTE }} | |
LOCAL: ${{ steps.commits.outputs.SETLOCAL }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
repository: 'schklom/Infinity-For-Reddit' | |
ref: 'master' # branch | |
- name: set local and remote latest version as environment variables | |
id: commits | |
# https://lannonbr.com/blog/2020-04-16-gh-actions-job-outputs | |
# https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs | |
run: | | |
echo "SETREMOTE=$(git ls-remote --tags https://github.com/Docile-Alligator/Infinity-For-Reddit.git | grep -v 'beta' | tail -n 1 | awk '{ print $2 }' | cut -d '/' -f 3)" >> $GITHUB_OUTPUT | |
echo "SETLOCAL=$(cat last_sync_with_original_repo_version)" >> $GITHUB_OUTPUT | |
repo_sync_master: | |
needs: [get_version] | |
runs-on: ubuntu-latest | |
# https://lannonbr.com/blog/2020-04-16-gh-actions-job-outputs | |
if: needs.get_version.outputs.LOCAL != needs.get_version.outputs.REMOTE | |
steps: | |
- name: outputs | |
run: | | |
echo "${{ needs.get_version.outputs.LOCAL }}" | |
echo "${{ needs.get_version.outputs.REMOTE }}" | |
- name: repo-sync master branch | |
uses: wei/git-sync@v3 | |
with: | |
source_repo: "https://github.com/Docile-Alligator/Infinity-For-Reddit.git" | |
source_branch: "refs/remotes/source/*" | |
#source_branch: "master" | |
####destination_repo: "[email protected]:schklom/Mirror-workflows.git" | |
destination_repo: "[email protected]:schklom/Infinity-For-Reddit.git" | |
####destination_branch: "Gadgetbridge-osmand-experiments" | |
destination_branch: "refs/heads/*" | |
#source_branch: "refs/tags/*" | |
#destination_branch: "refs/tags/*" | |
destination_ssh_private_key: ${{ secrets.GITSYNCACTION }} | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
repository: 'schklom/Infinity-For-Reddit' | |
ref: 'master' # branch | |
token: ${{ secrets.PAT_GITHUB_ACTION }} | |
- name: Remove HEAD branch from schklom/tt-rss-android if it exists | |
run: | | |
# Configure Git to use the PAT for authentication | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git remote add foreign-repo https://github.com/schklom/Infinity-For-Reddit.git | |
# Fetch the latest branches from the foreign repository | |
git fetch foreign-repo | |
# Check if the HEAD branch exists in the foreign repository and delete it if it does | |
if git show-ref --verify --quiet refs/remotes/foreign-repo/HEAD; then | |
git push foreign-repo --delete HEAD | |
else | |
echo "HEAD branch does not exist in the foreign repository. No action required." | |
fi | |
- name: get most recent version on original repo, for next comparison on sync | |
run: git ls-remote --tags https://github.com/Docile-Alligator/Infinity-For-Reddit.git | grep -v 'beta' | tail -n 1 | awk '{ print $2 }' | cut -d '/' -f 3 > last_sync_with_original_repo_version | |
# Inspired by https://www.reddit.com/r/Infinity_For_Reddit/comments/14c2v5x/build_your_own_apk_with_your_personal_api_key_in/ | |
# which links specifically to https://colab.research.google.com/drive/13AE8RvjnCfuBJGaACEqxeBIMo33_l-Sc | |
- name: Changes for personal API key | |
run: | | |
api_token=${{ secrets.INFINITY_FOR_REDDIT_API_KEY }} | |
redirect_uri="http://127.0.0.1" | |
reddit_username=${{ secrets.REDDIT_USERNAME }} | |
user_agent="android:personal-app:0.0.1 (by /u/$reddit_username)" | |
# https://github.com/Docile-Alligator/Infinity-For-Reddit/issues/1648#issuecomment-2140935760 | |
# remove android from user-agent | |
user_agent="personal-app:0.0.1 (by /u/$reddit_username)" | |
# Change some code for user_agent and api key | |
file="app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java" | |
sed -i "s|NOe2iKrPPzwscA|$api_token|" $file | |
# the redirect URI seems to cause problems | |
sed -i "s|infinity://localhost|$redirect_uri|" $file | |
# use double quotes to use bash variable inside sed, then escape double quotes inside via \" | |
sed -ir "s|public static final String USER_AGENT = \".*?\";|public static final String USER_AGENT = \"$user_agent\";|" $file | |
- name: Changes to sign the APKs | |
run: | | |
## DISABLED BECAUSE I SIGN IT IN THE WORKFLOW DEFINED BELOW | |
## Add Keystore | |
#file="app/build.gradle" | |
#wget "https://github.com/TanukiAI/Infinity-keystore/raw/main/Infinity.jks" | |
## multi-line insert before match " signingConfigs {" (add one space after "i" | |
## This feels dirty, if someone knows how to do it better please tell me | |
## Need to backslash the first delimeter since I don't use "s" | |
## Need to escape the first space after "i" then sed escapes the others | |
#sed -i '\| buildTypes {|i\ signingConfigs {\n release {\n storeFile file("/Infinity.jks")\n storePassword "Infinity"\n keyAlias "Infinity"\n keyPassword "Infinity"\n }\n }' $file | |
# Try the same with a heredoc? | |
#where_to_add=" buildTypes {" | |
#what_to_add=" signingConfigs { | |
# release { | |
# storeFile file("/Infinity.jks") | |
# storePassword "Infinity" | |
# keyAlias "Infinity" | |
# keyPassword "Infinity" | |
# } | |
#}" | |
#sed -i "\|$where_to_add|r"<(echo "$what_to_add") $file | |
# Sign the APKs | |
# Need to escape the dollar double bracket | |
file=".github/workflows/build.yml" | |
what_to_add=" | |
- name: Sign APK | |
id: sign_apk | |
uses: ilharp/sign-android-release@v1 | |
with: | |
releaseDir: app/build/outputs/apk/ | |
signingKey: ${{ '\${{ secrets.APK_KEYSTORE_FILE_BASE64 }}' }} | |
keyAlias: ${{ '\${{ secrets.APK_KEYSTORE_ALIAS }}' }} | |
keyStorePassword: ${{ '\${{ secrets.APK_KEYSTORE_PASSWORD }}' }} | |
keyPassword: ${{ '\${{ secrets.APK_KEYSTORE_PASSWORD }}' }} | |
" | |
where_to_add="arguments: build -x lint" | |
sed -i "\|$where_to_add|r"<(echo "$what_to_add") $file | |
- name: Changes to release the APKs | |
run: | | |
# Add the release of the artifact at the end of the build action | |
# Need to escape the dollar double bracket | |
# https://github.com/orgs/community/discussions/26621#discussioncomment-3840420 | |
## The script says it should be app/build/outputs/apk/release/app-release-unsigned.apk | |
## But I can't install it, so I switch to app/build/outputs/apk/debug/app-debug.apk | |
file=".github/workflows/build.yml" | |
echo "" >> $file | |
echo " - name: Release Infinity-For-Reddit APK ${{ needs.get_version.outputs.REMOTE }}" >> $file | |
echo " uses: softprops/action-gh-release@v1" >> $file | |
echo " with:" >> $file | |
echo " tag_name: \"${{ needs.get_version.outputs.REMOTE }}\"" >> $file | |
echo " body: New version of Infinity-For-Reddit" >> $file | |
# OLD | |
#echo " files: app/build/outputs/apk/debug/app-debug.apk" >> $file | |
# NEW | |
echo " files: |" >> $file | |
echo " app/build/outputs/apk/release/app-release-unsigned-signed.apk" >> $file | |
echo " app/build/outputs/apk/minifiedRelease/app-minifiedRelease-unsigned-signed.apk" >> $file | |
echo " app/build/outputs/apk/debug/app-debug-signed.apk" >> $file | |
echo " repository: schklom/Infinity-For-Reddit" >> $file | |
echo " token: ${{ '\${{ secrets.PAT_GITHUB_ACTION }}' }}" >> $file | |
- name: Remove pointless workflow | |
run: rm .github/workflows/codeql* | |
# Reuse app build workflow | |
# https://github.blog/2022-02-10-using-reusable-workflows-github-actions/ | |
# Not reusable workflow, because it preloads before modifications | |
# Instead, we trigger a push if there was a change, because "push" is a trigger for the build | |
- name: Commit and push the change | |
uses: stefanzweifel/git-auto-commit-action@v5 | |
with: | |
commit_message: Add Change API key + change User-Agent + Keystore + remove codeql workflow + Add last_sync_with_original_repo_version | |
# fix_for_workflow: | |
# needs: [repo_sync_master] | |
# runs-on: ubuntu-latest | |
# outputs: | |
# CHANGESONBUILDYML: ${{ steps.changes.outputs.SETCHANGESONBUILDYML }} | |
# steps: | |
# - name: Checkout main repo to fix a reusable workflow bug | |
# uses: actions/checkout@v4 | |
# with: | |
# repository: 'schklom/Mirror-workflows' | |
# ref: 'main' # branch | |
# token: ${{ secrets.PAT_GITHUB_ACTION }} | |
# | |
# - name: Copy modified workflow | |
# run: | | |
# url="https://raw.githubusercontent.com/schklom/Infinity-For-Reddit/master/.github/workflows/build.yml" | |
# file="Infinity-For-RedditCustomBuild-auto-updated.yml" | |
# curl "$url" -o ".github/workflows/$file" | |
# | |
# - name: Commit and push the change (modified workflow) | |
# uses: stefanzweifel/git-auto-commit-action@v5 | |
# id: auto-commit-action | |
# with: | |
# commit_message: Copy modified workflow | |
# | |
# - name: Changes on build.yml? | |
# id: changes | |
# run: | | |
# echo "${{ steps.auto-commit-action.outputs.changes_detected }}" | |
# echo "SETCHANGESONBUILDYML=${{ steps.auto-commit-action.outputs.changes_detected }}" >> $GITHUB_OUTPUT | |
# | |
# build_tomorrow: | |
# needs: [fix_for_workflow] | |
# runs-on: ubuntu-latest | |
# steps: | |
# - name: There was a change on build.yml, so we build tomorrow no matter what | |
# if: ${{ needs.get_version.outputs.LOCAL} } == 'true' | |
# run: echo "1" > there-was-a-change-on-build-yml-yesterday | |
#build_from_workflow: | |
# if: false | |
#needs: [fix_for_workflow] | |
# Cannot use, so I made a local branch to store the Action | |
#uses: schklom/Infinity-For-Reddit/.github/workflows/build.yml@master | |
#uses: ./.github/workflows/Infinity-For-RedditCustomBuildautoupdated.yml | |
# publish_infinity_on_master: | |
# # needs: [build_from_workflow] | |
# runs-on: ubuntu-latest | |
# #if: false | |
# steps: | |
# - name: Checkout | |
# uses: actions/checkout@v4 | |
# with: | |
# repository: 'schklom/Infinity-For-Reddit' | |
# ref: 'master' # branch | |
# token: ${{ secrets.PAT_GITHUB_ACTION }} | |
# | |
# - name: Set the version | |
# run: | | |
# ver=$(cat last_sync_with_original_repo_version) | |
# echo "version=${ver}" >> $GITHUB_ENV | |
# | |
# - name: Rename apk file | |
# run: mv app/build/outputs/apk/release/app*.apk ./Infinity.apk | |
# | |
# - name: Release apk | |
# uses: softprops/action-gh-release@v1 | |
# with: | |
# tag_name: "${{ env.version }}" | |
# body: "Infinity.apk is the Infinity file" | |
# #files: | | |
# # ./app/build/outputs/apk/app-debug.apk | |
# #files: ./app/build/outputs/apk/main/release/app-main-release-unsigned.apk | |
# #files: ./app/build/outputs/apk/main/debug/app-main-debug.apk | |
# files: ./Infinity.apk | |
# repository: "schklom/Infinity-For-Reddit" | |
# token: ${{ secrets.PAT_GITHUB_ACTION }} |