From a2ea5176e42ec877f0c0056719e91e96a0db853d Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Tue, 14 Mar 2023 13:18:51 -0700 Subject: [PATCH 1/4] build: Add release-please configuration. --- .github/workflows/manual-publish-docs.yml | 38 +++++++++++ .github/workflows/manual-publish.yml | 53 +++++++++++++++ .github/workflows/release-please.yml | 80 +++++++++++++++++++++++ .release-please-manifest.json | 0 actions/ci/action.yml | 6 +- actions/full-release/action.yml | 42 ++++++++++++ actions/publish-docs/action.yml | 22 +++++++ actions/publish/action.yml | 25 +++++++ actions/release-secrets/action.yml | 26 ++++++++ packages/sdk/server-node/CHANGELOG.md | 0 packages/shared/common/CHANGELOG.md | 0 packages/shared/sdk-server/CHANGELOG.md | 0 release-please-config.json | 20 ++++++ scripts/doc-name.sh | 5 +- scripts/package-name.sh | 8 +++ scripts/publish-doc.sh | 54 +++++++++++++++ scripts/publish.sh | 12 ++++ 17 files changed, 387 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/manual-publish-docs.yml create mode 100644 .github/workflows/manual-publish.yml create mode 100644 .github/workflows/release-please.yml create mode 100644 .release-please-manifest.json create mode 100644 actions/full-release/action.yml create mode 100644 actions/publish-docs/action.yml create mode 100644 actions/publish/action.yml create mode 100644 actions/release-secrets/action.yml create mode 100644 packages/sdk/server-node/CHANGELOG.md create mode 100644 packages/shared/common/CHANGELOG.md create mode 100644 packages/shared/sdk-server/CHANGELOG.md create mode 100644 release-please-config.json create mode 100755 scripts/package-name.sh create mode 100755 scripts/publish-doc.sh create mode 100755 scripts/publish.sh diff --git a/.github/workflows/manual-publish-docs.yml b/.github/workflows/manual-publish-docs.yml new file mode 100644 index 0000000000..c47664fdca --- /dev/null +++ b/.github/workflows/manual-publish-docs.yml @@ -0,0 +1,38 @@ +on: + workflow_dispatch: + inputs: + workspace_path: + description: 'The workspace to publish docs for' + required: true + default: 'packages/shared/common' + type: choice + options: + - packages/shared/common + - packages/shared/sdk-server + - packages/sdk/server-node +name: Publish Documentation +jobs: + build-publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16.x + registry-url: 'https://registry.npmjs.org' + - name: "Set WORKSPACE_NAME variable" + run: | + WORKSPACE_NAME=$(./scripts/package-name.sh ${{ inputs.workspace_path }}) + echo "WORKSPACE_NAME=$WORKSPACE_NAME" >> $GITHUB_ENV + - id: build + # Build using the same steps from CI. + name: Build and Test + uses: ./actions/ci + with: + workspace_name: ${{ env.WORKSPACE_NAME }} + workspace_path: ${{ inputs.workspace_path }} + - id: publish + name: Publish Documentation + uses: ./actions/publish-docs + with: + workspace_path: ${{ inputs.workspace_path }} diff --git a/.github/workflows/manual-publish.yml b/.github/workflows/manual-publish.yml new file mode 100644 index 0000000000..4185326122 --- /dev/null +++ b/.github/workflows/manual-publish.yml @@ -0,0 +1,53 @@ +name: Publish Package +on: + workflow_dispatch: + inputs: + workspace_path: + description: 'The workspace to publish' + required: true + default: 'packages/shared/common' + type: choice + options: + - packages/shared/common + - packages/shared/sdk-server + - packages/sdk/server-node + prerelease: + description: 'Is this a prerelease. If so, then the latest tag will not be updated in npm.' + type: boolean + required: true + dry_run: + description: 'Is this a dry run. If so no package will be published.' + type: boolean + required: true + +jobs: + build-publish: + runs-on: ubuntu-latest + # Needed to get tokens during publishing. + permissions: + id-token: write + contents: read + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16.x + registry-url: 'https://registry.npmjs.org' + - name: "Set WORKSPACE_NAME variable" + run: | + WORKSPACE_NAME=$(./scripts/package-name.sh ${{ inputs.workspace_path }}) + echo "WORKSPACE_NAME=$WORKSPACE_NAME" >> $GITHUB_ENV + - id: build-and-test + # Build using the same steps from CI. + name: Build and Test + uses: ./actions/ci + with: + workspace_name: ${{ env.WORKSPACE_NAME }} + workspace_path: ${{ inputs.workspace_path }} + - id: publish + name: Publish Package + uses: ./actions/publish + with: + workspace_name: ${{ env.WORKSPACE_NAME }} + prerelease: ${{ inputs.prerelease }} + dry_run: ${{ inputs.dry_run }} diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml new file mode 100644 index 0000000000..9f99d8651c --- /dev/null +++ b/.github/workflows/release-please.yml @@ -0,0 +1,80 @@ +on: + push: + branches: + - main +name: release-please + +jobs: + release-please: + runs-on: ubuntu-latest + outputs: + package-common-released: ${{ steps.release.outputs['packages/shared/common--release_created'] }} + package-sdk-server-released: ${{ steps.release.outputs['packages/shared/sdk-server--release_created'] }} + package-server-node-released: ${{ steps.release.outputs['packages/sdk/server-node--release_created'] }} + steps: + - uses: google-github-actions/release-please-action@v3 + id: release + with: + command: manifest + token: ${{secrets.GITHUB_TOKEN}} + default-branch: main + + release-common: + runs-on: ubuntu-latest + needs: ['release-please'] + permissions: + id-token: write + contents: write + if: ${{ needs.release-please.outputs.package-common-released }} + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16.x + registry-url: 'https://registry.npmjs.org' + - id: release-common + name: Full release of packages/shared/common + uses: ./actions/full-release + with: + workspace_path: packages/shared/common + aws_assume_role: ${{ vars.AWS_ROLE_ARN }} + + release-sdk-server: + runs-on: ubuntu-latest + needs: ['release-please'] + permissions: + id-token: write + contents: write + if: ${{ needs.release-please.outputs.package-sdk-server-released }} + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16.x + registry-url: 'https://registry.npmjs.org' + - id: release-common + name: Full release of packages/shared/sdk-server + uses: ./actions/full-release + with: + workspace_path: packages/shared/sdk-server + aws_assume_role: ${{ vars.AWS_ROLE_ARN }} + + release-server-node: + runs-on: ubuntu-latest + needs: ['release-please'] + permissions: + id-token: write + contents: write + if: ${{ needs.release-please.outputs.package-sdk-server-released }} + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16.x + registry-url: 'https://registry.npmjs.org' + - id: release-common + name: Full release of packages/sdk/server-node + uses: ./actions/full-release + with: + workspace_path: packages/sdk/server-node + aws_assume_role: ${{ vars.AWS_ROLE_ARN }} diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actions/ci/action.yml b/actions/ci/action.yml index e92110e1e4..e980ae1b9d 100644 --- a/actions/ci/action.yml +++ b/actions/ci/action.yml @@ -6,11 +6,11 @@ inputs: # Some commands work on the package name (yarn commands), other require the path (typedoc), # so we supply both. workspace_name: + description: 'Name, from the package.json, of the package to build/test.' required: true - type: string workspace_path: + description: 'Path to the package to release.' required: true - type: string runs: using: composite @@ -23,7 +23,7 @@ runs: shell: bash # Install only the dependencies requires for the specific workspace. run: yarn workspaces focus ${{ inputs.workspace_name }} - + - name: Build shell: bash # This will build the package and its dependencies. diff --git a/actions/full-release/action.yml b/actions/full-release/action.yml new file mode 100644 index 0000000000..120d258676 --- /dev/null +++ b/actions/full-release/action.yml @@ -0,0 +1,42 @@ +name: Build, Test, and Publish +description: 'Execute the full release process for a workspace.' +inputs: + workspace_path: + description: 'Path to the workspace being released.' + required: true + aws_assume_role: + description: 'The ARN of an AWS IAM role to assume. Used to auth with AWS to upload results to S3.' + required: true + + +runs: + using: composite + steps: + - name: 'Set WORKSPACE_NAME variable' + shell: bash + run: | + WORKSPACE_NAME=$(./scripts/package-name.sh ${{ inputs.workspace_path }}) + echo "WORKSPACE_NAME=$WORKSPACE_NAME" >> $GITHUB_ENV + - uses: ./actions/ci + with: + workspace_name: ${{ env.WORKSPACE_NAME }} + workspace_path: ${{ inputs.workspace_path }} + - uses: ./actions/release-secrets + name: "Get NPM token" + with: + aws_assume_role: ${{ inputs.aws_assume_role }} + ssm_parameter_pairs: "/production/common/releasing/npm/token = NODE_AUTH_TOKEN" + - name: Setup .yarnrc.yml + shell: bash + run: | + yarn config set npmScopes.launchdarkly.npmRegistryServer "https://registry.npmjs.org" + yarn config set npmScopes.launchdarkly.npmAlwaysAuth true + yarn config set npmScopes.launchdarkly.npmAuthToken $NODE_AUTH_TOKEN + - uses: ./actions/publish + with: + workspace_name: ${{ env.WORKSPACE_NAME }} + prerelease: false + dry_run: false + - uses: ./actions/publish-docs + with: + workspace_path: ${{ inputs.workspace_path }} diff --git a/actions/publish-docs/action.yml b/actions/publish-docs/action.yml new file mode 100644 index 0000000000..1757b755e5 --- /dev/null +++ b/actions/publish-docs/action.yml @@ -0,0 +1,22 @@ +# This action publishes docs. The docs must have been build prior. +name: Publish Docs +description: Publish documentation to github pages. +inputs: + workspace_path: + description: 'The workspace to publish docs for' + required: true +runs: + using: composite + steps: + # We put the github pages in another directory. + - uses: actions/checkout@v3 + with: + path: gh-pages + ref: gh-pages + - name: Publish Docs + shell: bash + run: | + echo "Publishing docs for: $WORKSPACE" + ./scripts/publish-doc.sh + env: + WORKSPACE: ${{ inputs.workspace_path }} diff --git a/actions/publish/action.yml b/actions/publish/action.yml new file mode 100644 index 0000000000..7dc17901e7 --- /dev/null +++ b/actions/publish/action.yml @@ -0,0 +1,25 @@ +name: Publish to NPM +description: Publish a package from the workspace. +inputs: + workspace_name: + description: 'The workspace to publish' + required: true + prerelease: + description: 'Is this a prerelease. If so, then the latest tag will not be updated in npm.' + required: true + dry_run: + description: 'Is this a dry run. If so no package will be published.' + required: true + +runs: + using: composite + steps: + - name: Publish + shell: bash + run: | + echo "Publishing: $WORKSPACE" + ./scripts/publish.sh + env: + WORKSPACE: ${{ inputs.workspace_name }} + LD_RELEASE_IS_PRERELEASE: ${{ inputs.prerelease }} + LD_RELEASE_IS_DRYRUN: ${{ inputs.dry_run }} diff --git a/actions/release-secrets/action.yml b/actions/release-secrets/action.yml new file mode 100644 index 0000000000..ade4c22e05 --- /dev/null +++ b/actions/release-secrets/action.yml @@ -0,0 +1,26 @@ +name: Release Secrets +# Currently this handles SSM, but once we need an s3 secret we should add support. +description: 'Action for getting release secrets from SSM' +inputs: + aws_assume_role: + description: 'The ARN of an AWS IAM role to assume. Used to auth with AWS to upload results to S3.' + required: true + # This uses this format to allow using the GetParameters action. + ssm_parameter_pairs: + description: 'A series of pairs of paths to environment mappings. "/path = ENV_NAME", "/path2 = ENV_NAME2' + required: false + # If we add S3, then just have a list of S3 paths. + +runs: + using: composite + steps: + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1-node16 + with: + audience: https://github.com/launchdarkly + role-to-assume: ${{ inputs.aws_assume_role }} + aws-region: us-east-1 + - uses: dkershner6/aws-ssm-getparameters-action@v1 + with: + parameterPairs: ${{ inputs.ssm_parameter_pairs }} + withDecryption: "true" diff --git a/packages/sdk/server-node/CHANGELOG.md b/packages/sdk/server-node/CHANGELOG.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/shared/common/CHANGELOG.md b/packages/shared/common/CHANGELOG.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/shared/sdk-server/CHANGELOG.md b/packages/shared/sdk-server/CHANGELOG.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000000..37283c9769 --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,20 @@ +{ + "packages": { + "packages/shared/common": { + "prerelease": true, + "bump-minor-pre-major": true, + "bootstrap-sha": "282a3fed8289fef680c5c2593e74aea0a3113c71" + }, + "packages/shared/sdk-server": { + "prerelease": true, + "bump-minor-pre-major": true, + "bootstrap-sha": "282a3fed8289fef680c5c2593e74aea0a3113c71" + }, + "packages/sdk/server-node": { + "prerelease": true, + "bump-minor-pre-major": true, + "bootstrap-sha": "282a3fed8289fef680c5c2593e74aea0a3113c71" + } + }, + "plugins": ["node-workspace"] +} diff --git a/scripts/doc-name.sh b/scripts/doc-name.sh index c12c9efe06..150c0fb704 100755 --- a/scripts/doc-name.sh +++ b/scripts/doc-name.sh @@ -1,5 +1,8 @@ # Given a path get the name for the documentation. -# ./scripts/doc-name.sh packages/sdk/node +# ./scripts/doc-name.sh packages/sdk/server-node # Produces something like: # LaunchDarkly Server-Side SDK for Node.js (0.1.0) + +set -e + node -p "let pj = require('./$1/package.json');\`\${pj.description} (\${pj.version})\`"; diff --git a/scripts/package-name.sh b/scripts/package-name.sh new file mode 100755 index 0000000000..e443b2c7d4 --- /dev/null +++ b/scripts/package-name.sh @@ -0,0 +1,8 @@ +# Given a path get the name of the package. +# ./scripts/package-name.sh packages/sdk/server-node +# Produces something like: +# @launchdarkly/node-server-sdk + +set -e + +node -p "require('./$1/package.json').name"; diff --git a/scripts/publish-doc.sh b/scripts/publish-doc.sh new file mode 100755 index 0000000000..d6ccc6d84b --- /dev/null +++ b/scripts/publish-doc.sh @@ -0,0 +1,54 @@ +# Run this script like: +# ./scripts/build-doc.sh packages/sdk/node + +set -e +set -x + +# Get the script location so we can run adjacent scripts. +script_path=$(readlink -f "$0") +base_name=$(dirname $script_path) +doc_name=$($base_name/doc-name.sh $WORKSPACE) + +# Move the built docs so switching branches doesn't conflict. +mv $WORKSPACE/docs $RUNNER_TEMP/doc-temp + +# Fetch the gg-pages branch. +# git fetch origin gh-pages + +# Switch to the pages branch. +# git checkout gh-pages + +# Action should have cloned the gh-pages to a subdirectory. +cd gh-pages + +# When running on CI we need to configure github before we commit. +if [ -n "${CI:-}" ]; then + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" +fi + +# Grep returns a non-zero exit code for no matches, so we want to ingore it. +set +e +existing_doc=$(git ls-files | grep -c $WORKSPACE/docs) +set -e + +if [ $existing_doc != "0" ]; then + echo "There are existing docs; removing them." + git rm -r $WORKSPACE/docs + git commit -m "chore: Removed old docs for $WORKSPACE" +else + echo "There are no existing docs; skipping removal." +fi + +mkdir -p $WORKSPACE/docs + +# Put the docs where they are expected for the github pages. +mv $RUNNER_TEMP/doc-temp/* $WORKSPACE/docs + +# Make the workspace directory if it doesn't exist. +mkdir -p $WORKSPACE +git add $WORKSPACE/docs + +git commit -m "chore: Updating docs for $doc_name" + +git push diff --git a/scripts/publish.sh b/scripts/publish.sh new file mode 100755 index 0000000000..f176886bc4 --- /dev/null +++ b/scripts/publish.sh @@ -0,0 +1,12 @@ +if $LD_RELEASE_IS_DRYRUN ; then + # Dry run just pack the workspace. + echo "Doing a dry run of publishing." + yarn workspace $WORKSPACE pack +else + if $LD_RELEASE_IS_PRERELEASE ; then + echo "Publishing with prerelease tag." + yarn workspace $WORKSPACE npm publish --tag prerelease || { echo "npm publish failed" >&2; exit 1; } + else + yarn workspace $WORKSPACE npm publish || { echo "npm publish failed" >&2; exit 1; } + fi +fi \ No newline at end of file From f28b28458c2c7cc47d2e07f5a53a574d6e9e94e2 Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Tue, 14 Mar 2023 13:18:51 -0700 Subject: [PATCH 2/4] build: Add release-please configuration. --- .github/workflows/manual-publish-docs.yml | 38 +++++++++++ .github/workflows/manual-publish.yml | 53 +++++++++++++++ .github/workflows/release-please.yml | 80 +++++++++++++++++++++++ .release-please-manifest.json | 0 actions/ci/action.yml | 6 +- actions/full-release/action.yml | 42 ++++++++++++ actions/publish-docs/action.yml | 22 +++++++ actions/publish/action.yml | 25 +++++++ actions/release-secrets/action.yml | 26 ++++++++ packages/sdk/server-node/CHANGELOG.md | 0 packages/shared/common/CHANGELOG.md | 0 packages/shared/sdk-server/CHANGELOG.md | 0 release-please-config.json | 20 ++++++ scripts/doc-name.sh | 5 +- scripts/package-name.sh | 8 +++ scripts/publish-doc.sh | 54 +++++++++++++++ scripts/publish.sh | 12 ++++ 17 files changed, 387 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/manual-publish-docs.yml create mode 100644 .github/workflows/manual-publish.yml create mode 100644 .github/workflows/release-please.yml create mode 100644 .release-please-manifest.json create mode 100644 actions/full-release/action.yml create mode 100644 actions/publish-docs/action.yml create mode 100644 actions/publish/action.yml create mode 100644 actions/release-secrets/action.yml create mode 100644 packages/sdk/server-node/CHANGELOG.md create mode 100644 packages/shared/common/CHANGELOG.md create mode 100644 packages/shared/sdk-server/CHANGELOG.md create mode 100644 release-please-config.json create mode 100755 scripts/package-name.sh create mode 100755 scripts/publish-doc.sh create mode 100755 scripts/publish.sh diff --git a/.github/workflows/manual-publish-docs.yml b/.github/workflows/manual-publish-docs.yml new file mode 100644 index 0000000000..c47664fdca --- /dev/null +++ b/.github/workflows/manual-publish-docs.yml @@ -0,0 +1,38 @@ +on: + workflow_dispatch: + inputs: + workspace_path: + description: 'The workspace to publish docs for' + required: true + default: 'packages/shared/common' + type: choice + options: + - packages/shared/common + - packages/shared/sdk-server + - packages/sdk/server-node +name: Publish Documentation +jobs: + build-publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16.x + registry-url: 'https://registry.npmjs.org' + - name: "Set WORKSPACE_NAME variable" + run: | + WORKSPACE_NAME=$(./scripts/package-name.sh ${{ inputs.workspace_path }}) + echo "WORKSPACE_NAME=$WORKSPACE_NAME" >> $GITHUB_ENV + - id: build + # Build using the same steps from CI. + name: Build and Test + uses: ./actions/ci + with: + workspace_name: ${{ env.WORKSPACE_NAME }} + workspace_path: ${{ inputs.workspace_path }} + - id: publish + name: Publish Documentation + uses: ./actions/publish-docs + with: + workspace_path: ${{ inputs.workspace_path }} diff --git a/.github/workflows/manual-publish.yml b/.github/workflows/manual-publish.yml new file mode 100644 index 0000000000..4185326122 --- /dev/null +++ b/.github/workflows/manual-publish.yml @@ -0,0 +1,53 @@ +name: Publish Package +on: + workflow_dispatch: + inputs: + workspace_path: + description: 'The workspace to publish' + required: true + default: 'packages/shared/common' + type: choice + options: + - packages/shared/common + - packages/shared/sdk-server + - packages/sdk/server-node + prerelease: + description: 'Is this a prerelease. If so, then the latest tag will not be updated in npm.' + type: boolean + required: true + dry_run: + description: 'Is this a dry run. If so no package will be published.' + type: boolean + required: true + +jobs: + build-publish: + runs-on: ubuntu-latest + # Needed to get tokens during publishing. + permissions: + id-token: write + contents: read + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16.x + registry-url: 'https://registry.npmjs.org' + - name: "Set WORKSPACE_NAME variable" + run: | + WORKSPACE_NAME=$(./scripts/package-name.sh ${{ inputs.workspace_path }}) + echo "WORKSPACE_NAME=$WORKSPACE_NAME" >> $GITHUB_ENV + - id: build-and-test + # Build using the same steps from CI. + name: Build and Test + uses: ./actions/ci + with: + workspace_name: ${{ env.WORKSPACE_NAME }} + workspace_path: ${{ inputs.workspace_path }} + - id: publish + name: Publish Package + uses: ./actions/publish + with: + workspace_name: ${{ env.WORKSPACE_NAME }} + prerelease: ${{ inputs.prerelease }} + dry_run: ${{ inputs.dry_run }} diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml new file mode 100644 index 0000000000..9f99d8651c --- /dev/null +++ b/.github/workflows/release-please.yml @@ -0,0 +1,80 @@ +on: + push: + branches: + - main +name: release-please + +jobs: + release-please: + runs-on: ubuntu-latest + outputs: + package-common-released: ${{ steps.release.outputs['packages/shared/common--release_created'] }} + package-sdk-server-released: ${{ steps.release.outputs['packages/shared/sdk-server--release_created'] }} + package-server-node-released: ${{ steps.release.outputs['packages/sdk/server-node--release_created'] }} + steps: + - uses: google-github-actions/release-please-action@v3 + id: release + with: + command: manifest + token: ${{secrets.GITHUB_TOKEN}} + default-branch: main + + release-common: + runs-on: ubuntu-latest + needs: ['release-please'] + permissions: + id-token: write + contents: write + if: ${{ needs.release-please.outputs.package-common-released }} + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16.x + registry-url: 'https://registry.npmjs.org' + - id: release-common + name: Full release of packages/shared/common + uses: ./actions/full-release + with: + workspace_path: packages/shared/common + aws_assume_role: ${{ vars.AWS_ROLE_ARN }} + + release-sdk-server: + runs-on: ubuntu-latest + needs: ['release-please'] + permissions: + id-token: write + contents: write + if: ${{ needs.release-please.outputs.package-sdk-server-released }} + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16.x + registry-url: 'https://registry.npmjs.org' + - id: release-common + name: Full release of packages/shared/sdk-server + uses: ./actions/full-release + with: + workspace_path: packages/shared/sdk-server + aws_assume_role: ${{ vars.AWS_ROLE_ARN }} + + release-server-node: + runs-on: ubuntu-latest + needs: ['release-please'] + permissions: + id-token: write + contents: write + if: ${{ needs.release-please.outputs.package-sdk-server-released }} + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16.x + registry-url: 'https://registry.npmjs.org' + - id: release-common + name: Full release of packages/sdk/server-node + uses: ./actions/full-release + with: + workspace_path: packages/sdk/server-node + aws_assume_role: ${{ vars.AWS_ROLE_ARN }} diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actions/ci/action.yml b/actions/ci/action.yml index e92110e1e4..e980ae1b9d 100644 --- a/actions/ci/action.yml +++ b/actions/ci/action.yml @@ -6,11 +6,11 @@ inputs: # Some commands work on the package name (yarn commands), other require the path (typedoc), # so we supply both. workspace_name: + description: 'Name, from the package.json, of the package to build/test.' required: true - type: string workspace_path: + description: 'Path to the package to release.' required: true - type: string runs: using: composite @@ -23,7 +23,7 @@ runs: shell: bash # Install only the dependencies requires for the specific workspace. run: yarn workspaces focus ${{ inputs.workspace_name }} - + - name: Build shell: bash # This will build the package and its dependencies. diff --git a/actions/full-release/action.yml b/actions/full-release/action.yml new file mode 100644 index 0000000000..120d258676 --- /dev/null +++ b/actions/full-release/action.yml @@ -0,0 +1,42 @@ +name: Build, Test, and Publish +description: 'Execute the full release process for a workspace.' +inputs: + workspace_path: + description: 'Path to the workspace being released.' + required: true + aws_assume_role: + description: 'The ARN of an AWS IAM role to assume. Used to auth with AWS to upload results to S3.' + required: true + + +runs: + using: composite + steps: + - name: 'Set WORKSPACE_NAME variable' + shell: bash + run: | + WORKSPACE_NAME=$(./scripts/package-name.sh ${{ inputs.workspace_path }}) + echo "WORKSPACE_NAME=$WORKSPACE_NAME" >> $GITHUB_ENV + - uses: ./actions/ci + with: + workspace_name: ${{ env.WORKSPACE_NAME }} + workspace_path: ${{ inputs.workspace_path }} + - uses: ./actions/release-secrets + name: "Get NPM token" + with: + aws_assume_role: ${{ inputs.aws_assume_role }} + ssm_parameter_pairs: "/production/common/releasing/npm/token = NODE_AUTH_TOKEN" + - name: Setup .yarnrc.yml + shell: bash + run: | + yarn config set npmScopes.launchdarkly.npmRegistryServer "https://registry.npmjs.org" + yarn config set npmScopes.launchdarkly.npmAlwaysAuth true + yarn config set npmScopes.launchdarkly.npmAuthToken $NODE_AUTH_TOKEN + - uses: ./actions/publish + with: + workspace_name: ${{ env.WORKSPACE_NAME }} + prerelease: false + dry_run: false + - uses: ./actions/publish-docs + with: + workspace_path: ${{ inputs.workspace_path }} diff --git a/actions/publish-docs/action.yml b/actions/publish-docs/action.yml new file mode 100644 index 0000000000..1757b755e5 --- /dev/null +++ b/actions/publish-docs/action.yml @@ -0,0 +1,22 @@ +# This action publishes docs. The docs must have been build prior. +name: Publish Docs +description: Publish documentation to github pages. +inputs: + workspace_path: + description: 'The workspace to publish docs for' + required: true +runs: + using: composite + steps: + # We put the github pages in another directory. + - uses: actions/checkout@v3 + with: + path: gh-pages + ref: gh-pages + - name: Publish Docs + shell: bash + run: | + echo "Publishing docs for: $WORKSPACE" + ./scripts/publish-doc.sh + env: + WORKSPACE: ${{ inputs.workspace_path }} diff --git a/actions/publish/action.yml b/actions/publish/action.yml new file mode 100644 index 0000000000..7dc17901e7 --- /dev/null +++ b/actions/publish/action.yml @@ -0,0 +1,25 @@ +name: Publish to NPM +description: Publish a package from the workspace. +inputs: + workspace_name: + description: 'The workspace to publish' + required: true + prerelease: + description: 'Is this a prerelease. If so, then the latest tag will not be updated in npm.' + required: true + dry_run: + description: 'Is this a dry run. If so no package will be published.' + required: true + +runs: + using: composite + steps: + - name: Publish + shell: bash + run: | + echo "Publishing: $WORKSPACE" + ./scripts/publish.sh + env: + WORKSPACE: ${{ inputs.workspace_name }} + LD_RELEASE_IS_PRERELEASE: ${{ inputs.prerelease }} + LD_RELEASE_IS_DRYRUN: ${{ inputs.dry_run }} diff --git a/actions/release-secrets/action.yml b/actions/release-secrets/action.yml new file mode 100644 index 0000000000..ade4c22e05 --- /dev/null +++ b/actions/release-secrets/action.yml @@ -0,0 +1,26 @@ +name: Release Secrets +# Currently this handles SSM, but once we need an s3 secret we should add support. +description: 'Action for getting release secrets from SSM' +inputs: + aws_assume_role: + description: 'The ARN of an AWS IAM role to assume. Used to auth with AWS to upload results to S3.' + required: true + # This uses this format to allow using the GetParameters action. + ssm_parameter_pairs: + description: 'A series of pairs of paths to environment mappings. "/path = ENV_NAME", "/path2 = ENV_NAME2' + required: false + # If we add S3, then just have a list of S3 paths. + +runs: + using: composite + steps: + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1-node16 + with: + audience: https://github.com/launchdarkly + role-to-assume: ${{ inputs.aws_assume_role }} + aws-region: us-east-1 + - uses: dkershner6/aws-ssm-getparameters-action@v1 + with: + parameterPairs: ${{ inputs.ssm_parameter_pairs }} + withDecryption: "true" diff --git a/packages/sdk/server-node/CHANGELOG.md b/packages/sdk/server-node/CHANGELOG.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/shared/common/CHANGELOG.md b/packages/shared/common/CHANGELOG.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/shared/sdk-server/CHANGELOG.md b/packages/shared/sdk-server/CHANGELOG.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000000..37283c9769 --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,20 @@ +{ + "packages": { + "packages/shared/common": { + "prerelease": true, + "bump-minor-pre-major": true, + "bootstrap-sha": "282a3fed8289fef680c5c2593e74aea0a3113c71" + }, + "packages/shared/sdk-server": { + "prerelease": true, + "bump-minor-pre-major": true, + "bootstrap-sha": "282a3fed8289fef680c5c2593e74aea0a3113c71" + }, + "packages/sdk/server-node": { + "prerelease": true, + "bump-minor-pre-major": true, + "bootstrap-sha": "282a3fed8289fef680c5c2593e74aea0a3113c71" + } + }, + "plugins": ["node-workspace"] +} diff --git a/scripts/doc-name.sh b/scripts/doc-name.sh index c12c9efe06..150c0fb704 100755 --- a/scripts/doc-name.sh +++ b/scripts/doc-name.sh @@ -1,5 +1,8 @@ # Given a path get the name for the documentation. -# ./scripts/doc-name.sh packages/sdk/node +# ./scripts/doc-name.sh packages/sdk/server-node # Produces something like: # LaunchDarkly Server-Side SDK for Node.js (0.1.0) + +set -e + node -p "let pj = require('./$1/package.json');\`\${pj.description} (\${pj.version})\`"; diff --git a/scripts/package-name.sh b/scripts/package-name.sh new file mode 100755 index 0000000000..e443b2c7d4 --- /dev/null +++ b/scripts/package-name.sh @@ -0,0 +1,8 @@ +# Given a path get the name of the package. +# ./scripts/package-name.sh packages/sdk/server-node +# Produces something like: +# @launchdarkly/node-server-sdk + +set -e + +node -p "require('./$1/package.json').name"; diff --git a/scripts/publish-doc.sh b/scripts/publish-doc.sh new file mode 100755 index 0000000000..d6ccc6d84b --- /dev/null +++ b/scripts/publish-doc.sh @@ -0,0 +1,54 @@ +# Run this script like: +# ./scripts/build-doc.sh packages/sdk/node + +set -e +set -x + +# Get the script location so we can run adjacent scripts. +script_path=$(readlink -f "$0") +base_name=$(dirname $script_path) +doc_name=$($base_name/doc-name.sh $WORKSPACE) + +# Move the built docs so switching branches doesn't conflict. +mv $WORKSPACE/docs $RUNNER_TEMP/doc-temp + +# Fetch the gg-pages branch. +# git fetch origin gh-pages + +# Switch to the pages branch. +# git checkout gh-pages + +# Action should have cloned the gh-pages to a subdirectory. +cd gh-pages + +# When running on CI we need to configure github before we commit. +if [ -n "${CI:-}" ]; then + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" +fi + +# Grep returns a non-zero exit code for no matches, so we want to ingore it. +set +e +existing_doc=$(git ls-files | grep -c $WORKSPACE/docs) +set -e + +if [ $existing_doc != "0" ]; then + echo "There are existing docs; removing them." + git rm -r $WORKSPACE/docs + git commit -m "chore: Removed old docs for $WORKSPACE" +else + echo "There are no existing docs; skipping removal." +fi + +mkdir -p $WORKSPACE/docs + +# Put the docs where they are expected for the github pages. +mv $RUNNER_TEMP/doc-temp/* $WORKSPACE/docs + +# Make the workspace directory if it doesn't exist. +mkdir -p $WORKSPACE +git add $WORKSPACE/docs + +git commit -m "chore: Updating docs for $doc_name" + +git push diff --git a/scripts/publish.sh b/scripts/publish.sh new file mode 100755 index 0000000000..597e964da0 --- /dev/null +++ b/scripts/publish.sh @@ -0,0 +1,12 @@ +if $LD_RELEASE_IS_DRYRUN ; then + # Dry run just pack the workspace. + echo "Doing a dry run of publishing." + yarn workspace $WORKSPACE pack +else + if $LD_RELEASE_IS_PRERELEASE ; then + echo "Publishing with prerelease tag." + yarn workspace $WORKSPACE npm publish --tag prerelease || { echo "npm publish failed" >&2; exit 1; } + else + yarn workspace $WORKSPACE npm publish || { echo "npm publish failed" >&2; exit 1; } + fi +fi From f2bc9048478333ef54381820f8742a31ec673de2 Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Tue, 14 Mar 2023 13:28:39 -0700 Subject: [PATCH 3/4] chore: Ran prettier over the yaml files. --- .github/workflows/manual-publish-docs.yml | 8 ++++---- .github/workflows/manual-publish.yml | 8 ++++---- actions/ci/action.yml | 2 +- actions/full-release/action.yml | 5 ++--- actions/publish-docs/action.yml | 2 +- actions/release-secrets/action.yml | 2 +- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/.github/workflows/manual-publish-docs.yml b/.github/workflows/manual-publish-docs.yml index c47664fdca..4090ba0d6c 100644 --- a/.github/workflows/manual-publish-docs.yml +++ b/.github/workflows/manual-publish-docs.yml @@ -7,9 +7,9 @@ on: default: 'packages/shared/common' type: choice options: - - packages/shared/common - - packages/shared/sdk-server - - packages/sdk/server-node + - packages/shared/common + - packages/shared/sdk-server + - packages/sdk/server-node name: Publish Documentation jobs: build-publish: @@ -20,7 +20,7 @@ jobs: with: node-version: 16.x registry-url: 'https://registry.npmjs.org' - - name: "Set WORKSPACE_NAME variable" + - name: 'Set WORKSPACE_NAME variable' run: | WORKSPACE_NAME=$(./scripts/package-name.sh ${{ inputs.workspace_path }}) echo "WORKSPACE_NAME=$WORKSPACE_NAME" >> $GITHUB_ENV diff --git a/.github/workflows/manual-publish.yml b/.github/workflows/manual-publish.yml index 4185326122..39650f4beb 100644 --- a/.github/workflows/manual-publish.yml +++ b/.github/workflows/manual-publish.yml @@ -8,9 +8,9 @@ on: default: 'packages/shared/common' type: choice options: - - packages/shared/common - - packages/shared/sdk-server - - packages/sdk/server-node + - packages/shared/common + - packages/shared/sdk-server + - packages/sdk/server-node prerelease: description: 'Is this a prerelease. If so, then the latest tag will not be updated in npm.' type: boolean @@ -33,7 +33,7 @@ jobs: with: node-version: 16.x registry-url: 'https://registry.npmjs.org' - - name: "Set WORKSPACE_NAME variable" + - name: 'Set WORKSPACE_NAME variable' run: | WORKSPACE_NAME=$(./scripts/package-name.sh ${{ inputs.workspace_path }}) echo "WORKSPACE_NAME=$WORKSPACE_NAME" >> $GITHUB_ENV diff --git a/actions/ci/action.yml b/actions/ci/action.yml index e980ae1b9d..c9f1f3ca6c 100644 --- a/actions/ci/action.yml +++ b/actions/ci/action.yml @@ -23,7 +23,7 @@ runs: shell: bash # Install only the dependencies requires for the specific workspace. run: yarn workspaces focus ${{ inputs.workspace_name }} - + - name: Build shell: bash # This will build the package and its dependencies. diff --git a/actions/full-release/action.yml b/actions/full-release/action.yml index 120d258676..b295d24487 100644 --- a/actions/full-release/action.yml +++ b/actions/full-release/action.yml @@ -8,7 +8,6 @@ inputs: description: 'The ARN of an AWS IAM role to assume. Used to auth with AWS to upload results to S3.' required: true - runs: using: composite steps: @@ -22,10 +21,10 @@ runs: workspace_name: ${{ env.WORKSPACE_NAME }} workspace_path: ${{ inputs.workspace_path }} - uses: ./actions/release-secrets - name: "Get NPM token" + name: 'Get NPM token' with: aws_assume_role: ${{ inputs.aws_assume_role }} - ssm_parameter_pairs: "/production/common/releasing/npm/token = NODE_AUTH_TOKEN" + ssm_parameter_pairs: '/production/common/releasing/npm/token = NODE_AUTH_TOKEN' - name: Setup .yarnrc.yml shell: bash run: | diff --git a/actions/publish-docs/action.yml b/actions/publish-docs/action.yml index 1757b755e5..f2699c1584 100644 --- a/actions/publish-docs/action.yml +++ b/actions/publish-docs/action.yml @@ -8,7 +8,7 @@ inputs: runs: using: composite steps: - # We put the github pages in another directory. + # We put the github pages in another directory. - uses: actions/checkout@v3 with: path: gh-pages diff --git a/actions/release-secrets/action.yml b/actions/release-secrets/action.yml index ade4c22e05..aa82a3c951 100644 --- a/actions/release-secrets/action.yml +++ b/actions/release-secrets/action.yml @@ -23,4 +23,4 @@ runs: - uses: dkershner6/aws-ssm-getparameters-action@v1 with: parameterPairs: ${{ inputs.ssm_parameter_pairs }} - withDecryption: "true" + withDecryption: 'true' From a2f821905155223979b6bfa802c3381747baf185 Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Wed, 15 Mar 2023 09:57:38 -0700 Subject: [PATCH 4/4] chore: Add stale issue workflow. --- .github/workflows/stale.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/stale.yml diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 0000000000..2ac9e7b528 --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,14 @@ +name: 'Close stale issues and PRs' +on: + schedule: + - cron: '30 1 * * *' + +jobs: + stale: + runs-on: ubuntu-latest + steps: + - uses: actions/stale@v7 + with: + stale-issue-message: 'This issue is stale because it has been open for 90 days without activity. Remove the stale label or comment, or this will be closed in 14 days.' + days-before-stale: 90 + days-before-close: 14