From 36ea9e7f65d467cf3efb01e59deecde4210db02a Mon Sep 17 00:00:00 2001 From: Tony Gorez Date: Thu, 2 Mar 2023 13:10:59 +0100 Subject: [PATCH] tools: refactor dep_updaters PR-URL: https://github.com/nodejs/node/pull/46488 Reviewed-By: Antoine du Hamel Reviewed-By: Darshan Sen --- .github/workflows/tools.yml | 46 ++++++++++----------------- tools/dep_updaters/update-eslint.sh | 23 +++++++++++--- tools/dep_updaters/update-libuv.sh | 35 ++++++++++++++++---- tools/dep_updaters/update-postject.sh | 22 ++++++++++--- tools/dep_updaters/update-simdutf.sh | 29 ++++++++++++----- 5 files changed, 100 insertions(+), 55 deletions(-) diff --git a/.github/workflows/tools.yml b/.github/workflows/tools.yml index e4865d15d0e839..df2aa374c31189 100644 --- a/.github/workflows/tools.yml +++ b/.github/workflows/tools.yml @@ -21,12 +21,10 @@ jobs: subsystem: tools label: tools run: | - NEW_VERSION=$(npm view eslint dist-tags.latest) - CURRENT_VERSION=$(node -p "require('./tools/node_modules/eslint/package.json').version") - if [ "$NEW_VERSION" != "$CURRENT_VERSION" ]; then - echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV - ./tools/dep_updaters/update-eslint.sh - fi + ./tools/dep_updaters/update-eslint.sh > temp-output + cat temp-output + tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true + rm temp-output - id: corepack subsystem: deps label: dependencies @@ -81,12 +79,10 @@ jobs: subsystem: deps,test label: test run: | - NEW_VERSION=$(npm view postject dist-tags.latest) - CURRENT_VERSION=$(node -p "require('./test/fixtures/postject-copy/node_modules/postject/package.json').version") - if [ "$NEW_VERSION" != "$CURRENT_VERSION" ]; then - echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV - ./tools/dep_updaters/update-postject.sh - fi + ./tools/dep_updaters/update-postject.sh > temp-output + cat temp-output + tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true + rm temp-output - id: base64 subsystem: deps label: dependencies @@ -122,28 +118,18 @@ jobs: subsystem: deps label: dependencies run: | - NEW_VERSION=$(gh api repos/libuv/libuv/releases/latest -q '.tag_name|ltrimstr("v")') - VERSION_H="./deps/uv/include/uv/version.h" - CURRENT_MAJOR_VERSION=$(grep "#define UV_VERSION_MAJOR" $VERSION_H | sed -n "s/^.*MAJOR \(.*\)/\1/p") - CURRENT_MINOR_VERSION=$(grep "#define UV_VERSION_MINOR" $VERSION_H | sed -n "s/^.*MINOR \(.*\)/\1/p") - CURRENT_PATCH_VERSION=$(grep "#define UV_VERSION_PATCH" $VERSION_H | sed -n "s/^.*PATCH \(.*\)/\1/p") - CURRENT_SUFFIX_VERSION=$(grep "#define UV_VERSION_SUFFIX" $VERSION_H | sed -n "s/^.*SUFFIX \"\(.*\)\"/\1/p") - SUFFIX_STRING=$([[ -z "$CURRENT_SUFFIX_VERSION" ]] && echo "" || echo "-$CURRENT_SUFFIX_VERSION") - CURRENT_VERSION="$CURRENT_MAJOR_VERSION.$CURRENT_MINOR_VERSION.$CURRENT_PATCH_VERSION$SUFFIX_STRING" - if [ "$NEW_VERSION" != "$CURRENT_VERSION" ]; then - echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV - ./tools/dep_updaters/update-libuv.sh "$NEW_VERSION" - fi + ./tools/dep_updaters/update-libuv.sh > temp-output + cat temp-output + tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true + rm temp-output - id: simdutf subsystem: deps label: dependencies run: | - NEW_VERSION=$(gh api repos/simdutf/simdutf/releases/latest -q '.tag_name|ltrimstr("v")') - CURRENT_VERSION=$(grep "#define SIMDUTF_VERSION" ./deps/simdutf/simdutf.h | sed -n "s/^.*VERSION \(.*\)/\1/p") - if [ "$NEW_VERSION" != "$CURRENT_VERSION" ]; then - echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV - ./tools/dep_updaters/update-simdutf.sh "$NEW_VERSION" - fi + ./tools/dep_updaters/update-simdutf.sh > temp-output + cat temp-output + tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true + rm temp-output - id: nghttp2 subsystem: deps label: dependencies diff --git a/tools/dep_updaters/update-eslint.sh b/tools/dep_updaters/update-eslint.sh index 7d536ef50212ab..b3025bb8ff9e7e 100755 --- a/tools/dep_updaters/update-eslint.sh +++ b/tools/dep_updaters/update-eslint.sh @@ -7,6 +7,20 @@ set -ex +ROOT=$(cd "$(dirname "$0")/../.." && pwd) + +[ -z "$NODE" ] && NODE="$ROOT/out/Release/node" +[ -x "$NODE" ] || NODE=$(command -v node) +NPM="$ROOT/deps/npm/bin/npm-cli.js" + +NEW_VERSION=$("$NODE" "$NPM" view eslint dist-tags.latest) +CURRENT_VERSION=$("$NODE" -p "require('./tools/node_modules/eslint/package.json').version") + +if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then + echo "Skipped because ESlint is on the latest version." + exit 0 +fi + cd "$( dirname "$0" )" || exit rm -rf ../node_modules/eslint ( @@ -14,11 +28,6 @@ rm -rf ../node_modules/eslint mkdir eslint-tmp cd eslint-tmp || exit - ROOT="$PWD/../../.." - [ -z "$NODE" ] && NODE="$ROOT/out/Release/node" - [ -x "$NODE" ] || NODE=$(command -v node) - NPM="$ROOT/deps/npm/bin/npm-cli.js" - "$NODE" "$NPM" init --yes "$NODE" "$NPM" install \ @@ -63,3 +72,7 @@ rm -rf ../node_modules/eslint mv eslint-tmp/node_modules/eslint ../node_modules/eslint rm -rf eslint-tmp/ + +# The last line of the script should always print the new version, +# as we need to add it to $GITHUB_ENV variable. +echo "NEW_VERSION=$NEW_VERSION" diff --git a/tools/dep_updaters/update-libuv.sh b/tools/dep_updaters/update-libuv.sh index ae7fe9a76cac4e..a7ab4de930fc41 100755 --- a/tools/dep_updaters/update-libuv.sh +++ b/tools/dep_updaters/update-libuv.sh @@ -4,12 +4,29 @@ set -e BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd) DEPS_DIR="$BASE_DIR/deps" -LIBUV_VERSION=$1 +[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node" +[ -x "$NODE" ] || NODE=$(command -v node) -if [ "$#" -le 0 ]; then - echo "Error: please provide an libuv version to update to" - echo " e.g. $0 1.44.2" - exit 1 +NEW_VERSION="$("$NODE" --input-type=module <<'EOF' +const res = await fetch('https://api.github.com/repos/libuv/libuv/releases/latest'); +if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res }); +const { tag_name } = await res.json(); +console.log(tag_name.replace('v', '')); +EOF +)" + +VERSION_H="$DEPS_DIR/uv/include/uv/version.h" +CURRENT_MAJOR_VERSION=$(grep "#define UV_VERSION_MAJOR" "$VERSION_H" | sed -n "s/^.*MAJOR \(.*\)/\1/p") +CURRENT_MINOR_VERSION=$(grep "#define UV_VERSION_MINOR" "$VERSION_H" | sed -n "s/^.*MINOR \(.*\)/\1/p") +CURRENT_PATCH_VERSION=$(grep "#define UV_VERSION_PATCH" "$VERSION_H" | sed -n "s/^.*PATCH \(.*\)/\1/p") +CURRENT_IS_RELEASE=$(grep "#define UV_VERSION_IS_RELEASE" "$VERSION_H" | sed -n "s/^.*RELEASE \(.*\)/\1/p") +CURRENT_SUFFIX_VERSION=$(grep "#define UV_VERSION_SUFFIX" "$VERSION_H" | sed -n "s/^.*SUFFIX \"\(.*\)\"/\1/p") +SUFFIX_STRING=$([ "$CURRENT_IS_RELEASE" = 1 ] || [ -z "$CURRENT_SUFFIX_VERSION" ] && echo "" || echo "-$CURRENT_SUFFIX_VERSION") +CURRENT_VERSION="$CURRENT_MAJOR_VERSION.$CURRENT_MINOR_VERSION.$CURRENT_PATCH_VERSION$SUFFIX_STRING" + +if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then + echo "Skipped because libuv is on the latest version." + exit 0 fi echo "Making temporary workspace..." @@ -27,7 +44,7 @@ trap cleanup INT TERM EXIT cd "$WORKSPACE" echo "Fetching libuv source archive..." -curl -sL "https://api.github.com/repos/libuv/libuv/tarball/v$LIBUV_VERSION" | tar xzf - +curl -sL "https://api.github.com/repos/libuv/libuv/tarball/v$NEW_VERSION" | tar xzf - mv libuv-libuv-* uv echo "Replacing existing libuv (except GYP build files)" @@ -40,5 +57,9 @@ echo "" echo "Please git add uv, commit the new version:" echo "" echo "$ git add -A deps/uv" -echo "$ git commit -m \"deps: update libuv to $LIBUV_VERSION\"" +echo "$ git commit -m \"deps: update libuv to $NEW_VERSION\"" echo "" + +# The last line of the script should always print the new version, +# as we need to add it to $GITHUB_ENV variable. +echo "NEW_VERSION=$NEW_VERSION" diff --git a/tools/dep_updaters/update-postject.sh b/tools/dep_updaters/update-postject.sh index 66b207f9666636..f7a63ce1816cf9 100755 --- a/tools/dep_updaters/update-postject.sh +++ b/tools/dep_updaters/update-postject.sh @@ -7,16 +7,24 @@ set -ex +ROOT=$(cd "$(dirname "$0")/../.." && pwd) +[ -z "$NODE" ] && NODE="$ROOT/out/Release/node" +[ -x "$NODE" ] || NODE=$(command -v node) +NPM="$ROOT/deps/npm/bin/npm-cli.js" + +NEW_VERSION=$("$NODE" "$NPM" view postject dist-tags.latest) +CURRENT_VERSION=$("$NODE" -p "require('./test/fixtures/postject-copy/node_modules/postject/package.json').version") + +if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then + echo "Skipped because Postject is on the latest version." + exit 0 +fi + cd "$( dirname "$0" )/../.." || exit rm -rf test/fixtures/postject-copy mkdir test/fixtures/postject-copy cd test/fixtures/postject-copy || exit -ROOT="$PWD/../../.." -[ -z "$NODE" ] && NODE="$ROOT/out/Release/node" -[ -x "$NODE" ] || NODE=$(command -v node) -NPM="$ROOT/deps/npm/bin/npm-cli.js" - "$NODE" "$NPM" init --yes "$NODE" "$NPM" install --no-bin-links --ignore-scripts postject @@ -27,3 +35,7 @@ rm -rf deps/postject mkdir deps/postject cp test/fixtures/postject-copy/node_modules/postject/LICENSE deps/postject cp test/fixtures/postject-copy/node_modules/postject/dist/postject-api.h deps/postject + +# The last line of the script should always print the new version, +# as we need to add it to $GITHUB_ENV variable. +echo "NEW_VERSION=$NEW_VERSION" diff --git a/tools/dep_updaters/update-simdutf.sh b/tools/dep_updaters/update-simdutf.sh index d502558b474479..d9e97cb21e4e60 100755 --- a/tools/dep_updaters/update-simdutf.sh +++ b/tools/dep_updaters/update-simdutf.sh @@ -4,12 +4,21 @@ set -e BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd) DEPS_DIR="$BASE_DIR/deps" -SIMDUTF_VERSION=$1 +[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node" +[ -x "$NODE" ] || NODE=$(command -v node) -if [ "$#" -le 0 ]; then - echo "Error: please provide an simdutf version to update to" - echo " e.g. $0 2.0.3" - exit 1 +NEW_VERSION="$("$NODE" --input-type=module <<'EOF' +const res = await fetch('https://api.github.com/repos/simdutf/simdutf/releases/latest'); +if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res }); +const { tag_name } = await res.json(); +console.log(tag_name.replace('v', '')); +EOF +)" +CURRENT_VERSION=$(grep "#define SIMDUTF_VERSION" "$DEPS_DIR/simdutf/simdutf.h" | sed -n "s/^.*VERSION \"\(.*\)\"/\1/p") + +if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then + echo "Skipped because simdutf is on the latest version." + exit 0 fi echo "Making temporary workspace..." @@ -24,8 +33,8 @@ cleanup () { trap cleanup INT TERM EXIT -SIMDUTF_REF="v$SIMDUTF_VERSION" -SIMDUTF_ZIP="simdutf-$SIMDUTF_VERSION.zip" +SIMDUTF_REF="v$NEW_VERSION" +SIMDUTF_ZIP="simdutf-$NEW_VERSION.zip" SIMDUTF_LICENSE="LICENSE-MIT" cd "$WORKSPACE" @@ -48,5 +57,9 @@ echo "" echo "Please git add simdutf, commit the new version:" echo "" echo "$ git add -A deps/simdutf" -echo "$ git commit -m \"deps: update simdutf to $SIMDUTF_VERSION\"" +echo "$ git commit -m \"deps: update simdutf to $NEW_VERSION\"" echo "" + +# The last line of the script should always print the new version, +# as we need to add it to $GITHUB_ENV variable. +echo "NEW_VERSION=$NEW_VERSION"