diff --git a/.github/actions/publish-npm/action.yml b/.github/actions/publish-npm/action.yml new file mode 100644 index 00000000..61d706b3 --- /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: 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: | + ./scripts/publish-npm.sh + env: + LD_RELEASE_IS_PRERELEASE: ${{ inputs.prerelease }} + LD_RELEASE_IS_DRYRUN: ${{ inputs.dry_run }} diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index b008de66..3fc31ff3 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -14,7 +14,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Go uses: actions/setup-go@v4 diff --git a/.github/workflows/manual-publish.yml b/.github/workflows/manual-publish.yml index a801ca03..1075aa38 100644 --- a/.github/workflows/manual-publish.yml +++ b/.github/workflows/manual-publish.yml @@ -39,6 +39,34 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} homebrew-gh-secret: ${{secrets.HOMEBREW_DEPLOY_KEY}} tag: ${{ inputs.tag }} + + release-ldcli-npm: + runs-on: ubuntu-latest + needs: ['release-ldcli'] + permissions: + actions: read + id-token: write + contents: write + steps: + - uses: actions/checkout@v4 + name: Checkout + with: + fetch-depth: 0 + - uses: actions/setup-node@v3 + with: + node-version: 20.x + registry-url: 'https://registry.npmjs.org' + - uses: launchdarkly/gh-actions/actions/release-secrets@release-secrets-v1.0.1 + name: 'Get NPM token' + with: + aws_assume_role: ${{ vars.AWS_ROLE_ARN }} + ssm_parameter_pairs: '/production/common/releasing/npm/token = NODE_AUTH_TOKEN' + - id: publish-npm + name: Publish NPM Package + uses: ./.github/actions/publish-npm + with: + prerelease: ${{ inputs.prerelease }} + release-ldcli-provenance: needs: ['release-ldcli'] permissions: diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 64f33a87..1c6d90b8 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -47,6 +47,31 @@ jobs: homebrew-gh-secret: ${{secrets.HOMEBREW_DEPLOY_KEY}} tag: ${{ needs.release-please.outputs.tag_name }} + release-ldcli-npm: + runs-on: ubuntu-latest + needs: ['release-please', 'release-ldcli'] + permissions: + id-token: write + contents: write + if: ${{ needs.release-please.outputs.release_created == 'true' }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v3 + with: + node-version: 20.x + registry-url: 'https://registry.npmjs.org' + - uses: launchdarkly/gh-actions/actions/release-secrets@release-secrets-v1.0.1 + name: 'Get NPM token' + with: + aws_assume_role: ${{ vars.AWS_ROLE_ARN }} + ssm_parameter_pairs: '/production/common/releasing/npm/token = NODE_AUTH_TOKEN' + - id: publish-npm + name: Publish NPM Package + uses: ./.github/actions/publish-npm + with: + prerelease: ${{ inputs.prerelease }} + dry_run: ${{ inputs.dry_run }} + release-ldcli-provenance: needs: ['release-please', 'release-ldcli'] permissions: diff --git a/.gitignore b/.gitignore index 6cf8daa5..b2125838 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea/ dist/ *.log +node_modules/ diff --git a/.npmignore b/.npmignore new file mode 100644 index 00000000..3d1d171a --- /dev/null +++ b/.npmignore @@ -0,0 +1,9 @@ +cmd/ +internal/ +main.go +vendor/ +go.mod +go.sum +Makefile +.goreleaser.yaml +Dockerfile.goreleaser diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..bbde10bb --- /dev/null +++ b/package-lock.json @@ -0,0 +1,25 @@ +{ + "name": "@launchdarkly/ldcli", + "version": "v0.0.1-test", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@launchdarkly/ldcli", + "version": "v0.0.1-test", + "hasInstallScript": true, + "license": "Apache-2.0", + "dependencies": { + "@go-task/go-npm": "^0.2.0" + } + }, + "node_modules/@go-task/go-npm": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/@go-task/go-npm/-/go-npm-0.2.0.tgz", + "integrity": "sha512-vQbdtBvesHm8EUFHX8QKg4rbBodmu9VsAXH1ozpbiN5jdTMOYHTCMM31EurAYmY+rNNtxJQ4JGy6t383RPlqbw==", + "bin": { + "go-npm": "bin/index.js" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 00000000..fb7a54ee --- /dev/null +++ b/package.json @@ -0,0 +1,35 @@ +{ + "name": "@launchdarkly/ldcli", + "description": "The official command line interface for managing LaunchDarkly feature flags.", + "version": "0.0.1", + "main": "index.js", + "scripts": { + "postinstall": "go-npm install", + "preuninstall": "go-npm uninstall" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/launchdarkly/ldcli.git" + }, + "keywords": [ + "cli", + "feature-flags", + "feature-toggles", + "command-line-interface", + "launchdarkly-integration" + ], + "author": "LaunchDarkly ", + "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/launchdarkly/ldcli/issues" + }, + "homepage": "https://github.com/launchdarkly/ldcli#readme", + "goBinary": { + "name": "ldcli", + "path": "./bin", + "url": "https://github.com/launchdarkly/ldcli/releases/download/v{{version}}/ldcli_{{version}}_{{platform}}_{{arch}}.tar.gz" + }, + "dependencies": { + "@go-task/go-npm": "^0.2.0" + } +} diff --git a/release-please-config.json b/release-please-config.json index 0cc9bd4f..31bfe96a 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -6,7 +6,14 @@ "versioning": "always-bump-minor", "bootstrap-sha": "f37bd3aee1f117faba005bf96f0d0888f898ee41", "prerelease": true, - "extra-files": ["PROVENANCE.md"] + "extra-files": [ + "PROVENANCE.md", + { + "type": "json", + "path": "package.json", + "jsonpath": "$.version" + } + ] } } } 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