Skip to content

Commit

Permalink
Apply last example_ynh
Browse files Browse the repository at this point in the history
  • Loading branch information
yalh76 committed Sep 26, 2022
1 parent 8634fbb commit 3246a5b
Show file tree
Hide file tree
Showing 11 changed files with 233 additions and 68 deletions.
107 changes: 107 additions & 0 deletions .github/workflows/updater.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/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' | sort -V | tail -1)
assets="https://github.com/diaspora/diaspora/archive/refs/tags/$version.tar.gz"

# Later down the script, we assume the version has only digits and dots
# Sometimes the release name starts with a "v", so let's filter it out.
# You may need more tweaks here if the upstream repository has different naming conventions.
if [[ ${version:0:1} == "v" || ${version:0:1} == "V" ]]; then
version=${version:1}
fi

# 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

#=================================================
# UPDATE SOURCE FILES
#=================================================

# Let's download source tarball
asset_url=$assets

echo "Handling asset at $asset_url"

src="app"

# Create the temporary directory
tempdir="$(mktemp -d)"

# Download sources and calculate checksum
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
else
extension=${filename##*.}
fi

# Rewrite source file
cat <<EOT > conf/$src.src
SOURCE_URL=$asset_url
SOURCE_SUM=$checksum
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=$extension
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=
SOURCE_EXTRACT=true
EOT
echo "... conf/$src.src updated"

#=================================================
# 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 changes: 49 additions & 0 deletions .github/workflows/updater.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions conf/app.src
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SOURCE_URL=https://github.com/diaspora/diaspora/archive/refs/tags/v0.7.17.0.tar.gz
SOURCE_SUM=d54f339c1f8da70a87e11240d07dab2645a5ffefa6dc2daf0cf893f84aef0564
SOURCE_URL=https://github.com/diaspora/diaspora/archive/refs/tags/v0.7.18.1.tar.gz
SOURCE_SUM=9dba7fc8ec261bc00c4f5d45af38e3c7aa9e44204dce3b2b79feeed3a120d148
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
Expand Down
9 changes: 4 additions & 5 deletions conf/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
location __PATH__/ {

# Path to source
alias __FINALPATH__/live/public/ ;
alias __FINALPATH__/live/public/;

# Configure maximum picture size
# Note that Diaspora has a client side check set at 4M
# Configure maximum picture size
# Note that Diaspora has a client side check set at 4M
client_max_body_size 5M;
client_body_buffer_size 256K;

# Proxy if requested file not found
# Proxy if requested file not found
try_files $uri @diaspora;

location __PATH__/assets/ {
Expand All @@ -29,5 +29,4 @@ location @diaspora {
proxy_redirect off;

proxy_pass http://unix:/run/__NAME__/diaspora.sock;

}
Empty file added doc/screenshots/.gitkeep
Empty file.
Binary file added doc/screenshots/Diaspora_latest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"en": "Distributed social networking service",
"fr": "Service de réseau social distribué"
},
"version": "0.7.17.0~ynh1",
"version": "0.7.18.1~ynh1",
"url": "https://diasporafoundation.org",
"upstream": {
"license": "AGPL-3.0",
Expand Down
25 changes: 16 additions & 9 deletions scripts/install
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ source /usr/share/yunohost/helpers
#=================================================

ynh_clean_setup () {
ynh_clean_check_starting
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
Expand All @@ -29,10 +29,10 @@ path_url="/"
admin=$YNH_APP_ARG_ADMIN
password=$YNH_APP_ARG_PASSWORD

admin_mail=$(ynh_user_get_info --username=$admin --key=mail)

app=$YNH_APP_INSTANCE_NAME

admin_mail=$(ynh_user_get_info --username=$admin --key=mail)

#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
Expand Down Expand Up @@ -86,7 +86,7 @@ db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..."
ynh_script_progression --message="Setting up source files..." --weight=1

ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
Expand All @@ -104,13 +104,20 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config

#=================================================
# SPECIFIC SETUP
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1

ynh_add_config --template="../conf/diaspora.yml" --destination="$final_path/live/config/diaspora.yml"
chmod 400 "$final_path/live/config/diaspora.yml"
chown $app:$app "$final_path/live/config/diaspora.yml"

ynh_add_config --template="../conf/database.yml" --destination="$final_path/live/config/database.yml"
chmod 400 "$final_path/live/config/database.yml"
chown $app:$app "$final_path/live/config/database.yml"

#=================================================
# BUILD APP
Expand Down Expand Up @@ -162,7 +169,7 @@ systemctl enable ${app}.target --quiet
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1

yunohost service add $app.target \
--log $final_path/live/log/production.log \
Expand All @@ -174,7 +181,7 @@ yunohost service add $app.target \
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_script_progression --message="Starting a systemd service..." --weight=1

systemctl restart ${app}.target
ynh_systemd_action --service_name=${app}_web.service --action=restart --log_path="$final_path/live/log/production.log" --line_match="successfully configured the federation library"
Expand All @@ -183,19 +190,19 @@ ynh_systemd_action --service_name=${app}_sidekiq.service --action=restart --log_
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring permissions..."
ynh_script_progression --message="Configuring permissions..." --weight=1

ynh_permission_update --permission="main" --add="visitors"

#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_script_progression --message="Reloading NGINX web server..." --weight=1

ynh_systemd_action --service_name=nginx --action=reload

#=================================================
# END OF SCRIPT
#=================================================

ynh_script_progression --message="Installation of $app completed"
ynh_script_progression --message="Installation of $app completed" --last
16 changes: 8 additions & 8 deletions scripts/remove
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
ynh_script_progression --message="Loading installation settings..." --weight=1

app=$YNH_APP_INSTANCE_NAME

Expand All @@ -31,14 +31,14 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status $app.target >/dev/null
then
ynh_script_progression --message="Removing $app.target service integration..."
ynh_script_progression --message="Removing $app.target service integration..." --weight=1
yunohost service remove $app.target
fi

#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..."
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1

systemctl stop ${app}.target
systemctl disable ${app}.target --quiet
Expand All @@ -52,23 +52,23 @@ systemctl daemon-reload
#=================================================
# REMOVE THE POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Removing the PostgreSQL database..."
ynh_script_progression --message="Removing the PostgreSQL database..." --weight=1

# Remove a database if it exists, along with the associated user
ynh_psql_remove_db --db_user=$db_user --db_name=$db_name

#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Removing app main directory..."
ynh_script_progression --message="Removing app main directory..." --weight=1

# Remove the app directory securely
ynh_secure_remove --file="$final_path"

#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing NGINX web server configuration..."
ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1

# Remove the dedicated NGINX config
ynh_remove_nginx_config
Expand All @@ -88,7 +88,7 @@ ynh_remove_app_dependencies
#=================================================
# REMOVE DEDICATED USER
#=================================================
ynh_script_progression --message="Removing the dedicated system user..."
ynh_script_progression --message="Removing the dedicated system user..." --weight=1

# Delete a system user
ynh_system_user_delete --username=$app
Expand All @@ -97,4 +97,4 @@ ynh_system_user_delete --username=$app
# END OF SCRIPT
#=================================================

ynh_script_progression --message="Removal of $app completed"
ynh_script_progression --message="Removal of $app completed" --last
Loading

0 comments on commit 3246a5b

Please sign in to comment.