Update #156
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: Update | |
on: | |
schedule: | |
- cron: '35 0 * * *' | |
workflow_dispatch: | |
inputs: | |
force_update: | |
type: boolean | |
description: 'Force update/build' | |
default: false | |
concurrency: | |
group: ${{ github.workflow }} | |
cancel-in-progress: true | |
permissions: | |
contents: write | |
jobs: | |
update: | |
runs-on: ubuntu-latest | |
outputs: | |
executed_update: ${{ steps.postprocess.outputs.executed_update }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Update | |
id: update | |
run: | | |
set -e | |
declare -a repo_infos=( | |
"org.schabi.newpipe.nightly;github;TeamNewPipe/NewPipe-nightly" | |
"org.schabi.newpipe.refactor.nightly;github;TeamNewPipe/NewPipe-refactor-nightly" | |
) | |
force_update="${{ inputs.force_update }}" | |
if [[ "$force_update" != "true" ]]; then | |
echo "Checking if updates are required..." | |
update_required=false | |
for repo_info in ${repo_infos[@]}; do | |
repo_info_parts=(${repo_info//;/ }) | |
id=${repo_info_parts[0]} | |
provider=${repo_info_parts[1]} | |
repo=${repo_info_parts[2]} | |
echo "Checking if $id needs updating" | |
current_deployed_release=$(cat current-versions/$id.txt || echo "") | |
echo "Currently deployed version is '$current_deployed_release'" | |
latest_version="" | |
if [[ "$provider" == "github" ]]; then | |
latest_release_data=$(curl -L https://api.github.com/repos/$repo/releases/latest) | |
latest_version=$(echo "$latest_release_data" | jq -r '.name') | |
else | |
echo "Unknown provider" | |
exit 1 | |
fi | |
echo "Latest version is '$latest_version'" | |
if [[ "$current_deployed_release" != "$latest_version" ]]; then | |
echo "Update required" | |
update_required=true | |
break | |
fi | |
done | |
if [[ "$update_required" != "true" ]]; then | |
echo "Everything is up-to-date; No update required" | |
exit 0 | |
fi | |
fi | |
echo "Downloading APKs" | |
mkdir -p apks | |
for repo_info in ${repo_infos[@]}; do | |
repo_info_parts=(${repo_info//;/ }) | |
id=${repo_info_parts[0]} | |
provider=${repo_info_parts[1]} | |
repo=${repo_info_parts[2]} | |
echo "Downloading APKs for $id" | |
latest_version="" | |
if [[ "$provider" == "github" ]]; then | |
curl -L https://api.github.com/repos/$repo/releases?per_page=3 \ | |
| jq -r '.[].assets[].browser_download_url' \ | |
| while read -r url; do wget -P apks --no-verbose $url; done | |
latest_release_data=$(curl -L https://api.github.com/repos/$repo/releases/latest) | |
latest_version=$(echo "$latest_release_data" | jq -r '.name') | |
else | |
echo "Unknown provider" | |
exit 1 | |
fi | |
echo "Downloaded APKs. Saving latest version $latest_version" | |
mkdir -p current-versions | |
echo "$latest_version" > current-versions/$id.txt | |
done | |
echo "Deleting non-APK files" | |
(cd apks && find . -type f ! -name '*.apk' -delete) | |
echo "Done" | |
echo "do_update=true" >> "$GITHUB_ENV" | |
ls -lha apks | |
- name: Load KeyStore file | |
if: ${{ env.do_update == 'true' }} | |
run: echo "${{ secrets.KEYSTORE_BASE64 }}" | base64 -d - > repo/keystore.p12 | |
- uses: docker/setup-qemu-action@v3 | |
if: ${{ env.do_update == 'true' }} | |
- uses: docker/setup-buildx-action@v3 | |
if: ${{ env.do_update == 'true' }} | |
- name: Build F-Droid Repo Generator | |
if: ${{ env.do_update == 'true' }} | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./fdroid-repo-generator | |
load: true | |
tags: fdroid-repo-generator | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Write index.html | |
if: ${{ env.do_update == 'true' }} | |
run: | | |
mkdir -p deploy | |
cat <<EOF >> deploy/index.html | |
<html> | |
<head> | |
<meta http-equiv="refresh" content="0; url=fdroid/repo" /> | |
</head> | |
<body> | |
<p><a href="fdroid/repo">Click here if redirect is not working</a></p> | |
</body> | |
</html> | |
EOF | |
- name: Run F-Droid Repo Generator | |
if: ${{ env.do_update == 'true' }} | |
run: | | |
docker run --rm \ | |
-v $(pwd)/apks:/apks \ | |
-v $(pwd)/deploy:/deploy \ | |
-v $(pwd)/repo:/repobase \ | |
-w /repo \ | |
-e REPO_KEYALIAS="${{ secrets.REPO_KEYALIAS }}" \ | |
-e KEYSTOREPASS="${{ secrets.KEYSTOREPASS }}" \ | |
-e KEYPASS="${{ secrets.KEYPASS }}" \ | |
-e KEYDNAME="${{ secrets.KEYDNAME }}" \ | |
fdroid-repo-generator | |
- name: Deploy to Github pages | |
if: ${{ env.do_update == 'true' }} | |
uses: peaceiris/actions-gh-pages@v4 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./deploy | |
force_orphan: true | |
- name: PostProcess | |
id: postprocess | |
if: ${{ env.do_update == 'true' }} | |
run: | | |
echo "Configuring git" | |
git config --global user.email "[email protected]" | |
git config --global user.name "GitHub Actions" | |
echo "Committing changed tracking files" | |
git add -A || true | |
git commit -m "Update versions" && git push || true | |
echo "executed_update=true" >> "$GITHUB_OUTPUT" | |
mirror: | |
runs-on: ubuntu-latest | |
needs: update | |
if: needs.update.outputs.executed_update == 'true' | |
steps: | |
- run: | | |
git clone --bare https://github.com/litetex/fdroid-pages.git --single-branch --branch gh-pages | |
cd fdroid-pages.git | |
echo "Renaming branch" | |
git branch -m gh-pages pages | |
echo "Starting push" | |
git push --mirror https://litetex:${{ secrets.CB_TOKEN }}@codeberg.org/litetex/fdroid-pages.git | |
echo "Done" |