|
1 | 1 | # GitHub / GitLab for Version Control
|
2 | 2 |
|
3 |
| -Learn how to integrate GitHub / GitLab repositories with your Windmill workspace for effective version control. |
| 3 | +Windmill integration with Git repositories makes it possible to adopt a robust development process for you Windmill scripts, flows and apps. |
4 | 4 |
|
5 |
| -Check out the [windmill-sync-example repository](https://github.com/windmill-labs/windmill-sync-example) as an illustrative guide on utilizing GitHub / GitLab repositories as the version control source for your Windmill workspace. |
| 5 | +The process is as follow: |
| 6 | +- Users iterates and make their changes in a "staging" Windmill workspace |
| 7 | +- Every time a Windmill App, Flow or Script is deployed to that workspace (via Windmill's UI), Windmill automatically commits it to this repo and creates one branch per app/flow/script. |
| 8 | +- On every commit from Windmill, PRs are automatically created via a Github action. Approved Github users can review and merge those PRs. |
| 9 | +- Every time a PR is merged, another Github action automatically deploys the change to a "production" Windmill workspace |
6 | 10 |
|
7 |
| -Users of this repo can commit changes to the main branches and have it deployed to their Windmill workspace thanks to a GitHub / GitLab action that will simply use the [Windmill CLI's](https://github.com/windmill-labs/windmill/tree/main/cli) `wmill sync push` under the hood. |
| 11 | +This gives the flexibility to fully test new Windmill scripts, flows and apps, while having them version controlled and deployed in an automated way to the production environment. |
8 | 12 |
|
9 |
| -This repo is used to sync with the example folder in the demo workspace. |
| 13 | +:::info |
| 14 | + |
| 15 | +Windmill workspace sync to a Git repository is an Enterprise Edition only feature. |
| 16 | + |
| 17 | +::: |
| 18 | + |
| 19 | +:::tip |
| 20 | + |
| 21 | +Check out the [windmill-sync-example repository](https://github.com/windmill-labs/windmill-sync-example) as an illustration of this process. |
| 22 | + |
| 23 | +::: |
10 | 24 |
|
11 | 25 | ## Setup
|
12 | 26 |
|
13 |
| -Write access to the workspace is required. This is done using an access token. |
14 |
| -To generate a new token log into your Windmill instance |
15 |
| -(<a href="https://app.windmill.dev/" rel="nofollow">https://app.windmill.dev/</a> for cloud hosted instances) and navigate to the |
16 |
| -account settings, which contains a "[Tokens](../../core_concepts/4_webhooks/index.mdx#user-token)" section, use the relevant button |
17 |
| -there to generate a new token. Note that you will only be able to copy this |
18 |
| -token once! |
| 27 | +Note: this is the detailed setup steps for a Github repository. It will need to ba adapted for GitLab. |
| 28 | + |
| 29 | +#### Github repository setup |
| 30 | + |
| 31 | +First the Github repo needs to be setup and Windmill needs to be able to commit to it. |
| 32 | + |
| 33 | +1. Create a Github repository |
| 34 | +1. Generate a [Github token with write permission](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-fine-grained-personal-access-token) to this repository. This is necessary for Windmill to push commits to the repo every time a change is made to the staging workspace. |
| 35 | +1. In the repository settings > Actions > General, tick the [Allow GitHub Actions to create and approve pull requests](https://docs.github.com/en/enterprise-server@3.10/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository#preventing-github-actions-from-creating-or-approving-pull-requests). This is necessary for the Github action automatically creating PRs when Windmill commits a change |
| 36 | +1. From Windmill, create a token under User settings > Token and [save it as a secret](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository) named `WMILL_TOKEN` in the repo settings > "Secret and Variable" > "Actions". This is necessary for Windmill to push to the production workspace |
19 | 37 |
|
20 |
| -  |
| 38 | +#### Windmill setup |
21 | 39 |
|
22 |
| -Add an environment "windmill" to the repository via the settings. You may name |
23 |
| -this anything, but will need to adjust the workflow accordingly. Then add a |
24 |
| -secret "WMILL_TOKEN" to this environment. |
| 40 | +1. In Windmill, create a `git_repository` resource pointing to the Github repository and containing the token generated previously. You URL should be `https://[USERNAME]:[TOKEN]@github.com/[ORG|USER]/[REPO_NAME].git`. Note that you have the possibility to input a custom branch name and a subfolder in this resource. Given that we are going to request Windmill to create one branch per script/flow/app, setting a custom branch will have no effect. However, if you wish to persist the windmill workspace in a subfolder of your repository, you can set it here. |
| 41 | +1. In Windmill workspace settings > Git sync tab, pick the `git_repository` resource and toggle ON "Create one branch per per deployed script/flow/app" |
25 | 42 |
|
26 |
| - |
| 43 | +#### Github actions setup |
27 | 44 |
|
28 |
| -Edit the workflows: |
| 45 | +Two actions are needed. |
29 | 46 |
|
30 |
| -- [.github/workflows/push-on-merge.yaml](https://github.com/windmill-labs/windmill-sync-example/blob/main/.github/workflows/push-on-merge.yaml) to push on merge to main, usually you'll |
31 |
| - only need to fill out the `env` variables, then activate GitHub actions by |
32 |
| - navigating to the "Actions" tab in GitHub. You may want to run the action once |
33 |
| - manually to see that everything works. |
| 47 | +1. The first one to automatically create a PR when Windmill commits a change after a user deployed a script/flow/app in the staging workspace. The workflow file is available in [the example repo](https://github.com/windmill-labs/windmill-sync-example/blob/main/.github/workflows/open-pr-on-commit.yaml). All branches created by Windmill will have a `wm_deploy/` prefix, which is handy to trigger this action only when a branch matching this pattern is created. |
| 48 | +1. The second one to automatically push the content of the repo to the Windmill production workspace when a PR is merged. The workflow file is available in [the example repo](https://github.com/windmill-labs/windmill-sync-example/blob/main/.github/workflows/push-on-merge.yaml). This action uses the [Github CLI](https://cli.github.com/) which is available by default on Github action workers. |
34 | 49 |
|
35 |
| -- [.github/workflows/pull-workspace.yaml](https://github.com/windmill-labs/windmill-sync-example/blob/main/.github/workflows/pull-workspace.yaml) to sync back any changes made in Windmill UI to this repo under the form of either a Pull Request or a commit to main directly. |
| 50 | +## Alternatives |
36 | 51 |
|
37 |
| - |
| 52 | +If you don't have and Enterprise Edition license, alternatives exists to achieve similar workflows. |
38 | 53 |
|
39 |
| -### Security |
| 54 | +#### Using Windmill's embedded promotion feature |
40 | 55 |
|
41 |
| -We recommend creating and using a separate account in Windmill from which to use the token of. This will allow better tracking of the use of the token. |
| 56 | +Windmill provides an easy way to "promote" scripts, flow and apps from one workspace to another. From the workspace settings, you can defined a workspace to be the "production" version of your current workspace. When this is set, any script flow or app can be promoted to the production workspace by clicking the ... button at the right of the script / flow / app in the home menu, and then "Deploy to Staging/Prod". |
42 | 57 |
|
43 |
| -It may additionally be useful to restrict the GitHub environment. |
44 |
| -[The GitHub help article](https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment) |
45 |
| -goes into detail of all the options. |
| 58 | +#### Using Windmill CLI in Github actions |
46 | 59 |
|
47 |
| -## .wmillignore |
| 60 | +Finally, you can define your own github actions to pull Windmill workspace regularly from Github using Windmill CLI. To automatically deploy a PR to the Windmill workspace, the (push-on-merge.yaml)[https://github.com/windmill-labs/windmill-sync-example/blob/main/.github/workflows/push-on-merge.yaml] mentioned above can be used. |
48 | 61 |
|
49 |
| -Use the .wmillignore file to filter the contents to sync (like only the content of some folders), it supports the .gitignore syntax. |
| 62 | +And another Github action can be created to regularly pull Windmill workspace to the Github repo using Windmill CLI. This action can be run on a schedule to keep the repo and the workspace in sync. |
0 commit comments