YunoHost-Apps / gitea_ynh

Gitea is a fork of Gogs. A git platform, Mirror of https://framagit.org/YunoHost-Apps/gitea_ynh
https://gitea.io
MIT License
22 stars 17 forks source link

Implementing auto update #67

Closed OniriCorpe closed 9 months ago

OniriCorpe commented 1 year ago

gitea updates are often slow to arrive on ynh so I thought I'd implement auto update to help you

I have two questions:

at the moment the script doesn't take these 2 things into account because they are maybe not relevant anymore I'll make the appropriate changes if it turns out that it was necessary

the script ignores the release candidates, by the way

PR Status

Josue-T commented 1 year ago

Hello,

I don't really think that the updates are slow. I do it as quickly as I can and generally it take less than one week to be updated and in all case it still need to be tested manually and merged... anyway.

Thanks for your work. Well, currently on the main version upgrade we also need to update the update script to manage correctly the database migration. I share you my current upgrade script. You can take inspiration to manage correctly the upgrade.

        set -eu
        get_checksum() {
            local v=$1
            wget https://github.com/go-gitea/gitea/releases/download/v${v}/gitea-${v}-linux-arm-6.sha256
            wget https://github.com/go-gitea/gitea/releases/download/v${v}/gitea-${v}-linux-386.sha256
            wget https://github.com/go-gitea/gitea/releases/download/v${v}/gitea-${v}-linux-amd64.sha256
            wget https://github.com/go-gitea/gitea/releases/download/v${v}/gitea-${v}-linux-arm64.sha256

            sha256sumarm6=$(cat gitea-${v}-linux-arm-6.sha256 | cut -d' ' -f1)
            sha256sumarm7=$(cat gitea-${v}-linux-arm-6.sha256 | cut -d' ' -f1)
            sha256sum386=$(cat gitea-${v}-linux-386.sha256 | cut -d' ' -f1)
            sha256sumamd64=$(cat gitea-${v}-linux-amd64.sha256 | cut -d' ' -f1)
            sha256sumarm64=$(cat gitea-${v}-linux-arm64.sha256 | cut -d' ' -f1)

            rm gitea-${v}-linux-arm-6.sha256
            rm gitea-${v}-linux-386.sha256
            rm gitea-${v}-linux-amd64.sha256
            rm gitea-${v}-linux-arm64.sha256
        }
        update_source_file() {
            local suffix=$1
            local v=$2
            #   Update this link
            sed -r -i "s@SOURCE_URL=(.*)/releases/download/v[[:alnum:].]{4,8}/gitea-[[:alnum:].]{4,8}-linux-arm-6@SOURCE_URL=\1/releases/download/v${v}/gitea-${v}-linux-arm-6@" conf/source/arm${suffix}
            sed -r -i "s@SOURCE_SUM=[[:alnum:]]{64}@SOURCE_SUM=$sha256sumarm6@" conf/source/arm${suffix}
            sed -r -i "s@SOURCE_URL=(.*)/releases/download/v[[:alnum:].]{4,8}/gitea-[[:alnum:].]{4,8}-linux-arm-6@SOURCE_URL=\1/releases/download/v${v}/gitea-${v}-linux-arm-6@" conf/source/armv7${suffix}
            sed -r -i "s@SOURCE_SUM=[[:alnum:]]{64}@SOURCE_SUM=$sha256sumarm7@" conf/source/armv7${suffix}
            sed -r -i "s@SOURCE_URL=(.*)/releases/download/v[[:alnum:].]{4,8}/gitea-[[:alnum:].]{4,8}-linux-386@SOURCE_URL=\1/releases/download/v${v}/gitea-${v}-linux-386@" conf/source/i386${suffix}
            sed -r -i "s@SOURCE_SUM=[[:alnum:]]{64}@SOURCE_SUM=$sha256sum386@" conf/source/i386${suffix}
            sed -r -i "s@SOURCE_URL=(.*)/releases/download/v[[:alnum:].]{4,8}/gitea-[[:alnum:].]{4,8}-linux-amd64@SOURCE_URL=\1/releases/download/v${v}/gitea-${v}-linux-amd64@" conf/source/x86-64${suffix}
            sed -r -i "s@SOURCE_SUM=[[:alnum:]]{64}@SOURCE_SUM=$sha256sumamd64@" conf/source/x86-64${suffix}
            sed -r -i "s@SOURCE_URL=(.*)/releases/download/v[[:alnum:].]{4,8}/gitea-[[:alnum:].]{4,8}-linux-arm64@SOURCE_URL=\1/releases/download/v${v}/gitea-${v}-linux-arm64@" conf/source/arm64${suffix}
            sed -r -i "s@SOURCE_SUM=[[:alnum:]]{64}@SOURCE_SUM=$sha256sumarm64@" conf/source/arm64${suffix}
        }

        pushd repos/gitea

        git checkout auto_update
        git pull -f gitea auto_update:auto_update

        last_version=$(egrep '\"version\": \"[[:alnum:].]{4,8}~ynh([[:digit:]]+)\",' manifest.json | cut -d'~' -f1 | egrep -o '[[:alnum:].]{4,8}$')

        last_main_version=${last_version%.*}
        main_version=${gitea_version%.*}

        if [ $last_main_version != $main_version ]; then
            cp conf/source/arm.src conf/source/arm_${last_main_version}.src
            cp conf/source/armv7.src conf/source/armv7_${last_main_version}.src
            cp conf/source/i386.src conf/source/i386_${last_main_version}.src
            cp conf/source/x86-64.src conf/source/x86-64_${last_main_version}.src
            cp conf/source/arm64.src conf/source/arm64_${last_main_version}.src

            last_main_version_full=$(curl 'https://api.github.com/repos/go-gitea/gitea/releases' -H 'Host: api.github.com' --compressed \
                | grep '"tag_name":' | grep -o -P '(\d+\.)*\d+' | grep "^$last_main_version" | head -n1)

            get_checksum $last_main_version_full
            update_source_file "_$last_main_version.src" $last_main_version_full
    #         WE need to add this
    #         "1.7."* )
    #             ynh_setup_source $final_path source/${architecture}_1.8
    #             restart_gitea
    #         ;&
    #         esac
            last_last_version=$(grep 'ynh_setup_source $final_path source/${architecture}_' scripts/upgrade \
                | tail -n1 | egrep -o '[[:alnum:]]+\.[[:alnum:]]+$')
            perl -0777 -pe "s@restart_gitea\n;&\nesac@restart_gitea\n;&\n\"${last_last_version}."'"* )\n    ynh_setup_source \$final_path source/\${architecture}_'"${last_main_version}\n    restart_gitea\n;&\nesac@" scripts/upgrade > tmp
            mv tmp scripts/upgrade
        fi

        get_checksum $gitea_version
        update_source_file ".src" $gitea_version
        sed -r -i "s@\"version\": \"[[:alnum:].]{4,8}~ynh([[:digit:]]+)\",@\"version\": \"${gitea_version}~ynh1\",@" manifest.json
OniriCorpe commented 1 year ago

I don't really think that the updates are slow. I do it as quickly as I can and generally it take less than one week to be updated and in all case it still need to be tested manually and merged... anyway.

I mean available to users (so on the master branch) currently the user available version of gitea on ynh is the 1.17.4, released in December 2022 when I say that updates are slow to arrive, it is for the final users

and it has happened several times already that there are several months of delays that's why I had the idea of automating part of the work, but in fact it was already done at least with my work the bot can do it autonomously

it's great that the work has already been automated! thanks for your script, I used parts of it and reworked others

the script has been tested and works well

is this right for you?

OniriCorpe commented 1 year ago

I made the patching of the armv7 file with the armv6 file conditional on the file not being updated, so if there is no armv7 build

so that if one day the bug is fixed, it will switch back to the armv7 build by itself

https://github.com/YunoHost-Apps/gitea_ynh/pull/67/commits/21dc0e8b4e952c050480da4603d27df4c48851fa#diff-a7e89d2fee50dafb9ca639121350be8362bf14ea294d265c2fbf6546dea79477R23-R33

Josue-T commented 9 months ago

Closing as #84 should do this.