|
| 1 | +# This is a basic workflow to help you get started with Actions |
| 2 | + |
| 3 | +name: Update Deb |
| 4 | + |
| 5 | +# Controls when the workflow will run |
| 6 | +on: |
| 7 | + schedule: |
| 8 | + - cron: '0 0 */2 * *' |
| 9 | + # Allows you to run this workflow manually from the Actions tab |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +jobs: |
| 13 | + update: |
| 14 | + # The type of runner that the job will run on |
| 15 | + runs-on: ubuntu-latest |
| 16 | + env: |
| 17 | + PUSH: 1 |
| 18 | + steps: |
| 19 | + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Import GPG key |
| 23 | + id: import_gpg |
| 24 | + uses: crazy-max/ghaction-import-gpg@v6 |
| 25 | + with: |
| 26 | + gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} |
| 27 | + passphrase: ${{ secrets.PASSPHRASE }} |
| 28 | + - name: GPG user IDs |
| 29 | + run: | |
| 30 | + echo "fingerprint: ${{ steps.import_gpg.outputs.fingerprint }}" |
| 31 | + echo "keyid: ${{ steps.import_gpg.outputs.keyid }}" |
| 32 | + echo "name: ${{ steps.import_gpg.outputs.name }}" |
| 33 | + echo "email: ${{ steps.import_gpg.outputs.email }}" |
| 34 | + # Runs a set of commands using the runners shell |
| 35 | + - name: Install dependencies |
| 36 | + run: | |
| 37 | + sudo apt install reprepro |
| 38 | + - name: Check Update |
| 39 | + run: | |
| 40 | + function update_repo() { |
| 41 | + ver=$(echo "$1" | tr -d 'v' | cut -d "-" -f 1) |
| 42 | + reprepro --basedir "$(pwd)/meta" includedeb stable "./freetube_${ver}_amd64.deb" "./freetube_${ver}_arm64.deb" "./freetube_${ver}_armv7l.deb" |
| 43 | + if [ -d dists ]; then rm -r dists; fi |
| 44 | + if [ -d pool ]; then rm -r pool; fi |
| 45 | + mv meta/dists ./ |
| 46 | + mv meta/pool ./ |
| 47 | + checksum_amd64=$(sha256sum pool/main/f/freetube/freetube_${ver}_amd64.deb) |
| 48 | + checksum_arm64=$(sha256sum pool/main/f/freetube/freetube_${ver}_arm64.deb) |
| 49 | + checksum_armhf=$(sha256sum pool/main/f/freetube/freetube_${ver}_armhf.deb) |
| 50 | + sed -i -E "s,[a-f0-9]{64}[ ]+pool/main/f/freetube/freetube_[0-9]\.[0-9]+\.[0-9]_amd64.deb,$checksum_amd64," README.md |
| 51 | + sed -i -E "s,[a-f0-9]{64}[ ]+pool/main/f/freetube/freetube_[0-9]\.[0-9]+\.[0-9]_arm64.deb,$checksum_arm64," README.md |
| 52 | + sed -i -E "s,[a-f0-9]{64}[ ]+pool/main/f/freetube/freetube_[0-9]\.[0-9]+\.[0-9]_armhf.deb,$checksum_armhf," README.md |
| 53 | + echo "PUSH=0" >> $GITHUB_ENV |
| 54 | + } |
| 55 | + |
| 56 | + function download_update() { |
| 57 | + if [ -f /tmp/verify.log ]; then rm /tmp/verify.log; fi |
| 58 | + ver=$(echo "$1" | tr -d 'v' | cut -d "-" -f 1) |
| 59 | + wget -q "https://github.com/FreeTubeApp/FreeTube/releases/download/$1/freetube_${ver}_amd64.deb" --show-progress |
| 60 | + if [ "$?" -eq "0" ]; then |
| 61 | + echo 'amd64 downloaded' |
| 62 | + wget -q "https://github.com/FreeTubeApp/FreeTube/releases/download/$1/freetube_${ver}_arm64.deb" --show-progress |
| 63 | + if [ "$?" -eq "0" ]; then |
| 64 | + echo 'arm64 downloaded' |
| 65 | + wget -q "https://github.com/FreeTubeApp/FreeTube/releases/download/$1/freetube_${ver}_armv7l.deb" --show-progress |
| 66 | + if [ "$?" -eq "0" ]; then |
| 67 | + echo 'armv7l downloaded' |
| 68 | + echo "$1" > last_update |
| 69 | + return 0 |
| 70 | + fi |
| 71 | + fi |
| 72 | + fi |
| 73 | + return 1 |
| 74 | + } |
| 75 | + |
| 76 | + function compare (){ |
| 77 | + last_ver=$(echo "$1" | tr -d 'v') |
| 78 | + latest_ver=$(echo "$2" | tr -d 'v') |
| 79 | + last_big=$(echo "$last_ver" | cut -d "." -f 1) |
| 80 | + last_medium=$(echo "$last_ver" | cut -d "." -f 2) |
| 81 | + last_small=$(echo "$last_ver" | cut -d "." -f 3 | cut -d "-" -f 1) |
| 82 | + latest_big=$(echo "$latest_ver" | cut -d "." -f 1) |
| 83 | + latest_medium=$(echo "$latest_ver" | cut -d "." -f 2) |
| 84 | + latest_small=$(echo "$latest_ver" | cut -d "." -f 3 | cut -d "-" -f 1) |
| 85 | + if [ "$latest_big" -gt "$last_big" ]; then |
| 86 | + return 0 |
| 87 | + else |
| 88 | + if [ "$latest_medium" -gt "$last_medium" ]; then |
| 89 | + return 0 |
| 90 | + else |
| 91 | + if [ "$latest_small" -gt "$last_small" ]; then |
| 92 | + return 0 |
| 93 | + fi |
| 94 | + fi |
| 95 | + fi |
| 96 | + return 1 |
| 97 | + } |
| 98 | + |
| 99 | + echo 'Checking update...' |
| 100 | + releases=$(wget -qO- https://freetubeapp.io/#download | grep -o 'https://github.com/FreeTubeApp/FreeTube/releases/download/.*/freetube_.*_amd64.deb') |
| 101 | + latest=$(echo "$releases" | egrep -o 'v[0-9]\.[0-9]+\.[0-9](-beta)?') |
| 102 | + echo "PUSH=1" >> $GITHUB_ENV |
| 103 | + if [ -f 'last_update' ]; then |
| 104 | + last_update=$(cat last_update) |
| 105 | + if compare "$last_update" "$latest"; then |
| 106 | + echo 'Update available, downloading latest deb' |
| 107 | + if download_update "$latest"; then |
| 108 | + update_repo "$latest" |
| 109 | + fi |
| 110 | + else |
| 111 | + echo 'No update available' |
| 112 | + fi |
| 113 | + else |
| 114 | + echo 'No version file found, assuming update available' |
| 115 | + if download_update "$latest" "$releases"; then |
| 116 | + update_repo "$latest" |
| 117 | + fi |
| 118 | + fi |
| 119 | + - name: Commit repo changes |
| 120 | + if: ${{ env.PUSH == 0 }} |
| 121 | + run: | |
| 122 | + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ GITHUB.REPOSITORY }} |
| 123 | + git status |
| 124 | + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 125 | + git config --global user.name "github-actions[bot]" |
| 126 | + git add last_update dists pool README.md |
| 127 | + git commit -m "Update packages" |
| 128 | + git push |
0 commit comments