tidepool-org / tools

A place to put tooling and scripts that help when working on Tidepool stuff.
Other
11 stars 11 forks source link

Use custom environment vars to determine if feature flags are enabled #90

Closed clintonium-119 closed 2 years ago

clintonium-119 commented 3 years ago

The prior solution for enabling feature flags wouldn't cover our use cases properly due to the way that Travis handles pull request build branches.

Problem

Instead of using the pull request source branch to apply our feature flag environment variables to, it uses the base branch.

So, if we set, via the Travis UI:

CLINICS_ENABLED 
true
Only available to the clinic-ui-staging branch

Now, if we have a a PR for clinic-ui-staging that has develop as a base, when we push to clinic-ui-staging, the Travis branch build will set CLINICS_ENABLED to true, but the pull request build will set CLINICS_ENABLED to false, since we did not specify a CLINICS_ENABLED=true flag for develop as well in the UI.

We could simply add another branch-specific feature flag for the targeted base branch, but that would cause us to have to enable the feature on master before we're ready when we have a release candidate PR in testing.

Proposed Solution

We create a custom env var in the Travis UI (in our example case - CLINICS_ENABLED_BRANCHES) that Travis will apply for all builds that contains a comma separated list for branches to enable. So, in the UI we would set:

CLINICS_ENABLED_BRANCHES 
clinic-ui-staging,any-other-branch
Available to all branches

Now any matches of ${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH} with our "feature-enable-lists" in our artifact.sh script will get the proper feature flags set whether it's a 'branch build' or a 'pull request build'.