Skip to content

Commit c0fd9ce

Browse files
committed
Bump Node to v20 and add .nvmrc (nginx#1627)
Problem: We don't have a way to keep track of Node version and we're not using the latest LTS Solution: Add .nvmrc, set it to v20 and use it in the Workflows and Makefile. Also uploads code coverage for the modules.
1 parent 5826418 commit c0fd9ce

File tree

9 files changed

+1451
-744
lines changed

9 files changed

+1451
-744
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,15 @@ jobs:
9090
- name: Setup Node.js Environment
9191
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
9292
with:
93-
node-version: 18
94-
- run: npm --prefix ${{ github.workspace }}/internal/mode/static/nginx/modules install-ci-test
93+
node-version-file: .nvmrc
94+
95+
- name: Run tests
96+
run: npm --prefix ${{ github.workspace }}/internal/mode/static/nginx/modules install-ci-test
97+
98+
- name: Upload coverage reports to Codecov
99+
uses: codecov/codecov-action@54bcd8715eee62d40e33596ef5e8f0f48dbbccab # v4.1.0
100+
with:
101+
token: ${{ secrets.CODECOV_TOKEN }}
95102

96103
binary:
97104
name: Build Binary

.github/workflows/lint.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ on:
66
- main
77
pull_request:
88

9+
defaults:
10+
run:
11+
shell: bash
12+
913
concurrency:
1014
group: ${{ github.ref_name }}-lint
1115
cancel-in-progress: true
@@ -43,6 +47,11 @@ jobs:
4347
run: |
4448
echo "version=$(jq -r .devDependencies.prettier ${{ github.workspace }}/internal/mode/static/nginx/modules/package.json)" >> $GITHUB_OUTPUT
4549
50+
- name: Setup Node.js Environment
51+
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
52+
with:
53+
node-version-file: .nvmrc
54+
4655
- name: Run Prettier on NJS code
4756
id: prettier-run
4857
uses: rutajdash/prettier-cli-action@d42c4325a3b344f3bd4be482bc34de521998d557 # v1.0.2

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20

Makefile

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
VERSION = edge
33
GIT_COMMIT = $(shell git rev-parse HEAD || echo "unknown")
44
DATE = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
5-
MANIFEST_DIR = $(shell pwd)/deploy/manifests
6-
CHART_DIR = $(shell pwd)/deploy/helm-chart
5+
MANIFEST_DIR = $(CURDIR)/deploy/manifests
6+
CHART_DIR = $(CURDIR)/deploy/helm-chart
77
NGINX_CONF_DIR = internal/mode/static/nginx/conf
88
NJS_DIR = internal/mode/static/nginx/modules/src
99
NGINX_DOCKER_BUILD_PLUS_ARGS = --secret id=nginx-repo.crt,src=nginx-repo.crt --secret id=nginx-repo.key,src=nginx-repo.key
1010
BUILD_AGENT=local
1111
TELEMETRY_REPORT_PERIOD = 24h # also configured in goreleaser.yml
1212
GW_API_VERSION = 1.0.0
1313
INSTALL_WEBHOOK = false
14+
NODE_VERSION = $(shell cat .nvmrc)
1415

1516
# go build flags - should not be overridden by the user
1617
GO_LINKER_FlAGS_VARS = -X main.version=${VERSION} -X main.commit=${GIT_COMMIT} -X main.date=${DATE} -X main.telemetryReportPeriod=${TELEMETRY_REPORT_PERIOD}
@@ -24,7 +25,7 @@ NGINX_PLUS_PREFIX ?= $(PREFIX)/nginx-plus## The name of the nginx plus image. Fo
2425
TAG ?= $(VERSION:v%=%)## The tag of the image. For example, 0.3.0
2526
TARGET ?= local## The target of the build. Possible values: local and container
2627
KIND_KUBE_CONFIG=$${HOME}/.kube/kind/config## The location of the kind kubeconfig
27-
OUT_DIR ?= $(shell pwd)/build/out## The folder where the binary will be stored
28+
OUT_DIR ?= $(CURDIR)/build/out## The folder where the binary will be stored
2829
GOARCH ?= amd64## The architecture of the image and/or binary. For example: amd64 or arm64
2930
GOOS ?= linux## The OS of the image and/or binary. For example: linux or darwin
3031
override HELM_TEMPLATE_COMMON_ARGS += --set creator=template --set nameOverride=nginx-gateway## The common options for the Helm template command.
@@ -125,17 +126,17 @@ fmt: ## Run go fmt against code
125126
.PHONY: njs-fmt
126127
njs-fmt: ## Run prettier against the njs httpmatches module
127128
docker run --rm -w /modules \
128-
-v $(PWD)/internal/nginx/modules/:/modules/ \
129-
node:18 \
130-
/bin/bash -c "npm install && npm run format"
129+
-v $(CURDIR)/internal/nginx/modules/:/modules/ \
130+
node:${NODE_VERSION} \
131+
/bin/bash -c "npm ci && npm run format"
131132

132133
.PHONY: vet
133134
vet: ## Run go vet against code
134135
go vet ./...
135136

136137
.PHONY: lint
137138
lint: ## Run golangci-lint against code
138-
docker run --pull always --rm -v $(shell pwd):/nginx-gateway-fabric -w /nginx-gateway-fabric -v $(shell go env GOCACHE):/cache/go -e GOCACHE=/cache/go -e GOLANGCI_LINT_CACHE=/cache/go -v $(shell go env GOPATH)/pkg:/go/pkg golangci/golangci-lint:latest golangci-lint --color always run
139+
docker run --pull always --rm -v $(CURDIR):/nginx-gateway-fabric -w /nginx-gateway-fabric -v $(shell go env GOCACHE):/cache/go -e GOCACHE=/cache/go -e GOLANGCI_LINT_CACHE=/cache/go -v $(shell go env GOPATH)/pkg:/go/pkg golangci/golangci-lint:latest golangci-lint --color always run
139140

140141
.PHONY: unit-test
141142
unit-test: ## Run unit tests for the go code
@@ -148,9 +149,9 @@ unit-test: ## Run unit tests for the go code
148149
.PHONY: njs-unit-test
149150
njs-unit-test: ## Run unit tests for the njs httpmatches module
150151
docker run --rm -w /modules \
151-
-v $(PWD)/internal/mode/static/nginx/modules:/modules/ \
152-
node:18 \
153-
/bin/bash -c "npm install && npm test && npm run clean"
152+
-v $(CURDIR)/internal/mode/static/nginx/modules:/modules/ \
153+
node:${NODE_VERSION} \
154+
/bin/bash -c "npm ci && npm test && npm run clean"
154155

155156
.PHONY: lint-helm
156157
lint-helm: ## Run the helm chart linter

internal/mode/static/nginx/modules/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ This directory contains the [njs](http://nginx.org/en/docs/njs/) modules for NGI
66

77
We recommend using [nvm](https://github.com/nvm-sh/nvm/blob/master/README.md) to install the following dependencies:
88

9-
- [Node.js](https://nodejs.org/en/) (version 1.18)
9+
- [Node.js](https://nodejs.org/en/) (version 20)
1010
- [npm](https://docs.npmjs.com/)
1111

12+
If you use nvm, you can switch to the recommended version of Node.js by running:
13+
14+
```shell
15+
nvm use
16+
```
17+
1218
Once you've installed Node.js and npm, run `npm install` in this directory to install the rest of the project's
1319
dependencies.
1420

0 commit comments

Comments
 (0)