From e8075fd1f81ec478f7f521fde7c7b3c83faf3297 Mon Sep 17 00:00:00 2001 From: Facundo Tuesca Date: Thu, 10 Nov 2022 09:27:45 +0000 Subject: [PATCH] tools: add automation for updating acorn dependency Add a Github Action that checks for new versions of the `acorn` and `acorn-walk` dependencies, and creates PRs to update them if newer versions than the ones present in the repo are found. Refs: https://github.com/nodejs/security-wg/issues/828 PR-URL: https://github.com/nodejs/node/pull/45357 Reviewed-By: Darshan Sen Reviewed-By: Luigi Pinca Reviewed-By: Jiawen Geng --- .github/workflows/tools.yml | 20 ++++++++++++++++++++ tools/update-acorn-walk.sh | 30 ++++++++++++++++++++++++++++++ tools/update-acorn.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 tools/update-acorn-walk.sh create mode 100755 tools/update-acorn.sh diff --git a/.github/workflows/tools.yml b/.github/workflows/tools.yml index a2172b491b5066..2b371c93cd7f5a 100644 --- a/.github/workflows/tools.yml +++ b/.github/workflows/tools.yml @@ -89,6 +89,26 @@ jobs: echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV ./tools/update-base64.sh "$NEW_VERSION" fi + - id: acorn + subsystem: deps + label: dependencies + run: | + NEW_VERSION=$(npm view acorn dist-tags.latest) + CURRENT_VERSION=$(node -p "require('./deps/acorn/acorn/package.json').version") + if [ "$NEW_VERSION" != "$CURRENT_VERSION" ]; then + echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV + ./tools/update-acorn.sh + fi + - id: acorn-walk + subsystem: deps + label: dependencies + run: | + NEW_VERSION=$(npm view acorn-walk dist-tags.latest) + CURRENT_VERSION=$(node -p "require('./deps/acorn/acorn-walk/package.json').version") + if [ "$NEW_VERSION" != "$CURRENT_VERSION" ]; then + echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV + ./tools/update-acorn-walk.sh + fi steps: - uses: actions/checkout@v3 with: diff --git a/tools/update-acorn-walk.sh b/tools/update-acorn-walk.sh new file mode 100644 index 00000000000000..0d8670742728ea --- /dev/null +++ b/tools/update-acorn-walk.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +# Shell script to update acorn-walk in the source tree to the latest release. + +# This script must be in the tools directory when it runs because it uses the +# script source file path to determine directories to work in. + +set -ex + +cd "$( dirname "$0" )/.." || exit +rm -rf deps/acorn/acorn-walk + +( + rm -rf acorn-walk-tmp + mkdir acorn-walk-tmp + cd acorn-walk-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 --global-style --no-bin-links --ignore-scripts acorn-walk +) + +mv acorn-walk-tmp/node_modules/acorn-walk deps/acorn + +rm -rf acorn-walk-tmp/ diff --git a/tools/update-acorn.sh b/tools/update-acorn.sh new file mode 100755 index 00000000000000..fadcb242884d77 --- /dev/null +++ b/tools/update-acorn.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +# Shell script to update acorn in the source tree to the latest release. + +# This script must be in the tools directory when it runs because it uses the +# script source file path to determine directories to work in. + +set -ex + +cd "$( dirname "$0" )/.." || exit +rm -rf deps/acorn/acorn + +( + rm -rf acorn-tmp + mkdir acorn-tmp + cd acorn-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 --global-style --no-bin-links --ignore-scripts acorn +) + +mv acorn-tmp/node_modules/acorn deps/acorn + +rm -rf acorn-tmp/