Move Flathub watcher from my laptop to GitHub Actions #2007

This commit is contained in:
Sergei Eremenko 2020-02-21 18:07:19 +02:00
parent 9390bb403a
commit daae1b1b0b
3 changed files with 126 additions and 0 deletions

25
.github/workflows/flathub.yml vendored Normal file
View file

@ -0,0 +1,25 @@
name: Flathub Watcher
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
on:
schedule:
- cron: "30 */6 * * *"
jobs:
flathub_list_updater:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Flatpak and dependencies
run: |
sudo add-apt-repository ppa:alexlarsson/flatpak
sudo apt-get update
sudo apt-get install curl jq git-core flatpak
- name: Add Flathub repo
run: flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
- name: Run Flathub list updater
run: bash -x tools/flathub_list_updater.sh

38
tools/flathub_list_updater.sh Executable file
View file

@ -0,0 +1,38 @@
#!/usr/bin/env bash
# This script updates list of Flathub apps in specified GitHub issue
set -euo pipefail
SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
API_ENDPOINT="https://api.github.com/repos/PapirusDevelopmentTeam/papirus-icon-theme/issues/2007"
unchecked_apps_list="$(mktemp -u)"
completed_apps_list="$(mktemp -u)"
missing_apps_list="$(mktemp -u)"
_cleanup() {
rm -f "$unchecked_apps_list" "$completed_apps_list" "$missing_apps_list"
}
trap _cleanup EXIT HUP INT TERM
curl -s "$API_ENDPOINT" |
jq -r '.body' | tee \
>(sed -n '/\[x\][ ]/p' > "$completed_apps_list") \
>(sed -n '/\[ \][ ]/p' > "$unchecked_apps_list") \
>/dev/null
env MARKDOWN=1 bash "$SCRIPT_DIR/missing_flathub_apps.sh" > "$missing_apps_list"
if ! diff -w --brief "$unchecked_apps_list" "$missing_apps_list" >/dev/null; then
echo "Uptading issue #${API_ENDPOINT##*/} ..." >&2
jq --null-input --compact-output \
--arg body "$(cat "$missing_apps_list" "$completed_apps_list")" '{$body}' |
curl \
--silent \
--output /dev/null \
--header "Authorization: token ${GITHUB_TOKEN?is not set}" \
--header 'Content-Type: application/json' \
--data @- \
--request PATCH "$API_ENDPOINT"
fi

63
tools/missing_flathub_apps.sh Executable file
View file

@ -0,0 +1,63 @@
#!/usr/bin/env bash
#
# Before running this script make sure that Flathub repo is added:
#
# flatpak remote-add --user --if-not-exists \
# flathub https://flathub.org/repo/flathub.flatpakrepo
set -euo pipefail
IFS=$'\n\t'
SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
GIT_ROOT="$SCRIPT_DIR/.."
IGNORED_APPS=(
# apps without icons:
io.atom.electron.BaseApp
io.elementary.BaseApp
io.elementary.Loki.BaseApp
io.gitlab.sdl_jstest.sdl2_jstest
io.gitlab.sdl_jstest.sdl_jstest
io.qt.qtwebengine.BaseApp
io.qt.qtwebkit.BaseApp
org.electronjs.Electron2.BaseApp
org.flathub.flatpak-external-data-checker
org.flatpak.Builder
org.freedesktop.appstream-glib
org.freedesktop.GlxInfo
org.godotengine.godot.BaseApp
org.mosh.mosh
org.mozilla.Firefox.BaseApp
# apps with icons that do not match with App ID:
com.github.utsushi.Utsushi
com.wps.Office
net.openra.OpenRA
org.homelinuxserver.vance.biblereader
org.libreoffice.LibreOffice
org.vranki.spectral
)
flathub_apps_list="$(mktemp -u)"
papirus_icons_list="$(mktemp -u)"
_cleanup() {
rm -f "$flathub_apps_list" "$papirus_icons_list"
}
trap _cleanup EXIT HUP INT TERM
env XDG_DATA_DIRS="$HOME/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share" \
flatpak remote-ls --app --columns app flathub | sort -u > "$flathub_apps_list"
git -C "$GIT_ROOT" ls-tree master:Papirus/64x64/apps --name-only |
sed 's/\.svg$//' | sort > "$papirus_icons_list"
while read -r app_id; do
[[ "${IGNORED_APPS[*]//$app_id/}" == "${IGNORED_APPS[*]}" ]] || continue
if [ -n "${MARKDOWN:-}" ]; then
# shellcheck disable=SC2016
printf ' - [ ] `%s` <kbd>[GitHub](%s)</kbd> <kbd>[Flathub](%s)</kbd>\n' "$app_id" \
"https://github.com/flathub/$app_id" "https://flathub.org/apps/details/$app_id"
else
printf '%s\n' "$app_id"
fi
done < <(comm -23 "$flathub_apps_list" "$papirus_icons_list")