From c63fde116bdeb76f623f6447b37f2028904c56b0 Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Tue, 18 Jun 2024 15:32:58 -0700 Subject: [PATCH] chore: Migrate to github actions and release-please. --- .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 + .ldrelease/config.yml | 25 ----------- .release-please-manifest.json | 3 ++ docs/typedoc.js | 11 ----- package.json | 6 ++- release-please-config.json | 8 ++++ scripts/publish-npm.sh | 11 +++++ typedoc.json | 8 ++++ 13 files changed, 181 insertions(+), 38 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 delete mode 100644 .ldrelease/config.yml create mode 100644 .release-please-manifest.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 0000000..6b5e418 --- /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 0000000..92fed56 --- /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 0000000..7f6bcb4 --- /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 }} + + 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 + env: + JEST_JUNIT_OUTPUT_FILE: "reports/junit/js-test-results.xml" + - 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 0000000..4ba79c1 --- /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 0000000..214f657 --- /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 d9dede7..c1a5fb4 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ lib test-types.js docs/build/ package-lock.json +docs/ diff --git a/.ldrelease/config.yml b/.ldrelease/config.yml deleted file mode 100644 index 4c45778..0000000 --- a/.ldrelease/config.yml +++ /dev/null @@ -1,25 +0,0 @@ -version: 2 - -repo: - public: js-sdk-common - private: js-sdk-common-private - -branches: - - name: main - description: 5.x - - name: 4.x - - name: 3.x - -publications: - - url: https://www.npmjs.com/package/launchdarkly-js-sdk-common - description: npm - -jobs: - - docker: - image: node:12-buster - template: - name: npm - -documentation: - gitHubPages: true - title: LaunchDarkly Javascript SDK Core Components diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..b5e9157 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "5.2.0" +} diff --git a/docs/typedoc.js b/docs/typedoc.js deleted file mode 100644 index ea3de38..0000000 --- a/docs/typedoc.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - out: '/tmp/project-releaser/project/docs/build/html', - exclude: [ - '**/node_modules/**', - 'test-types.ts' - ], - name: "LaunchDarkly Javascript SDK Core Components (4.0.2)", - readme: 'none', // don't add a home page with a copy of README.md - entryPoints: "/tmp/project-releaser/project/typings.d.ts", - entryPointStrategy: "expand" -}; diff --git a/package.json b/package.json index b6b8140..b8e3764 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ "format:test:md": "prettier --parser markdown --ignore-path .prettierignore --list-different '*.md'", "format:test:js": "prettier --ignore-path .prettierignore --list-different 'src/**/*.js'", "test": "cross-env NODE_ENV=test jest", - "check-typescript": "node_modules/typescript/bin/tsc" + "check-typescript": "tsc", + "doc": "typedoc" }, "devDependencies": { "@babel/cli": "^7.8.4", @@ -42,7 +43,8 @@ "launchdarkly-js-test-helpers": "1.1.0", "prettier": "1.11.1", "readline-sync": "^1.4.9", - "typescript": "~4.4.4" + "typescript": "~5.4.5", + "typedoc": "^0.25.13" }, "dependencies": { "base64-js": "^1.3.0", diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..7547500 --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,8 @@ +{ + "bootstrap-sha": "d49ca41718a593c071874950d301f2f00c71a371", + "packages": { + ".": { + "release-type": "node" + } + } +} diff --git a/scripts/publish-npm.sh b/scripts/publish-npm.sh new file mode 100755 index 0000000..69196bd --- /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 0000000..976948e --- /dev/null +++ b/typedoc.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://typedoc.org/schema.json", + "name": "launchdarkly-js-sdk-common", + "includeVersion": true, + "entryPoints": [ + "typings.d.ts", + ] +}