mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
helpers/nodejs: simplify 'n' script install and maintenance
This commit is contained in:
parent
5b58e0e60c
commit
13ac9dade6
6 changed files with 1649 additions and 109 deletions
78
.github/workflows/n_updater.sh
vendored
78
.github/workflows/n_updater.sh
vendored
|
@ -1,78 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# N UPDATING HELPER
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# This script is meant to be run by GitHub Actions.
|
|
||||||
# It is derived from the Updater script from the YunoHost-Apps organization.
|
|
||||||
# It aims to automate the update of `n`, the Node version management system.
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# FETCHING LATEST RELEASE AND ITS ASSETS
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# Fetching information
|
|
||||||
source helpers/nodejs
|
|
||||||
current_version="$n_version"
|
|
||||||
repo="tj/n"
|
|
||||||
# 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)
|
|
||||||
|
|
||||||
# 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.
|
|
||||||
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
|
|
||||||
# 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:-YunoHost/yunohost}.git ci-auto-update-n-v$version ; then
|
|
||||||
echo "::warning ::A branch already exists for this update"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# UPDATE SOURCE FILES
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
asset_url="https://github.com/tj/n/archive/v${version}.tar.gz"
|
|
||||||
|
|
||||||
echo "Handling asset at $asset_url"
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
echo "Calculated checksum for n v${version} is $checksum"
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# GENERIC FINALIZATION
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# Replace new version in helper
|
|
||||||
sed -i -E "s/^n_version=.*$/n_version=$version/" helpers/nodejs
|
|
||||||
|
|
||||||
# Replace checksum in helper
|
|
||||||
sed -i -E "s/^n_checksum=.*$/n_checksum=$checksum/" helpers/nodejs
|
|
||||||
|
|
||||||
# The Action will proceed only if the PROCEED environment variable is set to true
|
|
||||||
echo "PROCEED=true" >> $GITHUB_ENV
|
|
||||||
exit 0
|
|
3
.github/workflows/n_updater.yml
vendored
3
.github/workflows/n_updater.yml
vendored
|
@ -21,7 +21,8 @@ jobs:
|
||||||
git config --global user.name 'yunohost-bot'
|
git config --global user.name 'yunohost-bot'
|
||||||
git config --global user.email 'yunohost-bot@users.noreply.github.com'
|
git config --global user.email 'yunohost-bot@users.noreply.github.com'
|
||||||
# Run the updater script
|
# Run the updater script
|
||||||
/bin/bash .github/workflows/n_updater.sh
|
wget https://raw.githubusercontent.com/tj/n/master/bin/n --output-document=helpers/vendor/n/n
|
||||||
|
[[ -z "$(git diff helpers/vendor/n/n)" ]] || echo "PROCEED=true" >> $GITHUB_ENV
|
||||||
- name: Commit changes
|
- name: Commit changes
|
||||||
id: commit
|
id: commit
|
||||||
if: ${{ env.PROCEED == 'true' }}
|
if: ${{ env.PROCEED == 'true' }}
|
||||||
|
|
|
@ -1,32 +1,10 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
n_version=9.0.1
|
|
||||||
n_checksum=ad305e8ee9111aa5b08e6dbde23f01109401ad2d25deecacd880b3f9ea45702b
|
|
||||||
n_install_dir="/opt/node_n"
|
n_install_dir="/opt/node_n"
|
||||||
node_version_path="$n_install_dir/n/versions/node"
|
node_version_path="$n_install_dir/n/versions/node"
|
||||||
# N_PREFIX is the directory of n, it needs to be loaded as a environment variable.
|
# N_PREFIX is the directory of n, it needs to be loaded as a environment variable.
|
||||||
export N_PREFIX="$n_install_dir"
|
export N_PREFIX="$n_install_dir"
|
||||||
|
|
||||||
# Install Node version management
|
|
||||||
#
|
|
||||||
# [internal]
|
|
||||||
#
|
|
||||||
# usage: ynh_install_n
|
|
||||||
#
|
|
||||||
# Requires YunoHost version 2.7.12 or higher.
|
|
||||||
ynh_install_n() {
|
|
||||||
# Build an app.src for n
|
|
||||||
echo "SOURCE_URL=https://github.com/tj/n/archive/v${n_version}.tar.gz
|
|
||||||
SOURCE_SUM=${n_checksum}" >"$YNH_APP_BASEDIR/conf/n.src"
|
|
||||||
# Download and extract n
|
|
||||||
ynh_setup_source --dest_dir="$n_install_dir/git" --source_id=n
|
|
||||||
# Install n
|
|
||||||
(
|
|
||||||
cd "$n_install_dir/git"
|
|
||||||
PREFIX=$N_PREFIX make install 2>&1
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
# Load the version of node for an app, and set variables.
|
# Load the version of node for an app, and set variables.
|
||||||
#
|
#
|
||||||
# usage: ynh_use_nodejs
|
# usage: ynh_use_nodejs
|
||||||
|
@ -133,14 +111,10 @@ ynh_install_nodejs() {
|
||||||
test -x /usr/bin/node && mv /usr/bin/node /usr/bin/node_n
|
test -x /usr/bin/node && mv /usr/bin/node /usr/bin/node_n
|
||||||
test -x /usr/bin/npm && mv /usr/bin/npm /usr/bin/npm_n
|
test -x /usr/bin/npm && mv /usr/bin/npm /usr/bin/npm_n
|
||||||
|
|
||||||
# If n is not previously setup, install it
|
# Install (or update if YunoHost vendor/ folder updated since last install) n
|
||||||
if ! $n_install_dir/bin/n --version >/dev/null 2>&1; then
|
mkdir -p $n_install_dir/bin/
|
||||||
ynh_install_n
|
cp /usr/share/yunohost/helpers.d/vendor/n/n $n_install_dir/bin/n
|
||||||
elif dpkg --compare-versions "$($n_install_dir/bin/n --version)" lt $n_version; then
|
# Tweak for n to understand it's installed in $N_PREFIX
|
||||||
ynh_install_n
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Modify the default N_PREFIX in n script
|
|
||||||
ynh_replace_string --match_string="^N_PREFIX=\${N_PREFIX-.*}$" --replace_string="N_PREFIX=\${N_PREFIX-$N_PREFIX}" --target_file="$n_install_dir/bin/n"
|
ynh_replace_string --match_string="^N_PREFIX=\${N_PREFIX-.*}$" --replace_string="N_PREFIX=\${N_PREFIX-$N_PREFIX}" --target_file="$n_install_dir/bin/n"
|
||||||
|
|
||||||
# Restore /usr/local/bin in PATH
|
# Restore /usr/local/bin in PATH
|
||||||
|
|
21
helpers/vendor/n/LICENSE
vendored
Normal file
21
helpers/vendor/n/LICENSE
vendored
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2018 TJ Holowaychuk
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
1
helpers/vendor/n/README.md
vendored
Normal file
1
helpers/vendor/n/README.md
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
This is taken from https://github.com/tj/n/
|
1621
helpers/vendor/n/n
vendored
Executable file
1621
helpers/vendor/n/n
vendored
Executable file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue