1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/weblate_ynh.git synced 2024-10-01 13:35:04 +02:00

Merge pull request #59 from YunoHost-Apps/upgrade

Upgrade
This commit is contained in:
yalh76 2022-07-14 00:55:19 +02:00 committed by GitHub
commit fe3c178a37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 209 additions and 33 deletions

59
.github/workflows/updater.sh vendored Normal file
View file

@ -0,0 +1,59 @@
#!/bin/bash
#=================================================
# PACKAGE UPDATING HELPER
#=================================================
# This script is meant to be run by GitHub Actions
# The YunoHost-Apps organisation offers a template Action to run this script periodically
# Since each app is different, maintainers can adapt its contents so as to perform
# automatic actions when a new upstream release is detected.
#=================================================
# FETCHING LATEST RELEASE AND ITS ASSETS
#=================================================
# Fetching information
current_version=$(cat manifest.json | jq -j '.version|split("~")[0]')
repo=$(cat manifest.json | jq -j '.upstream.code|split("https://github.com/")[1]')
# Some jq magic is needed, because the latest upstream release is not always the latest version (e.g. security patches for older versions)
version=$(curl --silent "https://api.github.com/repos/$repo/releases" | jq -r '.[] | select( .prerelease != true ) | .tag_name' | cut -d "-" -f2 | sort -V | tail -1)
# Setting up the environment variables
echo "Current version: $current_version"
echo "Latest release from upstream: $version"
echo "VERSION=$version" >> $GITHUB_ENV
echo "REPO=$repo" >> $GITHUB_ENV
# For the time being, let's assume the script will fail
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
#=================================================
# SPECIFIC UPDATE STEPS
#=================================================
# 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.
#=================================================
# GENERIC FINALIZATION
#=================================================
# Replace new version in manifest
echo "$(jq -s --indent 4 ".[] | .version = \"$version~ynh1\"" manifest.json)" > manifest.json
# 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
echo "PROCEED=true" >> $GITHUB_ENV
exit 0

49
.github/workflows/updater.yml vendored Normal file
View file

@ -0,0 +1,49 @@
# This workflow allows GitHub Actions to automagically update your app whenever a new upstream release is detected.
# You need to enable Actions in your repository settings, and fetch this Action from the YunoHost-Apps organization.
# This file should be enough by itself, but feel free to tune it to your needs.
# It calls updater.sh, which is where you should put the app-specific update steps.
name: Check for new upstream releases
on:
# Allow to manually trigger the workflow
workflow_dispatch:
# Run it every day at 6:00 UTC
schedule:
- cron: '0 6 * * *'
jobs:
updater:
runs-on: ubuntu-latest
steps:
- name: Fetch the source code
uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Run the updater script
id: run_updater
run: |
# Setting up Git user
git config --global user.name 'yunohost-bot'
git config --global user.email 'yunohost-bot@users.noreply.github.com'
# Run the updater script
/bin/bash .github/workflows/updater.sh
- name: Commit changes
id: commit
if: ${{ env.PROCEED == 'true' }}
run: |
git commit -am "Upgrade to v$VERSION"
- name: Create Pull Request
id: cpr
if: ${{ env.PROCEED == 'true' }}
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Update to version ${{ env.VERSION }}
committer: 'yunohost-bot <yunohost-bot@users.noreply.github.com>'
author: 'yunohost-bot <yunohost-bot@users.noreply.github.com>'
signoff: false
base: testing
branch: ci-auto-update-v${{ env.VERSION }}
delete-branch: true
title: 'Upgrade to version ${{ env.VERSION }}'
body: |
Upgrade to v${{ env.VERSION }}
draft: false

View file

@ -2,9 +2,9 @@
; Manifest
domain="domain.tld"
path="/path"
admin="john"
password="randompass"
is_public=1
admin="john"
password="1Strong-Password"
github_account="myaccount"
github_token="myoauthtoken"
; Checks

7
conf/libxxhash.src Normal file
View file

@ -0,0 +1,7 @@
SOURCE_URL=https://github.com/Cyan4973/xxHash/archive/refs/tags/v0.8.1.tar.gz
SOURCE_SUM=3bb6b7d6f30c591dd65aaaff1c8b7a5b94d81687998ca9400082c739a690436c
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=
SOURCE_EXTRACT=true

View file

@ -17,9 +17,6 @@ borgbackup_dependencies="libacl1-dev libacl1 libssl-dev liblz4-dev libzstd-dev l
pkg_dependencies="$weblate_dependencies $borgbackup_dependencies"
# Weblate's version for PIP and settings file
weblate_version="4.13"
debian_maj_version=$(sed 's/\..*//' /etc/debian_version)
if [ "$debian_maj_version" -eq 9 ] ; then
@ -30,6 +27,10 @@ elif [ "$debian_maj_version" -eq 11 ] ; then
weblate_pypath="python3.9"
fi
#=================================================
# PERSONAL HELPERS
#=================================================
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
@ -141,5 +142,5 @@ ynh_redis_remove_db() {
}
#=================================================
# EXPERIMENTAL HELPERS
# FUTURE OFFICIAL HELPERS
#=================================================

View file

@ -25,8 +25,8 @@ ynh_abort_if_errors
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN
is_public=$YNH_APP_ARG_IS_PUBLIC
admin=$YNH_APP_ARG_ADMIN
password=$YNH_APP_ARG_PASSWORD
github_account=$YNH_APP_ARG_GITHUB_ACCOUNT
github_token=$YNH_APP_ARG_GITHUB_TOKEN
@ -83,7 +83,6 @@ ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_psql_test_if_first_run
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name
@ -113,6 +112,19 @@ ynh_add_nginx_config
#=================================================
# SPECIFIC SETUP
#=================================================
# INSTALL XXHASH
#=================================================
ynh_script_progression --message="Installing xxHash..."
tempdir="$(mktemp -d)"
ynh_setup_source --dest_dir=$tempdir --source_id="libxxhash"
pushd $tempdir
make
make install
popd
ynh_secure_remove --file="$tempdir"
#=================================================
# CONFIGURE HUB
#=================================================
@ -140,12 +152,12 @@ chown -R $app: "$final_path"
set -o nounset
cd "${final_path}"
sudo --user=$app $final_path/venv/bin/pip install --upgrade pip setuptools wheel pkgconfig
sudo --user=$app $final_path/venv/bin/pip install --upgrade pip setuptools wheel pkgconfig xxhash
# Read the "Note" section in https://docs.weblate.org/en/weblate-4.11/admin/install/venv-debian.html#python-modules
sudo --user=$app $final_path/venv/bin/pip install --force-reinstall --no-binary :all: cffi
# Still needed with latest version of weblate?
sudo --user=$app BORG_OPENSSL_PREFIX=/usr/lib/x86_64-linux-gnu/ $final_path/venv/bin/pip install Weblate=="$weblate_version"
sudo --user=$app BORG_OPENSSL_PREFIX=/usr/lib/x86_64-linux-gnu/ $final_path/venv/bin/pip install Weblate=="$(ynh_app_upstream_version)"
sudo --user=$app $final_path/venv/bin/pip install psycopg2-binary ruamel.yaml aeidon phply
#pip install pytz python-bidi PyYaML Babel pyuca pylibravatar py3dns psycopg2-binary phply django-redis hiredis aeidon ruamel.yaml
# specific to YunoHost package:
@ -245,6 +257,8 @@ ynh_script_progression --message="Configuring permissions..." --weight=1
# Make app public if necessary
if [ $is_public -eq 1 ]
then
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
ynh_permission_update --permission="main" --add="visitors"
fi

View file

@ -90,6 +90,19 @@ ynh_script_progression --message="Removing dependencies..." --weight=10
# Remove metapackage and its dependencies
ynh_exec_warn_less ynh_remove_app_dependencies
#=================================================
# REMOVE XXHASH
#=================================================
ynh_script_progression --message="Removing xxHash..."
tempdir="$(mktemp -d)"
ynh_setup_source --dest_dir=$tempdir --source_id="libxxhash"
pushd $tempdir
make
make uninstall
popd
ynh_secure_remove --file="$tempdir"
#=================================================
# SPECIFIC REMOVE
#=================================================

View file

@ -23,7 +23,7 @@ ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading settings..." --weight=1
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
@ -43,13 +43,6 @@ test ! -d $final_path \
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
@ -85,7 +78,14 @@ ynh_script_progression --message="Reinstalling dependencies..." --weight=40
ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies"
#=================================================
# RESTORE THE PostgreSQL DATABASE
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=5
@ -95,6 +95,19 @@ ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name
ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
#=================================================
# INSTALL XXHASH
#=================================================
ynh_script_progression --message="Installing xxHash..."
tempdir="$(mktemp -d)"
ynh_setup_source --dest_dir=$tempdir --source_id="libxxhash"
pushd $tempdir
make
make install
popd
ynh_secure_remove --file="$tempdir"
#=================================================
# RESTORE VARIOUS FILES
#=================================================

View file

@ -23,13 +23,20 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
admin_mail=$(ynh_user_get_info "$admin" mail)
github_account=$(ynh_app_setting_get --app=$app --key=github_account)
github_token=$(ynh_app_setting_get --app=$app --key=github_token)
key=$(ynh_string_random 50)
redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
admin_mail=$(ynh_user_get_info --username="$admin" --key=mail)
key=$(ynh_string_random --length=50)
#=================================================
# CHECK VERSION
#=================================================
ynh_script_progression --message="Checking version..."
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
@ -89,6 +96,13 @@ ynh_script_progression --message="Making sure dedicated system user exists..." -
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path" --use_shell
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=5
ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies"
#=================================================
# NGINX CONFIGURATION
#=================================================
@ -97,15 +111,21 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." -
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=5
ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies"
#=================================================
# SPECIFIC UPGRADE
#=================================================
# INSTALL XXHASH
#=================================================
ynh_script_progression --message="Installing xxHash..."
tempdir="$(mktemp -d)"
ynh_setup_source --dest_dir=$tempdir --source_id="libxxhash"
pushd $tempdir
make
make install
popd
ynh_secure_remove --file="$tempdir"
#=================================================
# CONFIGURE HUB
#=================================================
@ -158,7 +178,7 @@ upgrade() {
set -o nounset
cd "${final_path}"
sudo --user=$app $final_path/venv/bin/pip install --upgrade pip setuptools wheel pkgconfig
sudo --user=$app $final_path/venv/bin/pip install --upgrade pip setuptools wheel pkgconfig xxhash
# Read the "Note" section in https://docs.weblate.org/en/weblate-4.11/admin/install/venv-debian.html#python-modules
sudo --user=$app $final_path/venv/bin/pip install --force-reinstall --no-binary :all: cffi
@ -210,7 +230,7 @@ upgrade() {
# Check the configuration
# This may fail in some cases with errors, etc., but the app works and the user can fix issues later.
if [ "$new_version" == "$weblate_version" ]; then
if [ "$new_version" == "$(ynh_app_upstream_version)" ]; then
sudo --user=$app $final_path/venv/bin/weblate check --deploy || true
fi
)
@ -238,7 +258,7 @@ then
upgrade "4.1.1" "../conf/settings.4.1.1.py"
fi
upgrade $weblate_version "../conf/settings.py"
upgrade $(ynh_app_upstream_version) "../conf/settings.py"
# Set right permissions for curl installation
mkdir -p "$final_path/avatar-cache"