Skip to content

Commit 682a730

Browse files
facutuescadanielleadams
authored andcommitted
tools: add automation for updating libuv dependency
Add a Github Action that checks for new versions of the `libuv` C library, and creates a PR to update it if a newer version than the one present in the repo is found. Refs: nodejs/security-wg#828 PR-URL: #45362 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 8f7109a commit 682a730

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

.github/workflows/tools.yml

+16
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,22 @@ jobs:
109109
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
110110
./tools/update-acorn-walk.sh
111111
fi
112+
- id: libuv
113+
subsystem: deps
114+
label: dependencies
115+
run: |
116+
NEW_VERSION=$(gh api repos/libuv/libuv/releases/latest -q '.tag_name|ltrimstr("v")')
117+
VERSION_H="./deps/uv/include/uv/version.h"
118+
CURRENT_MAJOR_VERSION=$(grep "#define UV_VERSION_MAJOR" $VERSION_H | sed -n "s/^.*MAJOR \(.*\)/\1/p")
119+
CURRENT_MINOR_VERSION=$(grep "#define UV_VERSION_MINOR" $VERSION_H | sed -n "s/^.*MINOR \(.*\)/\1/p")
120+
CURRENT_PATCH_VERSION=$(grep "#define UV_VERSION_PATCH" $VERSION_H | sed -n "s/^.*PATCH \(.*\)/\1/p")
121+
CURRENT_SUFFIX_VERSION=$(grep "#define UV_VERSION_SUFFIX" $VERSION_H | sed -n "s/^.*SUFFIX \"\(.*\)\"/\1/p")
122+
SUFFIX_STRING=$([[ -z "$CURRENT_SUFFIX_VERSION" ]] && echo "" || echo "-$CURRENT_SUFFIX_VERSION")
123+
CURRENT_VERSION="$CURRENT_MAJOR_VERSION.$CURRENT_MINOR_VERSION.$CURRENT_PATCH_VERSION$SUFFIX_STRING"
124+
if [ "$NEW_VERSION" != "$CURRENT_VERSION" ]; then
125+
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
126+
./tools/dep_updaters/update-libuv.sh "$NEW_VERSION"
127+
fi
112128
steps:
113129
- uses: actions/checkout@v3
114130
with:

tools/dep_updaters/README.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Dependency update scripts
2+
3+
This folder contains scripts used to automatically update a Node.js dependency.
4+
These scripts are usually run by CI (see `.github/workflows/tools.yml`) in order
5+
to download a new dependency version, and replace the old version with it.
6+
7+
Since these scripts only update to the upstream code, changes might be needed in
8+
this repository in order to successfully update (e.g: changing API calls to
9+
conform to upstream changes, updating GYP build files, etc.)
10+
11+
## libuv
12+
13+
The `update-libuv.sh` script takes the target version to update as its only
14+
argument, downloads it from the [GitHub repo](https://github.com/libuv/libuv)
15+
and uses it to replace the contents of `deps/uv/`. The contents are replaced
16+
entirely except for the `*.gyp` and `*.gypi` build files, which are part of the
17+
Node.js build definitions and are not present in the upstream repo.
18+
19+
For example, in order to update to version `1.44.2`, the following command can
20+
be run:
21+
22+
```bash
23+
./tools/dep_updaters/update-libuv.sh 1.44.2
24+
```
25+
26+
Once the script has run (either manually, or by CI in which case a PR will have
27+
been created with the changes), do the following:
28+
29+
1. Check the [changelog](https://github.com/libuv/libuv/blob/v1.x/ChangeLog) for
30+
things that might require changes in Node.js.
31+
2. If necessary, update `common.gypi` and `uv.gyp` with build-related changes.
32+
3. Check that Node.js compiles without errors and the tests pass.
33+
4. Create a commit for the update and in the commit message include the
34+
important/relevant items from the changelog (see [`c61870c`][] for an
35+
example).
36+
37+
[`c61870c`]: https://github.com/nodejs/node/commit/c61870c376e2f5b0dbaa939972c46745e21cdbdd

tools/dep_updaters/update-libuv.sh

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/sh
2+
set -e
3+
# Shell script to update libuv in the source tree to a specific version
4+
5+
BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd)
6+
DEPS_DIR="$BASE_DIR/deps"
7+
LIBUV_VERSION=$1
8+
9+
if [ "$#" -le 0 ]; then
10+
echo "Error: please provide an libuv version to update to"
11+
echo " e.g. $0 1.44.2"
12+
exit 1
13+
fi
14+
15+
echo "Making temporary workspace..."
16+
17+
WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp')
18+
19+
cleanup () {
20+
EXIT_CODE=$?
21+
[ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE"
22+
exit $EXIT_CODE
23+
}
24+
25+
trap cleanup INT TERM EXIT
26+
27+
cd "$WORKSPACE"
28+
29+
echo "Fetching libuv source archive..."
30+
curl -sL "https://api.github.com/repos/libuv/libuv/tarball/v$LIBUV_VERSION" | tar xzf -
31+
mv libuv-libuv-* uv
32+
33+
echo "Replacing existing libuv (except GYP build files)"
34+
mv "$DEPS_DIR/uv/"*.gyp "$DEPS_DIR/uv/"*.gypi "$WORKSPACE/uv/"
35+
rm -rf "$DEPS_DIR/uv"
36+
mv "$WORKSPACE/uv" "$DEPS_DIR/"
37+
38+
echo "All done!"
39+
echo ""
40+
echo "Please git add uv, commit the new version:"
41+
echo ""
42+
echo "$ git add -A deps/uv"
43+
echo "$ git commit -m \"deps: update libuv to $LIBUV_VERSION\""
44+
echo ""

0 commit comments

Comments
 (0)