-
Notifications
You must be signed in to change notification settings - Fork 5
chore: Update implementation and move to github actions. #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Verify Hello App | ||
on: | ||
schedule: | ||
# * is a special character in YAML so you have to quote this string | ||
- cron: '0 9 * * *' | ||
push: | ||
branches: [ main, 'feat/**' ] | ||
paths-ignore: | ||
- '**.md' # Do not need to run CI for markdown changes. | ||
pull_request: | ||
branches: [ main, 'feat/**' ] | ||
paths-ignore: | ||
- '**.md' | ||
|
||
jobs: | ||
build-and-run: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
id-token: write # Needed if using OIDC to get release secrets. | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-node@v4 | ||
|
||
- run: npm i | ||
|
||
- uses: launchdarkly/gh-actions/actions/[email protected] | ||
with: | ||
use_server_key: true | ||
role_arn: ${{ vars.AWS_ROLE_ARN }} | ||
command: npm start |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,71 @@ | ||
import * as LaunchDarkly from '@launchdarkly/node-server-sdk'; | ||
|
||
// Set sdkKey to your LaunchDarkly SDK key. | ||
const sdkKey = ""; | ||
const sdkKey = process.env.LAUNCHDARKLY_SDK_KEY ?? 'your-sdk-key'; | ||
|
||
// Set featureFlagKey to the feature flag key you want to evaluate. | ||
const featureFlagKey = "my-boolean-flag"; | ||
const featureFlagKey = process.env.LAUNCHDARKLY_FLAG_KEY ?? 'sample-feature'; | ||
|
||
// Set up the context properties. This use should appear on your LaunchDarkly | ||
// contexts dashboard soon after you run the demo. | ||
function showBanner() { | ||
console.log( | ||
` ██ | ||
██ | ||
████████ | ||
███████ | ||
██ LAUNCHDARKLY █ | ||
███████ | ||
████████ | ||
██ | ||
██ | ||
`, | ||
); | ||
} | ||
|
||
function printValueAndBanner(flagValue: boolean) { | ||
console.log(`*** The '${featureFlagKey}' feature flag evaluates to ${flagValue}.`); | ||
|
||
if (flagValue) showBanner(); | ||
} | ||
|
||
if (!sdkKey) { | ||
console.log('*** Please edit index.js to set sdkKey to your LaunchDarkly SDK key first.'); | ||
process.exit(1); | ||
} | ||
|
||
|
||
const ldClient = LaunchDarkly.init(sdkKey); | ||
|
||
// Set up the context properties. This context should appear on your LaunchDarkly contexts dashboard | ||
// soon after you run the demo. | ||
const context = { | ||
"kind": "user", | ||
"name": "Sandy", | ||
"key": "example-context-key" | ||
kind: 'user', | ||
key: 'example-user-key', | ||
name: 'Sandy', | ||
}; | ||
|
||
function showMessage(s: string) { | ||
console.log("*** " + s); | ||
console.log(""); | ||
} | ||
async function main() { | ||
try { | ||
await ldClient.waitForInitialization({timeout: 10}); | ||
|
||
const client = LaunchDarkly.init(sdkKey); | ||
|
||
client.once('ready', function () { | ||
showMessage("SDK successfully initialized!"); | ||
client.variation(featureFlagKey, context, false, function (err, showFeature) { | ||
client.track("event-called", context); | ||
if (showFeature) { | ||
// application code to show the feature | ||
showMessage("Feature flag '" + featureFlagKey + "' is true for this context"); | ||
} else { | ||
// the code to run if the feature is off | ||
showMessage("Feature flag '" + featureFlagKey + "' is false for this context"); | ||
} | ||
console.log('*** SDK successfully initialized!'); | ||
|
||
// Here we ensure that the SDK shuts down cleanly and has a chance to deliver analytics | ||
// events to LaunchDarkly before the program exits. If analytics events are not delivered, | ||
// the context properties and flag usage statistics will not appear on your dashboard. In a | ||
// normal long-running application, the SDK would continue running and events would be | ||
// delivered automatically in the background. | ||
client.flush(function () { | ||
client.close(); | ||
const eventKey = `update:${featureFlagKey}`; | ||
ldClient.on(eventKey, async () => { | ||
const flagValue = await ldClient.variation(featureFlagKey, context, false); | ||
printValueAndBanner(flagValue); | ||
}); | ||
}); | ||
}); | ||
|
||
const flagValue = await ldClient.variation(featureFlagKey, context, false); | ||
printValueAndBanner(flagValue); | ||
|
||
if (typeof process.env.CI !== "undefined") { | ||
process.exit(0); | ||
} | ||
} catch (error) { | ||
console.log(`*** SDK failed to initialize: ${error}`); | ||
process.exit(1); | ||
} | ||
|
||
} | ||
|
||
main(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,11 +9,11 @@ | |
"author": "LaunchDarkly <[email protected]>", | ||
"license": "Apache-2.0", | ||
"devDependencies": { | ||
"@types/node": "20.4.2", | ||
"ts-node": "10.9.1", | ||
"typescript": "5.1.6" | ||
"@types/node": "22.10.1", | ||
"ts-node": "10.9.2", | ||
"typescript": "5.7.2" | ||
}, | ||
"dependencies": { | ||
"@launchdarkly/node-server-sdk": ">= 8.0.0" | ||
"@launchdarkly/node-server-sdk": ">= 9.0.0" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"strict": true | ||
"module": "NodeNext", | ||
"strict": true, | ||
"target": "ES2020", | ||
"moduleResolution": "NodeNext", | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we have this, should we not default the SDK variable above to "your-sdk-key"?