Skip to content

๐Ÿš€ Template to build your next source function | Jest + ESLint + Prettier + Husky + GitHub Actions

Notifications You must be signed in to change notification settings

segment-services-eng/source-function-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Segment_Functions

Source Function Template

Base template to deploy your next source function

  1. Click Use This Template above
  • (If Segment PS, add to Segment Services Engineering Organization

Setup Steps

  1. nvm use (to get the right version of NodeJS)
  2. npm install (to install npm dependencies)

To Test

npm run test

  • GitHub Actions workflow also runs tests before deploying
  • Tests are created in src/index.test.js

To Deploy via GitHub Actions

  1. Create GitHub Environments in Settings โ†’ Environments โ†’ DEV

    • DEV is enabled by default in the .github/workflows/deployFunction.yml file
    • (repeat for QA & PROD)
  2. Create Source Function in Segment Workspace

  3. Connect Source Function to a Segment Source

  4. Create Public API Token to allow for deploying

  5. Add the following Environment Secrets

    • FUNCTION_ID (include the sfnc_ part of the function id)
      • Get it from the URL of the Function
      • 2023-09-11_17-13-03
    • SOURCE_ID (available in the Source Settings โ†’ API Keys tab)
      • 2023-09-11_17-14-05
    • PUBLIC_API_TOKEN (Get an API Token) DEV Environment Secrets

Deploying to multiple environments

  1. Once changes look good in the DEV environment, uncomment the QA section from the deployFunction.yml file.
  2. Push changes to your branch
  3. Add the label !!_RELEASE_TO_QA to the PR to deploy it to QA
    • (ensure a QA GitHub Environment has been created)
  4. If ready to deploy to PROD, uncomment the PROD section from the deployFunction.yml file & merge the PR (ensure a PROD GitHub Environment has been created)

Tooling Included

  1. Jest for code testing
  2. Prettier for code formatting
  3. ESLint for code linting
  4. GitHub Actions script for function deploy
  5. Husky for commit validation

About

๐Ÿš€ Template to build your next source function | Jest + ESLint + Prettier + Husky + GitHub Actions

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published