mirror of
https://github.com/YunoHost-Apps/wordpress_ynh.git
synced 2024-09-03 20:36:10 +02:00
cleaning
This commit is contained in:
parent
4ddd1adc0e
commit
d7b3cea730
5 changed files with 7 additions and 171 deletions
126
.github/workflows/updater.py
vendored
126
.github/workflows/updater.py
vendored
|
@ -1,126 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
This script is meant to be run by GitHub Actions.
|
||||
It comes with a Github Action updater.yml to run this script periodically.
|
||||
|
||||
Since each app is different, maintainers can adapt its contents to perform
|
||||
automatic actions when a new upstream release is detected.
|
||||
|
||||
You need to enable the action by removing `if ${{ false }}` in updater.yml!
|
||||
"""
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
from subprocess import run, PIPE
|
||||
import textwrap
|
||||
from typing import List, Tuple, Any
|
||||
import requests
|
||||
from packaging import version
|
||||
|
||||
logging.getLogger().setLevel(logging.INFO)
|
||||
|
||||
|
||||
# ========================================================================== #
|
||||
# Functions customizable by app maintainer
|
||||
|
||||
def get_latest_version(repo: str) -> Tuple[version.Version, Any]:
|
||||
"""
|
||||
May be customized by maintainers for other forges than Github.
|
||||
Returns a tuple: a comparable version, and some data that will
|
||||
be passed to get_asset_urls_of_release().
|
||||
"""
|
||||
api_url = "https://api.wordpress.org/core/version-check/1.7/"
|
||||
|
||||
# Maintainer: use either releases or tags
|
||||
tags = requests.get(f"{api_url}").json()
|
||||
tag_info = next(
|
||||
tag for tag in tags["offers"]
|
||||
)
|
||||
return version.Version(tag_info["version"]), tag_info
|
||||
|
||||
def generate_src_files(repo: str, release: Any):
|
||||
"""
|
||||
Should call write_src_file() for every asset/binary/... to download.
|
||||
"""
|
||||
|
||||
built_release = release["packages"]["full"]
|
||||
logging.info("Handling main tarball at %s", built_release)
|
||||
write_src_file("app.src", built_release, "zip")
|
||||
|
||||
|
||||
# ========================================================================== #
|
||||
# Core generic code of the script, app maintainers should not edit this part
|
||||
|
||||
def sha256sum_of_url(url: str) -> str:
|
||||
"""Compute checksum without saving the file"""
|
||||
checksum = hashlib.sha256()
|
||||
for chunk in requests.get(url, stream=True).iter_content(10*1024):
|
||||
checksum.update(chunk)
|
||||
return checksum.hexdigest()
|
||||
|
||||
def write_src_file(name: str, asset_url: str, extension: str,
|
||||
extract: bool = True, subdir: bool = True) -> None:
|
||||
"""Rewrite conf/app.src"""
|
||||
logging.info("Writing %s...", name)
|
||||
|
||||
with open(f"conf/{name}", "w", encoding="utf-8") as conf_file:
|
||||
conf_file.write(textwrap.dedent(f"""\
|
||||
SOURCE_URL={asset_url}
|
||||
SOURCE_SUM={sha256sum_of_url(asset_url)}
|
||||
SOURCE_SUM_PRG=sha256sum
|
||||
SOURCE_FORMAT={extension}
|
||||
SOURCE_IN_SUBDIR={str(subdir).lower()}
|
||||
SOURCE_EXTRACT={str(extract).lower()}
|
||||
"""))
|
||||
|
||||
def write_github_env(proceed: bool, new_version: str, branch: str):
|
||||
"""Those values will be used later in the workflow"""
|
||||
if "GITHUB_ENV" not in os.environ:
|
||||
logging.warning("GITHUB_ENV is not in the envvars, assuming not in CI")
|
||||
return
|
||||
with open(os.environ["GITHUB_ENV"], "w", encoding="utf-8") as github_env:
|
||||
github_env.write(textwrap.dedent(f"""\
|
||||
VERSION={new_version}
|
||||
BRANCH={branch}
|
||||
PROCEED={str(proceed).lower()}
|
||||
"""))
|
||||
|
||||
def main():
|
||||
with open("manifest.json", "r", encoding="utf-8") as manifest_file:
|
||||
manifest = json.load(manifest_file)
|
||||
repo = manifest["upstream"]["code"]
|
||||
|
||||
current_version = version.Version(manifest["version"].split("~")[0])
|
||||
latest_version, release_info = get_latest_version(repo)
|
||||
logging.info("Current version: %s", current_version)
|
||||
logging.info("Latest upstream version: %s", latest_version)
|
||||
|
||||
# Proceed only if the retrieved version is greater than the current one
|
||||
if latest_version <= current_version:
|
||||
logging.warning("No new version available")
|
||||
write_github_env(False, "", "")
|
||||
return
|
||||
|
||||
# Proceed only if a PR for this new version does not already exist
|
||||
branch = f"ci-auto-update-v{latest_version}"
|
||||
command = ["git", "ls-remote", "--exit-code", "-h", repo, branch]
|
||||
if run(command, stderr=PIPE, stdout=PIPE, check=False).returncode == 0:
|
||||
logging.warning("A branch already exists for this update")
|
||||
write_github_env(False, "", "")
|
||||
return
|
||||
|
||||
generate_src_files(repo, release_info)
|
||||
|
||||
manifest["version"] = f"{latest_version}~ynh1"
|
||||
with open("manifest.json", "w", encoding="utf-8") as manifest_file:
|
||||
json.dump(manifest, manifest_file, indent=4, ensure_ascii=False)
|
||||
manifest_file.write("\n")
|
||||
|
||||
write_github_env(True, latest_version, branch)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
38
.github/workflows/updater.yml
vendored
38
.github/workflows/updater.yml
vendored
|
@ -1,38 +0,0 @@
|
|||
# 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 8:00 UTC
|
||||
schedule:
|
||||
- cron: '0 8 * * *'
|
||||
|
||||
jobs:
|
||||
updater:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Fetch the source code
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Run the updater script
|
||||
run: .github/workflows/updater.py
|
||||
|
||||
- name: Create Pull Request
|
||||
if: ${{ env.PROCEED == 'true' }}
|
||||
uses: peter-evans/create-pull-request@v4
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
title: Upgrade ${{ env.APP_NAME }} to version ${{ env.VERSION }}
|
||||
body: Upgrade ${{ env.APP_NAME }} to version ${{ env.VERSION }}
|
||||
commit-message: Upgrade ${{ env.APP_NAME }} to version ${{ env.VERSION }}
|
||||
committer: 'yunohost-bot <yunohost-bot@users.noreply.github.com>'
|
||||
author: 'yunohost-bot <yunohost-bot@users.noreply.github.com>'
|
||||
base: testing
|
||||
branch: ${{ env.BRANCH }}
|
||||
delete-branch: true
|
|
@ -1,4 +1,4 @@
|
|||
### Updating wordpress
|
||||
### Updating WordPress
|
||||
|
||||
As the automatic update plugin isn't working as expected, pay attention to keep your WordPress up to date from the WordPress admin panel, and not only from YunoHost admin panel. For security reason, you should control that all updates are regularly applied in WordPress admin panel as well as in YunoHost admin panel.
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
### Mises à jour de wordpress
|
||||
### Mises à jour de WordPress
|
||||
|
||||
Comme les mises à jour automatiques ne fonctionnent pas correctement, prenez soin de bien mettre à jour WordPress via le panneau d'administration de WordPress et pas seulement via le panneau d'administration de YunoHost. Pour des raisons de sécurité, vérifiez bien que toutes les mises à jour sont bien installées dans le panneau d'administration de WordPress comme dans le panneau d'administration de YunoHost.
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ name = "WordPress"
|
|||
description.en = "Create a beautiful blog or website easily"
|
||||
description.fr = "Logiciel de création de blog ou de site Web"
|
||||
|
||||
version = "6.2~ynh1"
|
||||
version = "6.2.2~ynh1"
|
||||
|
||||
maintainers = ["kay0u"]
|
||||
|
||||
|
@ -16,7 +16,7 @@ admindoc = "https://codex.wordpress.org/"
|
|||
code = "https://core.trac.wordpress.org/browser"
|
||||
|
||||
[integration]
|
||||
yunohost = ">= 11.1.19"
|
||||
yunohost = ">= 11.1.21"
|
||||
architectures = "all"
|
||||
multi_instance = true
|
||||
ldap = true
|
||||
|
@ -55,8 +55,8 @@ ram.runtime = "50M"
|
|||
|
||||
[resources]
|
||||
[resources.sources.main]
|
||||
url = "https://downloads.wordpress.org/release/wordpress-6.2.zip"
|
||||
sha256 = "0078e0483d3447a465f71d6bbdab5c799cad2e57c221ec1d639d235b0ffced55"
|
||||
url = "https://downloads.wordpress.org/release/wordpress-6.2.2.zip"
|
||||
sha256 = "08669faf3c0c2289c66b1971cb0a6162d8d3ddac885ccbf342e29a0bda36250b"
|
||||
|
||||
[resources.system_user]
|
||||
|
||||
|
@ -69,7 +69,7 @@ ram.runtime = "50M"
|
|||
admin.allowed = "admins"
|
||||
|
||||
[resources.apt]
|
||||
packages = "mariadb-server php8.2-mysql php8.2-curl php8.2-json php8.2-mbstring php8.2-xml php8.2-zip php8.2-gd php8.2-soap php8.2-ssh2 php8.2-tokenizer php8.2-ldap"
|
||||
packages = "mariadb-server php8.2-mysql php8.2-curl php8.2-mbstring php8.2-xml php8.2-zip php8.2-gd php8.2-soap php8.2-ssh2 php8.2-tokenizer php8.2-ldap"
|
||||
|
||||
[resources.database]
|
||||
type = "mysql"
|
||||
|
|
Loading…
Add table
Reference in a new issue