From f10cfb22991af4b7f89f02515df82c55c7b989e1 Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Fri, 18 Oct 2024 08:48:17 -0700 Subject: [PATCH] chore: Migrate to github actions. (#305) --- .github/actions/publish-docs/action.yml | 16 +++++++ .github/actions/publish-npm/action.yml | 20 +++++++++ .github/workflows/ci.yml | 41 ++++++++++++++++++ .github/workflows/lint-pr-title.yml | 12 ++++++ .github/workflows/release-please.yml | 57 +++++++++++++++++++++++++ .gitignore | 1 + .release-please-manifest.json | 3 ++ docs/Makefile | 34 --------------- docs/doc.md | 7 --- docs/tsconfig.json | 12 ------ docs/typedoc.js | 18 -------- package.json | 6 ++- release-please-config.json | 10 +++++ scripts/publish-npm.sh | 11 +++++ typedoc.json | 17 ++++++++ typings.d.ts | 16 +++++-- 16 files changed, 204 insertions(+), 77 deletions(-) create mode 100644 .github/actions/publish-docs/action.yml create mode 100644 .github/actions/publish-npm/action.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/lint-pr-title.yml create mode 100644 .github/workflows/release-please.yml create mode 100644 .release-please-manifest.json delete mode 100644 docs/Makefile delete mode 100644 docs/doc.md delete mode 100644 docs/tsconfig.json delete mode 100644 docs/typedoc.js create mode 100644 release-please-config.json create mode 100755 scripts/publish-npm.sh create mode 100644 typedoc.json diff --git a/.github/actions/publish-docs/action.yml b/.github/actions/publish-docs/action.yml new file mode 100644 index 00000000..6b5e4187 --- /dev/null +++ b/.github/actions/publish-docs/action.yml @@ -0,0 +1,16 @@ +name: Publish Documentation +description: 'Publish documentation to github pages.' + +inputs: + github_token: + description: 'The github token to use for committing' + required: true + +runs: + using: composite + steps: + - uses: launchdarkly/gh-actions/actions/publish-pages@publish-pages-v1.0.2 + name: 'Publish to Github pages' + with: + docs_path: docs + github_token: ${{ inputs.github_token }} diff --git a/.github/actions/publish-npm/action.yml b/.github/actions/publish-npm/action.yml new file mode 100644 index 00000000..92fed566 --- /dev/null +++ b/.github/actions/publish-npm/action.yml @@ -0,0 +1,20 @@ +name: Publish to NPM +description: Publish an npm package. +inputs: + prerelease: + description: 'Is this a prerelease. If so, then the latest tag will not be updated in npm.' + required: false + dry-run: + description: 'Is this a dry run. If so no package will be published.' + required: false + +runs: + using: composite + steps: + - name: Publish + shell: bash + run: | + ./scripts/publish-npm.sh + env: + LD_RELEASE_IS_PRERELEASE: ${{ inputs.prerelease }} + LD_RELEASE_IS_DRYRUN: ${{ inputs.dry-run }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..c8155c7d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,41 @@ +name: Build and Test + +on: + push: + branches: [main] + paths-ignore: + - '**.md' #Do not need to run CI for markdown changes. + pull_request: + branches: [main] + paths-ignore: + - '**.md' + +jobs: + build-test: + strategy: + matrix: + variations: [ + {os: ubuntu-latest, node: latest}, + {os: ubuntu-latest, node: 18} + ] + + runs-on: ${{ matrix.variations.os }} + env: + TEST_SERVICE_PORT: 8000 + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.variations.node }} + registry-url: 'https://registry.npmjs.org' + - name: Install + run: npm install + - name: Test + run: npm test + - name: Lint + run: npm run lint:all + - name: Check typescript + run: npm run check-typescript + - name: Build Docs + run: npm run doc diff --git a/.github/workflows/lint-pr-title.yml b/.github/workflows/lint-pr-title.yml new file mode 100644 index 00000000..4ba79c13 --- /dev/null +++ b/.github/workflows/lint-pr-title.yml @@ -0,0 +1,12 @@ +name: Lint PR title + +on: + pull_request_target: + types: + - opened + - edited + - synchronize + +jobs: + lint-pr-title: + uses: launchdarkly/gh-actions/.github/workflows/lint-pr-title.yml@main diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml new file mode 100644 index 00000000..214f6578 --- /dev/null +++ b/.github/workflows/release-please.yml @@ -0,0 +1,57 @@ +name: Release Please + +on: + push: + branches: + - main + +jobs: + release-please: + runs-on: ubuntu-latest + outputs: + release_created: ${{ steps.release.outputs.release_created }} + steps: + - uses: googleapis/release-please-action@v4 + id: release + with: + token: ${{secrets.GITHUB_TOKEN}} + + publish-package: + runs-on: ubuntu-latest + needs: ['release-please'] + permissions: + id-token: write + contents: write + if: ${{ needs.release-please.outputs.release_created == 'true' }} + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 20.x + registry-url: 'https://registry.npmjs.org' + + - uses: launchdarkly/gh-actions/actions/release-secrets@release-secrets-v1.2.0 + name: 'Get NPM token' + with: + aws_assume_role: ${{ vars.AWS_ROLE_ARN }} + ssm_parameter_pairs: '/production/common/releasing/npm/token = NODE_AUTH_TOKEN' + + - name: Install Dependencies + run: npm install + + - id: publish-npm + name: Publish NPM Package + uses: ./.github/actions/publish-npm + with: + dry-run: 'false' + prerelease: 'false' + + - name: Build Documentation + run: npm run doc + + - id: publish-docs + name: Publish Documentation + uses: ./.github/actions/publish-docs + with: + github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index d9dede77..c1a5fb4b 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ lib test-types.js docs/build/ package-lock.json +docs/ diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 00000000..9dc6cef9 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "3.4.0" +} diff --git a/docs/Makefile b/docs/Makefile deleted file mode 100644 index c773c30e..00000000 --- a/docs/Makefile +++ /dev/null @@ -1,34 +0,0 @@ - -# The TypeDoc build for launchdarkly-js-client-sdk is more complicated than for ldclient-node because launchdarkly-js-client-sdks takes -# some of its types from launchdarkly-js-sdk-common. TypeDoc unfortunately does not understand the directive -# "export * from 'launchdarkly-js-sdk-common'" - so, by default, even though it does see the common types (like -# LDUser), it will not include them in the output. -# -# The current solution is to run TypeDoc on a hacked-together file that puts all of the types directly -# into one package. The sed commands below create this temporary declaration file by taking the types file -# from launchdarkly-js-client-sdk and replacing the launchdarkly-js-sdk-common imports with the actual contents of the -# launchdarkly-js-sdk-common module. We then run TypeDoc from the docs directory, which contains its own -# tsconfig.json that points to the temporarily file instead of the original files. -# - -.PHONY: html prepare - -html: prepare - ../node_modules/.bin/typedoc --options typedoc.js - mv before-typedoc-package.json ../package.json - mv before-typedoc-package-lock.json ../package-lock.json - if [ -n "$(LD_RELEASE_DOCS_DIR)" ]; then cp -r build/html/* "$(LD_RELEASE_DOCS_DIR)"; fi - -prepare: - cp ../package.json before-typedoc-package.json - cp ../package-lock.json before-typedoc-package-lock.json - cd .. && npm install "typedoc@0.23.17" - rm -rf build - mkdir build - @# Extract the whole module declaration from launchdarkly-js-sdk-common, then remove the first and last lines - sed -n '/^declare module/,/^}/p' ../node_modules/launchdarkly-js-sdk-common/typings.d.ts | \ - sed '1d;$$d' \ - >build/common-excerpt - @# Replace the block from DOCBUILD-START-REPLACE to DOCBUILD-END-REPLACE with that excerpt - sed -e '/DOCBUILD-END-REPLACE/r build/common-excerpt' ../typings.d.ts | \ - sed -e '/DOCBUILD-START-REPLACE/,/DOCBUILD-END-REPLACE/d' >build/typings.d.ts diff --git a/docs/doc.md b/docs/doc.md deleted file mode 100644 index 30d247ce..00000000 --- a/docs/doc.md +++ /dev/null @@ -1,7 +0,0 @@ - -This is the API reference for the LaunchDarkly SDK for browser JavaScript. - -In typical usage, you will call {@link initialize} once at startup time to obtain an instance of -{@link LDClient}, which provides access to all of the SDK's functionality. - -For more information, see the [SDK reference guide](https://docs.launchdarkly.com/sdk/client-side/javascript). diff --git a/docs/tsconfig.json b/docs/tsconfig.json deleted file mode 100644 index 9374e161..00000000 --- a/docs/tsconfig.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "strict": true, - "lib": [ - "es6" - ] - }, - "files": [ - "build/typings.d.ts" - ] -} diff --git a/docs/typedoc.js b/docs/typedoc.js deleted file mode 100644 index 56169880..00000000 --- a/docs/typedoc.js +++ /dev/null @@ -1,18 +0,0 @@ - -// Note that the format of this file is barely documented on the TypeDoc site. In general, -// the properties are equivalent to the command-line options described here: -// https://typedoc.org/api/ - -let version = process.env.VERSION; -if (!version) { - const package = require('../package.json'); - version = package.version; -} - -module.exports = { - out: './build/html', - name: 'LaunchDarkly JavaScript SDK (' + version + ')', - readme: 'doc.md', - entryPointStrategy: 'resolve', // Allows us to specify the specific entrypoints. - entryPoints: ["./build/typings.d.ts"] // This is the updated version created by the makefile. -}; diff --git a/package.json b/package.json index 2f961c0b..581ddb2c 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "test:junit": "cross-env NODE_ENV=test jest --testResultsProcessor jest-junit", "check-typescript": "node_modules/typescript/bin/tsc", "clean": "rimraf dist/**", - "prepublishOnly": "npm run build:min" + "prepublishOnly": "npm run build:min", + "doc": "typedoc" }, "devDependencies": { "@babel/cli": "^7.19.3", @@ -72,7 +73,8 @@ "rollup-plugin-node-globals": "^1.4.0", "rollup-plugin-terser": "^7.0.2", "sinon": "^14.0.0", - "typescript": "^4.8.4", + "typescript": "~5.4.5", + "typedoc": "^0.25.13", "@types/estree": "^1.0.0" }, "dependencies": { diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 00000000..f1f48ba8 --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,10 @@ +{ + "bootstrap-sha": "4d323c5e7cd7d509cfeb1be3a7446b10d94697a6", + "packages": { + ".": { + "release-type": "node", + "include-v-in-tag": false, + "include-component-in-tag": false + } + } +} diff --git a/scripts/publish-npm.sh b/scripts/publish-npm.sh new file mode 100755 index 00000000..69196bdf --- /dev/null +++ b/scripts/publish-npm.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +if $LD_RELEASE_IS_DRYRUN ; then + echo "Doing a dry run of publishing." +else + if $LD_RELEASE_IS_PRERELEASE ; then + echo "Publishing with prerelease tag." + npm publish --tag prerelease --provenance --access public || { echo "npm publish failed" >&2; exit 1; } + else + npm publish --provenance --access public || { echo "npm publish failed" >&2; exit 1; } + fi +fi diff --git a/typedoc.json b/typedoc.json new file mode 100644 index 00000000..c7ff2419 --- /dev/null +++ b/typedoc.json @@ -0,0 +1,17 @@ +{ + "$schema": "https://typedoc.org/schema.json", + "name": "launchdarkly-js-client-sdk", + "includeVersion": true, + "entryPoints": [ + "typings.d.ts", + ], + "readme": "none", + "visibilityFilters": { + "protected": false, + "private": false, + "inherited": true, + "external": true, + "@alpha": false, + "@beta": false + } +} diff --git a/typings.d.ts b/typings.d.ts index 10e5a3c7..61983382 100644 --- a/typings.d.ts +++ b/typings.d.ts @@ -1,7 +1,16 @@ -// Put top level documentation into docs/doc.md. +/** + * This is the API reference for the LaunchDarkly SDK for browser JavaScript. + * + * In typical usage, you will call {@link initialize} once at startup time to obtain an instance of + * {@link LDClient}, which provides access to all of the SDK's functionality. + * + * For more information, see the [SDK reference guide](https://docs.launchdarkly.com/sdk/client-side/javascript). + * + * @packageDocumentation + */ + declare module 'launchdarkly-js-client-sdk' { -//// DOCBUILD-START-REPLACE (see docs/Makefile) export * from 'launchdarkly-js-sdk-common'; import { BasicLoggerOptions, @@ -10,7 +19,6 @@ declare module 'launchdarkly-js-client-sdk' { LDLogger, LDOptionsBase, } from 'launchdarkly-js-sdk-common'; -//// DOCBUILD-END-REPLACE /** * Creates an instance of the LaunchDarkly client. @@ -133,7 +141,7 @@ declare module 'launchdarkly-js-client-sdk' { * * @param options Configuration for the logger. If no options are specified, the * logger uses `{ level: 'info' }`. - * + * * @example * This example shows how to use `basicLogger` in your SDK options to enable console * logging only at `warn` and `error` levels.