Version Control for Staging and Production Projects
It's a safe and efficient practice to use separate production and staging/testing projects to build out and test your workflows before starting to use them in production. This can be made seamless using Version Control. This guide walks you through how to set up your OpenFn projects and GitHub repo and gives you two examples of how to manage your Staging > Production
workflow: one for new projects, and one for existing projects where you want to add a staging project and branch.
Setup for new projects
- First, create a
Production
and aStaging
project on OpenFn (2 projects)
- Choose/create a GitHub repo for your project, and create a
staging
branch
Connect your projects to the
main
andstaging
respectively - use this guide to set up the connectionIn each repo, create an empty
.js
file for your job. Make sure they have the same name and path on each repo (e.g.upsert-contacts.js
). These will store the code for the job they'll be linked to in the next step.When you connected the branches to your projects in step 3 above, there was a
spec.yaml
file automatically created on the branch after the first sync (along with two other configuration files). Open these files on GitHub, and locate your job in the file. Replace the contents ofbody
with:path: {path to the related js file}
. Do this on both yourmain
andstaging
branches.
- You're now all set up!
- To sync a change from your Staging project to Production using the OpenFn app, go to your
Staging
project on OpenFn and make edits to your job. Then go to your project'sSettings
> Sync toGitHub
, and clickInitiate Sync to Branch
. - Alternatively, you can make edits directly to the job code on Github, and commit them to the
staging
branch on Github. - Once you've committed edits to your
staging
branch, on Github you'll see an update that there have been recent changes. ClickCompare & pull request
.
- Create a Pull Request. This will automatically include all changes that happened to the files on the staging branch.
Depending on your team's Github workflow, either have someone to approve and merge the Pull Request, or click
Merge pull request
.Your changes will now be automatically deployed to your OpenFn
Production
project (linked to themain
Github branch).
Setup for existing projects
- First, make sure that the code of all your jobs are stored in separate
.js
files (likeNotify-CHW-upload-successful.js
) on Github that are linked in yourspec.yaml
like so:
Notify-CHW-upload-successful:
name: Notify-CHW-upload-successful
adaptor: '@openfn/language-http@latest'
enabled: true
# credential:
# globals:
body: |
path: ./workflow/Notify-CHW-upload-successful.js
You can find more information on this setup in our Github docs.
- When this is set up, create a new
staging
branch on Github based on your existing productionmain
branch that stores your current project. To do this, on your Github repo click intoBranches
(where it show1 Branch
in the screenshot below).
- Click
New branch
, give it a name likestaging
, make sure the source ismain
if you have multiple branches already. Then clickCreate new branch
.
Navigate over to your new
staging
branch. Here comes an important step. Note how the new branch now contains the 3 configurations files (config.json
,spec.yaml
andstate.json
) that were present on the main branch. Delete these from thestaging
branch. New ones specific to the staging branch will be created in the subsequent steps.Now head over to OpenFn, and create a new
Staging
project.Following this guide, set up Github connection with your
staging
branch, and clickInitiate a sync
(via the projectSettings > Sync to Github
page). This will create the necessary config files in the Github branch.In the newly generated
spec.yaml
file on thestaging
branch on Github, link your job.js
files as explained in Step 1.When you initiate a new sync from OpenFn, the job code from the workflows configured in the app will be synced to the individual OpenFn job files on Github.
To make future changes to your "Staging" project, see steps #7-12 above in the
Setup for new projects
section of this guide.