Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/actions/setup-node-npm/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Set up Node.js and npm
description: >
Installs the latest release of the Node.js version in .nvmrc and npm 12, and
applies the repo's .npmrc supply-chain settings to every npm command in the
job, including the ones run in sub-projects. Jobs that test on another Node
version install and build with this first, then switch Node with
actions/setup-node only to run the tests.

inputs:
cache:
description: "Package manager to cache downloads for ('npm'), or '' for no cache. The release and GHR backfill jobs use '' so a cache can't affect what gets published."
required: false
default: npm
cache-dependency-path:
description: Lockfile(s) the cache key is computed from.
required: false
default: package-lock.json

runs:
using: composite
steps:
# .nvmrc gives only the major version. check-latest picks its newest
# release, so CI gets Node.js patches without the file changing.
# By default setup-node also enables the npm cache when package.json's
# devEngines names npm, even with cache: ''. package-manager-cache: false
# turns that off, so only cache: npm enables it.
- name: Set up Node.js (version from .nvmrc)
uses: actions/setup-node@v7
with:
node-version-file: .nvmrc
check-latest: true
cache: ${{ inputs.cache }}
Comment thread
Copilot marked this conversation as resolved.
Resolved
package-manager-cache: false
cache-dependency-path: ${{ inputs.cache-dependency-path }}

- name: Install npm and apply the repo's npm settings
shell: bash
env:
# Installs the newest npm of this major version that is at least
# min-release-age days old (see scripts/pick-npm-version.js).
NPM_MAJOR: '12'
run: |
NPM_VERSION=$(node "$GITHUB_WORKSPACE/scripts/pick-npm-version.js" "$NPM_MAJOR")
npm install -g "npm@${NPM_VERSION}"
# Sub-projects read the repo's .npmrc through symlinks. The user config
# also covers projects created during the job, such as
# tests/react-native-metro/.sdk.
cat "$GITHUB_WORKSPACE/.npmrc" >> ~/.npmrc
# In CI, an install script nobody approved or denied fails the install
# instead of only printing a warning.
echo "strict-allow-scripts=true" >> ~/.npmrc
# Forces the public registry even if an .npmrc sets another one. Env
# vars override every .npmrc, but not --registry flags or
# @scope:registry settings (with a lockfile, a scoped registry fails
# the install: allow-remote blocks the mismatched URL).
echo "npm_config_registry=https://registry.npmjs.org/" >> "$GITHUB_ENV"
echo "Node $(node --version), npm $(npm --version)"
10 changes: 6 additions & 4 deletions .github/workflows/ghr_backfill.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ jobs:
packages: write
steps:
- name: Checkout branch
uses: actions/checkout@v4
uses: actions/checkout@v7
with:
persist-credentials: false

- name: Set up Node
uses: actions/setup-node@v4
# No npm cache, so nothing from an earlier run can affect what gets
# published to GHR (same as release.yml).
- name: Set up Node and npm
uses: ./.github/actions/setup-node-npm
with:
node-version: 18
cache: ''

- name: Configure GitHub Package Registry auth
run: echo "//npm.pkg.github.com/:_authToken=\${NODE_AUTH_TOKEN}" >> ~/.npmrc
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/integration_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v7
Comment thread
arnica-github-connector[bot] marked this conversation as resolved.
Resolved
with:
# You should create a personal access token and store it in your repository
token: ${{ secrets.CI_USER_TOKEN }}
repository: 'optimizely/travisci-tools'
path: 'home/runner/travisci-tools'
ref: 'master'
# Don't leave the PAT on disk. The trigger scripts call the GitHub API
# with curl and the token from env, not through git.
persist-credentials: false
- name: set SDK Branch if PR
env:
HEAD_REF: ${{ github.head_ref }}
Expand Down
155 changes: 84 additions & 71 deletions .github/workflows/javascript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,79 +6,81 @@ on:
pull_request:
branches: [ master ]

# Every job installs and builds with the Node version in .nvmrc and npm 12 from
# .github/actions/setup-node-npm, which also applies the .npmrc supply-chain
# settings. Jobs that test other Node versions switch Node only to
# run the tests.
#
# Checkouts use persist-credentials: false so the token isn't left on disk for
# later steps. No job runs authenticated git commands after checkout.

jobs:
lint_markdown_files:
uses: optimizely/javascript-sdk/.github/workflows/lint_markdown.yml@master

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Node
uses: actions/setup-node@v3
- uses: actions/checkout@v7
Comment thread
arnica-github-connector[bot] marked this conversation as resolved.
Resolved
with:
node-version: 16
cache-dependency-path: ./package-lock.json
cache: 'npm'
persist-credentials: false
- uses: ./.github/actions/setup-node-npm
- name: Install dependencies
run: npm ci
- name: Run linting
working-directory: .
run: |
npm install
npm run lint
run: npm run lint

typescript_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Node
uses: actions/setup-node@v3
- uses: actions/checkout@v7
Comment thread
arnica-github-connector[bot] marked this conversation as resolved.
Resolved
with:
node-version: 20
cache-dependency-path: ./package-lock.json
cache: 'npm'
persist-credentials: false
- uses: ./.github/actions/setup-node-npm
with:
cache-dependency-path: |
package-lock.json
examples/typescript/package-lock.json
- name: Install dependencies
run: npm ci
- name: Run TypeScript example
working-directory: .
run: |
npm install
npm run test-typescript
run: npm run test-typescript

commonjs_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Node 20 (build)
uses: actions/setup-node@v3
- uses: actions/checkout@v7
Comment thread
arnica-github-connector[bot] marked this conversation as resolved.
Resolved
with:
node-version: 20
cache-dependency-path: ./package-lock.json
cache: 'npm'
- name: Build and pack SDK
persist-credentials: false
- uses: ./.github/actions/setup-node-npm
- name: Build, pack, and install the SDK in the example
run: |
npm install
npm ci
npm pack
npm run test-commonjs -- --skip-build --skip-run
- name: Set up Node 18 (runtime test)
uses: actions/setup-node@v3
uses: actions/setup-node@v7
with:
node-version: '18'
node-version: 18
- name: Run CommonJS example
run: npm run test-commonjs -- --skip-build
working-directory: examples/node-commonjs
run: npm start

react_native_metro_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Node
uses: actions/setup-node@v3
- uses: actions/checkout@v7
Comment thread
arnica-github-connector[bot] marked this conversation as resolved.
Resolved
with:
persist-credentials: false
- uses: ./.github/actions/setup-node-npm
with:
node-version: 22
cache-dependency-path: |
./package-lock.json
./tests/react-native-metro/fixtures/*/package-lock.json
cache: 'npm'
package-lock.json
tests/react-native-metro/fixtures/*/package-lock.json
- name: Install dependencies
run: npm ci
- name: Run React Native Metro tests
run: |
npm install
npm run test-rn-metro
run: npm run test-rn-metro

integration_tests:
uses: optimizely/javascript-sdk/.github/workflows/integration_test.yml@master
Expand Down Expand Up @@ -106,19 +108,17 @@ jobs:
USE_LOCAL_BROWSER: 'false'
TEST_BROWSER: ${{ matrix.browser }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v7
Comment thread
arnica-github-connector[bot] marked this conversation as resolved.
Resolved
with:
persist-credentials: false
# Browser and UMD tests run from tests/browser (see its README), which needs Node 22.23.4+.
- name: Set up Node
uses: actions/setup-node@v3
- uses: ./.github/actions/setup-node-npm
with:
node-version: 22
cache: 'npm'
cache-dependency-path: |
./package-lock.json
./tests/browser/package-lock.json
package-lock.json
tests/browser/package-lock.json
- name: Install SDK dependencies
working-directory: .
run: npm install
run: npm ci
- name: Install browser test dependencies
id: browser-deps
working-directory: ./tests/browser
Expand All @@ -137,40 +137,52 @@ jobs:
generate_messages_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Node
uses: actions/setup-node@v3
- uses: actions/checkout@v7
Comment thread
arnica-github-connector[bot] marked this conversation as resolved.
Resolved
with:
node-version: 20
cache-dependency-path: ./package-lock.json
cache: 'npm'
persist-credentials: false
- uses: ./.github/actions/setup-node-npm
- name: Install dependencies
run: npm ci
- name: Test generate-messages script
run: |
npm install
node scripts/test-generate-messages.js
run: node scripts/test-generate-messages.js

unit_tests:
runs-on: ubuntu-latest
strategy:
matrix:
node: ['18', '20', '22', '24']
env:
# The Coveralls action, for the Coveralls Parallel step below and the
# finish job. It's a third-party action, so it's pinned to a full commit
# SHA: a tag can be moved to other code (as in the 2025
# tj-actions/changed-files attack), and both steps get the GITHUB_TOKEN.
# GitHub's own actions (actions/*) use tags. Nothing updates the pin
# automatically. To upgrade, use the commit SHA of the new release tag and
# update the version comment.
# `uses:` doesn't accept ${{ }} expressions, so the steps can't read this
# env var. They reuse the value through the YAML anchor &coveralls-action.
COVERALLS_ACTION: &coveralls-action coverallsapp/github-action@8d6379e14d29928660c4ba802d8e85393440b329 # v2.3.8
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v7
Comment thread
arnica-github-connector[bot] marked this conversation as resolved.
Resolved
with:
persist-credentials: false
# Install with the Node version in .nvmrc and npm 12, then run the tests on
# the matrix version.
- uses: ./.github/actions/setup-node-npm
- name: Install dependencies
run: npm ci
- name: Set up Node ${{ matrix.node }}
uses: actions/setup-node@v3
uses: actions/setup-node@v7
with:
node-version: ${{ matrix.node }}
cache: 'npm'
cache-dependency-path: ./package-lock.json
check-latest: true
- name: Unit tests
working-directory: .
run: |
npm install
npm run coveralls
run: npm run coveralls
# The pinned Coveralls action from this job's env (see the comment there).
- name: Coveralls Parallel
uses: coverallsapp/github-action@master
uses: *coveralls-action
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./coverage/lcov.info
flag-name: run-${{ matrix.node }}
# This is a parallel build so need this
Expand All @@ -184,11 +196,12 @@ jobs:
needs: unit_tests
runs-on: ubuntu-latest
steps:
# The pinned Coveralls action from the unit_tests job's env (see the
# comment there).
- name: Coveralls Finished
uses: coverallsapp/github-action@master
uses: *coveralls-action
with:
github-token: ${{ secrets.github_token }}
path-to-lcov: ./coverage/lcov.info
parallel-finished: true
base-path: .

4 changes: 3 additions & 1 deletion .github/workflows/lint_markdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v7
Comment thread
arnica-github-connector[bot] marked this conversation as resolved.
Resolved
with:
persist-credentials: false
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
Expand Down
20 changes: 13 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ jobs:
environment: npm
steps:
- name: Checkout branch
uses: actions/checkout@v4
uses: actions/checkout@v7
with:
persist-credentials: false

- name: Setup Node
uses: actions/setup-node@v4
# The Node version in .nvmrc and npm 12 (new enough for OIDC trusted
# publishing), with the .npmrc supply-chain settings. cache: '' means no
# npm cache, so nothing from an earlier run (e.g. a pull request) can
# affect what gets published.
- name: Set up Node and npm
uses: ./.github/actions/setup-node-npm
with:
node-version: 22

- name: Upgrade npm for OIDC support
run: npm install -g npm@latest
cache: ''

# Configure auth for GHR only. npm registry auth is handled by OIDC
# (no .npmrc token entry needed — omitting registry-url from setup-node
Expand All @@ -41,6 +42,11 @@ jobs:
- name: Install dependencies
run: npm ci --ignore-scripts

# Don't build the published artifact from packages whose registry
# signatures don't verify.
- name: Verify package signatures
run: npm audit signatures

# Test, build, and pack a single tarball. Both registries publish this
# same artifact, so npm and GHR receive byte-identical bytes and the test
# suite runs only once. --ignore-scripts on pack avoids a rebuild.
Expand Down
Loading
Loading