Skip to content

Commit

Permalink
tools: move update-undici.sh to dep_updaters and create maintain md
Browse files Browse the repository at this point in the history
PR-URL: #47380
Refs: nodejs/security-wg#828
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Paolo Insogna <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
marco-ippolito authored and danielleadams committed Jul 6, 2023
1 parent f157893 commit ad2f78c
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 20 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,10 @@ jobs:
subsystem: deps
label: dependencies
run: |
NEW_VERSION=$(npm view undici dist-tags.latest)
CURRENT_VERSION=$(node -p "require('./deps/undici/src/package.json').version")
if [ "$NEW_VERSION" != "$CURRENT_VERSION" ]; then
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
./tools/update-undici.sh
fi
./tools/dep_updaters/update-undici.sh > temp-output
cat temp-output
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
rm temp-output
- id: postject
subsystem: deps,test
label: test
Expand Down
7 changes: 3 additions & 4 deletions doc/contributing/maintaining-brotli.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Maintaining brotli

The [brotli](https://github.com/google/brotli) dependency is used for
The [brotli](https://github.com/google/brotli) dependency is used for
the homonym generic-purpose lossless compression algorithm.

## Updating brotli
Expand All @@ -10,17 +10,16 @@ brotli source files.

Check that Node.js still builds and tests.

## Committing postject
## Committing brotli

1. Add brotli:
```console
$ git add deps/brotli
```
2. Commit the changes: `git commit`.
3. Add a message like:

```text
deps,test: update brotli to <version>
deps: update brotli to <version>

Updated as described in doc/contributing/maintaining-brotli.md.
```
3 changes: 3 additions & 0 deletions doc/contributing/maintaining-http.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ more control is required. The current plan is for the following APIs:
Fetch-based API. As this gets worked out we will discuss which
APIs to expose in the Node.js API surface.

For info see [maintaining undici][].

### Server APIs

For the server APIs we do not yet have a clear path, other than wanting
Expand Down Expand Up @@ -116,3 +118,4 @@ The low-level implementation of
is based on [nghttp2](https://nghttp2.org/). See [maintaining nghttp2][].

[maintaining nghttp2]: ./maintaining-nghttp2.md
[maintaining undici]: ./maintaining-undici.md
1 change: 0 additions & 1 deletion doc/contributing/maintaining-postject.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Check that Node.js still builds and tests.
```
2. Commit the changes: `git commit`.
3. Add a message like:

```text
deps,test: update postject to <version>

Expand Down
25 changes: 25 additions & 0 deletions doc/contributing/maintaining-undici.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Maintaining undici

The [undici](https://github.com/nodejs/undici) dependency is
an HTTP/1.1 client, written from scratch for Node.js.

## Updating undici

The `tools/dep_updaters/update-undici.sh` script automates the update of the
undici source files.

Check that Node.js still builds and tests.

## Committing undici

1. Add undici:
```console
$ git add deps/undici
```
2. Commit the changes: `git commit`.
3. Add a message like:
```text
deps: update undici to <version>

Updated as described in doc/contributing/maintaining-undici.md.
```
30 changes: 21 additions & 9 deletions tools/update-undici.sh → tools/dep_updaters/update-undici.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,22 @@

set -ex

cd "$( dirname "$0" )/.." || exit
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 undici dist-tags.latest)
CURRENT_VERSION=$("$NODE" -p "require('./deps/undici/src/package.json').version")

echo "Comparing $NEW_VERSION with $CURRENT_VERSION"

if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
echo "Skipped because Undici is on the latest version."
exit 0
fi

cd "$( dirname "$0" )/../.." || exit
rm -rf deps/undici/src
rm -f deps/undici/undici.js

Expand All @@ -16,25 +31,18 @@ rm -f deps/undici/undici.js
mkdir undici-tmp
cd undici-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 undici
cd node_modules/undici
"$NODE" "$NPM" run build:node
# get the new version of undici
UNDICI_VERSION=$("$NODE" -p "require('./package.json').version")
# update this version information in src/undici_version.h
FILE_PATH="$ROOT/src/undici_version.h"
echo "// This is an auto generated file, please do not edit." > "$FILE_PATH"
echo "// Refer to tools/update-undici.sh" >> "$FILE_PATH"
echo "#ifndef SRC_UNDICI_VERSION_H_" >> "$FILE_PATH"
echo "#define SRC_UNDICI_VERSION_H_" >> "$FILE_PATH"
echo "#define UNDICI_VERSION \"$UNDICI_VERSION\"" >> "$FILE_PATH"
echo "#define UNDICI_VERSION \"$NEW_VERSION\"" >> "$FILE_PATH"
echo "#endif // SRC_UNDICI_VERSION_H_" >> "$FILE_PATH"
)

Expand All @@ -43,3 +51,7 @@ mv deps/undici/src/undici-fetch.js deps/undici/undici.js
cp deps/undici/src/LICENSE deps/undici/LICENSE

rm -rf undici-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"

0 comments on commit ad2f78c

Please sign in to comment.