MLH / update-segment-function-action

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Update Segment Function Action

Forked from [https://github.com/samgehret/manageSegmentFunction] to use the Segment Public API

Overview

The purpose of this repo is to provide a workflow which uses Github Actions to manage Segment Functions within your existing Software Development Lifecycle (SDLC). By leveraging this repo you can write function code in your own IDE to Create and Update functions in your Segment workspace.

Key Benefits

  • Leverage function version control from Git and Github.
  • Use git commit history to revert functions to previous versions.
  • Integrate function code with automated testing currently leveraged in your SDLC.

Set Up

  • Create a main.yml file in your own repo where your function exists (not this repo), within a .github/workflows folder. So like .github/workflows/main.yml
  • Copy the content of the main.yml to the main.yml in your own repo.
  • Within your main.yml in your function repo, input your token, workspaceID, function-type and function-name.
  • Make sure to update the relative path to your function within the bash script in the main.yml file.
  • When you push your function code to your master branch, it should create a function in your Segment workspace.
  • Check the "Actions" section (look for the link at the top of your repo) to check on the status of the upload.
  • Check your Segment workspace to see if the function was sucessfully added.
  • If added, grab the function-id and input it into main.yml to allow your function to be updated. This can be found in the URL when looking at an indvidual function https://app.segment.com/demo-segment-workspace/functions/catalog/<FUNCTION ID HERE>/edit/code

Example Usage

on: [push]
jobs:
  deploy:
    name: Update Source Function in Segment
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Function
        uses: actions/checkout@v2

      - name: Prepare Function
        shell: bash
        run: |
          echo "Function Code Is"
          cp lib/function.js lib/function.txt
          value="$(< lib/function.txt)"
          value="${value//'%'/'%25'}"
          value="${value//$'\n'/'%0A'}"
          value="${value//$'\r'/'%0D'}"
          echo $value
          echo "::set-output name=function_code::$value"
        id: checkout

      - name: Send Function to Segment
        uses: MLH/update-segment-function-action@v1.0.0
        with:
          token: ${{ secrets.SEGMENT_TOKEN }}
          function-code: ${{ steps.checkout.outputs.function_code }} # don't update this
          function-name: "Source Function"
          function-type: Source
          function-id: sfnc_wXzcDGFR3KmjLDrtSawNHf

Components

Inputs

  • token Required The auhtorization token generated in Segment.
  • function-code Required Do not change this. This reads your function code.
  • function-name Required The display name of your function inside the Segment UI
  • function-type Required Specify either Source or Destination Function
  • function-id The id of your Segment function (assigned after it is created). You need to add this after the function is created.

About

License:MIT License


Languages

Language:JavaScript 100.0%