Skip to content

Commit

Permalink
feat: publish to npm (#159)
Browse files Browse the repository at this point in the history
Add workflow to publish as npm package
  • Loading branch information
dbolson authored Apr 16, 2024
1 parent c1feb53 commit 461467f
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 2 deletions.
20 changes: 20 additions & 0 deletions .github/actions/publish-npm/action.yml
Original file line number Diff line number Diff line change
@@ -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 }}
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/manual-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
dist/
*.log
node_modules/
9 changes: 9 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmd/
internal/
main.go
vendor/
go.mod
go.sum
Makefile
.goreleaser.yaml
Dockerfile.goreleaser
25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <team@launchdarkly.com>",
"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"
}
}
9 changes: 8 additions & 1 deletion release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
}
}
11 changes: 11 additions & 0 deletions scripts/publish-npm.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 461467f

Please sign in to comment.