From 4265d88d00a3ad7f62f5b85a3ae452e438e125d6 Mon Sep 17 00:00:00 2001 From: Dante Date: Fri, 2 Dec 2022 15:40:16 +0000 Subject: [PATCH 1/4] Enhance updater.sh script to also update config.yaml file and add git hook --- .githooks/pre-commit | 57 ++++++++++++++++++++++++++++++++++++ .github/workflows/updater.sh | 53 ++++++++++++++++++++++++++------- README.md | 10 ++++++- README_fr.md | 8 ++++- manifest.json | 2 +- 5 files changed, 116 insertions(+), 14 deletions(-) create mode 100755 .githooks/pre-commit diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..4c8bebc --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,57 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed. +# Called by "git commit" with no arguments. The hook should +# exit with non-zero status after issuing an appropriate message if +# it wants to stop the commit. +# +# To enable this hook, rename this file to "pre-commit". + +if git rev-parse --verify HEAD >/dev/null 2>&1 +then + against=HEAD +else + # Initial commit: diff against an empty tree object + against=$(git hash-object -t tree /dev/null) +fi + +# If you want to allow non-ASCII filenames set this variable to true. +allownonascii=$(git config --type=bool hooks.allownonascii) + +# Redirect output to stderr. +exec 1>&2 + +# Cross platform projects tend to avoid non-ASCII filenames; prevent +# them from being added to the repository. We exploit the fact that the +# printable range starts at the space character and ends with tilde. +if [ "$allownonascii" != "true" ] && + # Note that the use of brackets around a tr range is ok here, (it's + # even required, for portability to Solaris 10's /usr/bin/tr), since + # the square bracket bytes happen to fall in the designated range. + test $(git diff --cached --name-only --diff-filter=A -z $against | + LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 +then + cat <<\EOF +Error: Attempt to add a non-ASCII file name. + +This can cause problems if you want to work with people on other platforms. + +To be portable it is advisable to rename the file. + +If you know what you are doing you can disable this check using: + + git config hooks.allownonascii true +EOF + exit 1 +fi + +# Check if config.yaml has been modified and add a message +git diff --cached --name-only | if grep -q "conf/config.yaml" +then + cat <<\EOF +It seems that you have modified the config.yaml file, consider checking 'SPECIFIC UPDATE STEPS' section of .github/workflows/updater.sh and update there as well if needed" +EOF +fi + +# If there are whitespace errors, print the offending file names and fail. +exec git diff-index --check --cached $against -- diff --git a/.github/workflows/updater.sh b/.github/workflows/updater.sh index da21b75..ae0064d 100755 --- a/.github/workflows/updater.sh +++ b/.github/workflows/updater.sh @@ -36,14 +36,7 @@ echo "REPO=$repo" >> $GITHUB_ENV echo "PROCEED=false" >> $GITHUB_ENV # Proceed only if the retrieved version is greater than the current one -if ! dpkg --compare-versions "$current_version" "lt" "$version" ; then - echo "::warning ::No new version available" - exit 0 -# Proceed only if a PR for this new version does not already exist -elif git ls-remote -q --exit-code --heads https://github.com/$GITHUB_REPOSITORY.git ci-auto-update-v$version ; then - echo "::warning ::A branch already exists for this update" - exit 0 -fi + #================================================= # UPDATE SOURCE FILES @@ -64,9 +57,6 @@ filename=${asset_url##*/} curl --silent -4 -L $asset_url -o "$tempdir/$filename" checksum=$(sha256sum "$tempdir/$filename" | head -c 64) -# Delete temporary directory -rm -rf $tempdir - # Get extension if [[ $filename == *.tar.gz ]]; then extension=tar.gz @@ -93,6 +83,44 @@ echo "... conf/$src.src updated" # Any action on the app's source code can be done. # The GitHub Action workflow takes care of committing all changes after this script ends. +echo "Update latest version of conf/config.yaml" +# Update the config.yaml with the latest version of it and add vars that will be replaced +configFilePath="conf/config.yaml" +newConfigFilePath=$(tar -tf "$tempdir/$filename" | grep 'example-config.yaml') +tar -xf "$tempdir/$filename" --directory "$tempdir" "$newConfigFilePath" +mv "$tempdir/$newConfigFilePath" "$configFilePath" + +# Replace default values with vars that will be replaced on the install script +yq -i '.homeserver.address = "https://__DOMAIN__"' $configFilePath +yq -i '.homeserver.domain = "__SERVER_NAME__"' $configFilePath +yq -i '.appservice.address = "http://localhost:__PORT__"' $configFilePath +yq -i '.appservice.port = "__PORT__"' $configFilePath +yq -i '.appservice.database = "postgres://__DB_USER__:__DB_PWD__@localhost:5432/__DB_NAME__"' $configFilePath +yq -i '.appservice.id = "__APPSERVICEID__"' $configFilePath +yq -i '.appservice.bot_username = "__BOTNAME__"' $configFilePath +yq -i '.appservice.as_token = "__AS_TOKEN__" | .appservice.as_token style=""' $configFilePath +yq -i '.appservice.hs_token = "__HS_TOKEN__" | .appservice.hs_token style=""' $configFilePath +yq -i '.bridge.encryption.allow = "__IS_ENCRYPTION_ENABLED__"' $configFilePath +yq -i '.bridge.encryption.default = "__IS_ENCRYPTION_ENABLED__"' $configFilePath +yq -i '.bridge.encryption.require = "__IS_ENCRYPTION_ENABLED__"' $configFilePath +yq -i 'with(.bridge.permissions ; . = { "*": "relaybot", "__BOTUSERS__": "puppeting", "__BOTADMIN__": "admin" } | ... style="double")' $configFilePath +yq -i '.telegram.api_id = "__APIID__"' $configFilePath +yq -i '.telegram.api_hash = "__APIHASH__"' $configFilePath +yq -i '.telegram.bot_token = "__BOTTOKEN__"' $configFilePath +yq -i '.logging.handlers.file.filename = "/var/log/__APP__/__APP__.log"' $configFilePath + +# Keep some default options turned off +yq -i '.appservice.database_opts = {}' $configFilePath +yq -i '.appservice.provisioning.enabled = false' $configFilePath +yq -i '.appservice.ephemeral_events = false' $configFilePath +yq -i '.bridge.sync_channel_members = true' $configFilePath +yq -i '.bridge.startup_sync = true' $configFilePath +yq -i '.bridge.public_portals = true' $configFilePath +yq -i '.bridge.sync_with_custom_puppets = true' $configFilePath +yq -i '.bridge.relaybot.whitelist = {}' $configFilePath +yq -i '.logging.loggers.mau.level = "INFO"' $configFilePath +yq -i '.logging.root.level = "INFO"' $configFilePath + #================================================= # GENERIC FINALIZATION #================================================= @@ -100,6 +128,9 @@ echo "... conf/$src.src updated" # Replace new version in manifest echo "$(jq -s --indent 4 ".[] | .version = \"$version~ynh1\"" manifest.json)" > manifest.json +# Delete temporary directory +rm -rf $tempdir + # No need to update the README, yunohost-bot takes care of it # The Action will proceed only if the PROCEED environment variable is set to true diff --git a/README.md b/README.md index 1dbea85..00b094e 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in A puppeting bridge between Matrix and Telegram packaged as a YunoHost service. Messages, notifications (and sometimes media) are bridged between a Telegram user and a Matrix user. Currently the Matrix user can NOT invite other Matrix user in a bridged Telegram room, so only someone with a Telegram account can participate to Telegram group conversations. The ["Mautrix-Telegram"](https://docs.mau.fi/bridges/python/telegram/index.html) bridge is a Synapse App Service and relies on postgresql. Therefore, [Synapse for YunoHost](https://github.com/YunoHost-Apps/synapse_ynh) should be installed beforehand. -**Shipped version:** 0.12.2~ynh2 +**Shipped version:** 0.12.2~ynh3 ## Disclaimers / important information ## List of known public services @@ -118,4 +118,12 @@ or sudo yunohost app upgrade mautrix_telegram -u https://github.com/YunoHost-Apps/mautrix_telegram_ynh/tree/testing --debug ``` +The `.github/workflows/updater.sh` script needs to be synced with changes in `conf/config.yaml` so for now a `pre-commit` +hook is used to display a reminder to update `.github/workflows/updater.sh` (if needed) when `conf/config.yaml` has been modified. + +Please enable Git hooks using following command to ensure code quality and stability. +``` bash +git config --local core.hooksPath .githooks +``` + **More info regarding app packaging:** diff --git a/README_fr.md b/README_fr.md index 0dc59fa..829397f 100644 --- a/README_fr.md +++ b/README_fr.md @@ -21,7 +21,7 @@ La passerelle ["Mautrix-Telegram"](https://docs.mau.fi/bridges/python/telegram/i ** Attention : sauvegardez et restaurez toujours les deux applications Yunohost matrix-synapse et mautrix_telegram en même temps!** -**Version incluse :** 0.12.2~ynh2 +**Version incluse :** 0.12.2~ynh3 ## Avertissements / informations importantes ## Liste de passerelles publiques @@ -113,4 +113,10 @@ ou sudo yunohost app upgrade mautrix_telegram -u https://github.com/YunoHost-Apps/mautrix_telegram_ynh/tree/testing --debug ``` +Le script `.github/workflows/updater.sh` doit être synchronisé avec les changements dans `conf/config.yaml`, +donc pour l'instant un hook `pre-commit` est utilisé pour afficher un rappel pour mettre à jour +`.github/workflows/updater.sh` (si nécessaire) lorsque `conf/config.yaml` a été modifié. + +Veuillez activer les hooks Git en utilisant la commande suivante pour assurer la qualité et la stabilité du code. + **Plus d'infos sur le packaging d'applications :** diff --git a/manifest.json b/manifest.json index 5adf238..25c6a76 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Telegram puppeting bridge for Matrix/Synapse", "fr": "Passerelle Telegram pour Matrix/Synapse" }, - "version": "0.12.2~ynh2", + "version": "0.12.2~ynh3", "url": "https://docs.mau.fi/bridges/python/telegram/index.html", "upstream": { "license": "AGPL-3.0-or-later", From e22966957f85ad6075e606ec098491efabc8e5b2 Mon Sep 17 00:00:00 2001 From: Dante Date: Fri, 2 Dec 2022 15:53:11 +0000 Subject: [PATCH 2/4] Restore accidentally deleted --- .github/workflows/updater.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/updater.sh b/.github/workflows/updater.sh index ae0064d..1abea36 100755 --- a/.github/workflows/updater.sh +++ b/.github/workflows/updater.sh @@ -36,7 +36,14 @@ echo "REPO=$repo" >> $GITHUB_ENV echo "PROCEED=false" >> $GITHUB_ENV # Proceed only if the retrieved version is greater than the current one - +if ! dpkg --compare-versions "$current_version" "lt" "$version" ; then + echo "::warning ::No new version available" + exit 0 +# Proceed only if a PR for this new version does not already exist +elif git ls-remote -q --exit-code --heads https://github.com/$GITHUB_REPOSITORY.git ci-auto-update-v$version ; then + echo "::warning ::A branch already exists for this update" + exit 0 +fi #================================================= # UPDATE SOURCE FILES From f1d0162be80e2f18589a626aea577ba85b82502c Mon Sep 17 00:00:00 2001 From: Dante Date: Tue, 6 Dec 2022 13:03:30 +0000 Subject: [PATCH 3/4] Update DISCLAIMER docs with Git hooks section --- doc/DISCLAIMER.md | 10 ++++++++++ doc/DISCLAIMER_fr.md | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md index ecbb086..a90916a 100644 --- a/doc/DISCLAIMER.md +++ b/doc/DISCLAIMER.md @@ -73,3 +73,13 @@ ExecStartPre=/bin/sleep 90 ``` such that it is ensured that synapse is running before the bridge tries to connect. (If it worked after installation but broke after a restart this probably is it.) + +## Development code quality + +The `.github/workflows/updater.sh` script needs to be synced with changes in `conf/config.yaml` therefore a `pre-commit` +hook is used to display a reminder to update `.github/workflows/updater.sh` (if needed) when `conf/config.yaml` has been modified. + +Please enable Git hooks using following command to ensure code quality and stability. +``` bash +git config --local core.hooksPath .githooks +``` diff --git a/doc/DISCLAIMER_fr.md b/doc/DISCLAIMER_fr.md index fa14045..715e1d0 100644 --- a/doc/DISCLAIMER_fr.md +++ b/doc/DISCLAIMER_fr.md @@ -65,3 +65,14 @@ ExecStartPre=/bin/sleep 90 ``` such that it is ensured that synapse is running before the bridge tries to connect. (If it worked after installation but broke after a restart this probably is it.) + +## Development code quality + +Le script `.github/workflows/updater.sh` doit être synchronisé avec les changements dans `conf/config.yaml`, +donc un hook `pre-commit` est utilisé pour afficher un rappel pour mettre à jour +`.github/workflows/updater.sh` (si nécessaire) lorsque `conf/config.yaml` a été modifié. + +Veuillez activer les hooks Git en utilisant la commande suivante pour assurer la qualité et la stabilité du code. +``` bash +git config --local core.hooksPath .githooks +``` From 8dc5204cf2dbeefc2b29981a122d34ec94dea7df Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Tue, 6 Dec 2022 13:04:16 +0000 Subject: [PATCH 4/4] Auto-update README --- README.md | 18 ++++++++++-------- README_fr.md | 17 +++++++++++------ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 00b094e..cd5ecb8 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,16 @@ ExecStartPre=/bin/sleep 90 such that it is ensured that synapse is running before the bridge tries to connect. (If it worked after installation but broke after a restart this probably is it.) +## Development code quality + +The `.github/workflows/updater.sh` script needs to be synced with changes in `conf/config.yaml` therefore a `pre-commit` +hook is used to display a reminder to update `.github/workflows/updater.sh` (if needed) when `conf/config.yaml` has been modified. + +Please enable Git hooks using following command to ensure code quality and stability. +``` bash +git config --local core.hooksPath .githooks +``` + ## Documentation and resources * Official app website: @@ -118,12 +128,4 @@ or sudo yunohost app upgrade mautrix_telegram -u https://github.com/YunoHost-Apps/mautrix_telegram_ynh/tree/testing --debug ``` -The `.github/workflows/updater.sh` script needs to be synced with changes in `conf/config.yaml` so for now a `pre-commit` -hook is used to display a reminder to update `.github/workflows/updater.sh` (if needed) when `conf/config.yaml` has been modified. - -Please enable Git hooks using following command to ensure code quality and stability. -``` bash -git config --local core.hooksPath .githooks -``` - **More info regarding app packaging:** diff --git a/README_fr.md b/README_fr.md index 829397f..a43d9aa 100644 --- a/README_fr.md +++ b/README_fr.md @@ -92,6 +92,17 @@ ExecStartPre=/bin/sleep 90 such that it is ensured that synapse is running before the bridge tries to connect. (If it worked after installation but broke after a restart this probably is it.) +## Development code quality + +Le script `.github/workflows/updater.sh` doit être synchronisé avec les changements dans `conf/config.yaml`, +donc un hook `pre-commit` est utilisé pour afficher un rappel pour mettre à jour +`.github/workflows/updater.sh` (si nécessaire) lorsque `conf/config.yaml` a été modifié. + +Veuillez activer les hooks Git en utilisant la commande suivante pour assurer la qualité et la stabilité du code. +``` bash +git config --local core.hooksPath .githooks +``` + ## Documentations et ressources * Site officiel de l'app : @@ -113,10 +124,4 @@ ou sudo yunohost app upgrade mautrix_telegram -u https://github.com/YunoHost-Apps/mautrix_telegram_ynh/tree/testing --debug ``` -Le script `.github/workflows/updater.sh` doit être synchronisé avec les changements dans `conf/config.yaml`, -donc pour l'instant un hook `pre-commit` est utilisé pour afficher un rappel pour mettre à jour -`.github/workflows/updater.sh` (si nécessaire) lorsque `conf/config.yaml` a été modifié. - -Veuillez activer les hooks Git en utilisant la commande suivante pour assurer la qualité et la stabilité du code. - **Plus d'infos sur le packaging d'applications :**