Skip to content

Commit

Permalink
Bump Node to v20 and add .nvmrc (nginx#1627)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
miledxz committed Feb 29, 2024
1 parent 5826418 commit c0fd9ce
Show file tree
Hide file tree
Showing 9 changed files with 1,451 additions and 744 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,15 @@ jobs:
- name: Setup Node.js Environment
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: 18
- run: npm --prefix ${{ github.workspace }}/internal/mode/static/nginx/modules install-ci-test
node-version-file: .nvmrc

- name: Run tests
run: npm --prefix ${{ github.workspace }}/internal/mode/static/nginx/modules install-ci-test

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@54bcd8715eee62d40e33596ef5e8f0f48dbbccab # v4.1.0
with:
token: ${{ secrets.CODECOV_TOKEN }}

binary:
name: Build Binary
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
- main
pull_request:

defaults:
run:
shell: bash

concurrency:
group: ${{ github.ref_name }}-lint
cancel-in-progress: true
Expand Down Expand Up @@ -43,6 +47,11 @@ jobs:
run: |
echo "version=$(jq -r .devDependencies.prettier ${{ github.workspace }}/internal/mode/static/nginx/modules/package.json)" >> $GITHUB_OUTPUT
- name: Setup Node.js Environment
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version-file: .nvmrc

- name: Run Prettier on NJS code
id: prettier-run
uses: rutajdash/prettier-cli-action@d42c4325a3b344f3bd4be482bc34de521998d557 # v1.0.2
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
21 changes: 11 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
VERSION = edge
GIT_COMMIT = $(shell git rev-parse HEAD || echo "unknown")
DATE = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
MANIFEST_DIR = $(shell pwd)/deploy/manifests
CHART_DIR = $(shell pwd)/deploy/helm-chart
MANIFEST_DIR = $(CURDIR)/deploy/manifests
CHART_DIR = $(CURDIR)/deploy/helm-chart
NGINX_CONF_DIR = internal/mode/static/nginx/conf
NJS_DIR = internal/mode/static/nginx/modules/src
NGINX_DOCKER_BUILD_PLUS_ARGS = --secret id=nginx-repo.crt,src=nginx-repo.crt --secret id=nginx-repo.key,src=nginx-repo.key
BUILD_AGENT=local
TELEMETRY_REPORT_PERIOD = 24h # also configured in goreleaser.yml
GW_API_VERSION = 1.0.0
INSTALL_WEBHOOK = false
NODE_VERSION = $(shell cat .nvmrc)

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

.PHONY: vet
vet: ## Run go vet against code
go vet ./...

.PHONY: lint
lint: ## Run golangci-lint against code
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
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

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

.PHONY: lint-helm
lint-helm: ## Run the helm chart linter
Expand Down
8 changes: 7 additions & 1 deletion internal/mode/static/nginx/modules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ This directory contains the [njs](http://nginx.org/en/docs/njs/) modules for NGI

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

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

If you use nvm, you can switch to the recommended version of Node.js by running:

```shell
nvm use
```

Once you've installed Node.js and npm, run `npm install` in this directory to install the rest of the project's
dependencies.

Expand Down
Loading

0 comments on commit c0fd9ce

Please sign in to comment.