Skip to content

Commit 06f5045

Browse files
Nicorettickunki
andauthored
Add support for merge gate in CI workflow (#250)
--------- Co-authored-by: Christoph Kuhnke <christoph.kuhnke@exasol.com>
1 parent 67bb4c8 commit 06f5045

File tree

18 files changed

+204
-156
lines changed

18 files changed

+204
-156
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI/CD
1+
name: CD
22

33
on:
44
push:
@@ -11,18 +11,9 @@ jobs:
1111
name: Check Release Tag
1212
uses: ./.github/workflows/check-release-tag.yml
1313

14-
ci-job:
15-
name: Checks
16-
needs: [ check-tag-version-job ]
17-
uses: ./.github/workflows/checks.yml
18-
1914
cd-job:
2015
name: Continuous Delivery
2116
needs: [ ci-job ]
2217
uses: ./.github/workflows/build-and-publish.yml
2318
secrets:
2419
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
25-
26-
metrics:
27-
needs: [ ci-job ]
28-
uses: ./.github/workflows/report.yml

.github/workflows/checks.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ on:
88

99
jobs:
1010

11-
version-check-job:
12-
name: Version Check
11+
Version-Check:
12+
name: Version
1313
runs-on: ubuntu-latest
1414

1515
steps:
@@ -24,9 +24,9 @@ jobs:
2424
- name: Check Version(s)
2525
run: poetry run version-check `poetry run python -c "from noxconfig import PROJECT_CONFIG; print(PROJECT_CONFIG.version_file)"`
2626

27-
build-documentation-job:
28-
name: Build Documentation
29-
needs: [ version-check-job ]
27+
Documentation:
28+
name: Docs
29+
needs: [ Version-Check ]
3030
runs-on: ubuntu-latest
3131

3232
steps:
@@ -40,9 +40,9 @@ jobs:
4040
run: |
4141
poetry run python -m nox -s build-docs
4242
43-
lint-job:
43+
Lint:
4444
name: Linting (Python-${{ matrix.python-version }})
45-
needs: [ version-check-job ]
45+
needs: [ Version-Check ]
4646
runs-on: ubuntu-latest
4747
strategy:
4848
fail-fast: false
@@ -68,9 +68,9 @@ jobs:
6868
path: .lint.txt
6969
include-hidden-files: true
7070

71-
type-check-job:
71+
Type-Check:
7272
name: Type Checking (Python-${{ matrix.python-version }})
73-
needs: [ version-check-job ]
73+
needs: [ Version-Check ]
7474
runs-on: ubuntu-latest
7575
strategy:
7676
fail-fast: false
@@ -89,9 +89,9 @@ jobs:
8989
- name: Run type-check
9090
run: poetry run nox -s type-check
9191

92-
security-job:
93-
name: Security Checking (Python-${{ matrix.python-version }})
94-
needs: [ version-check-job ]
92+
Security:
93+
name: Security Checks (Python-${{ matrix.python-version }})
94+
needs: [ Version-Check ]
9595
runs-on: ubuntu-latest
9696
strategy:
9797
fail-fast: false
@@ -107,7 +107,7 @@ jobs:
107107
with:
108108
python-version: ${{ matrix.python-version }}
109109

110-
- name: Run security
110+
- name: Run security linter
111111
run: poetry run nox -s security
112112

113113
- name: Upload Artifacts
@@ -117,9 +117,9 @@ jobs:
117117
path: .security.json
118118
include-hidden-files: true
119119

120-
tests-job:
120+
Tests:
121121
name: Tests (Python-${{ matrix.python-version }}, Exasol-${{ matrix.exasol-version}})
122-
needs: [ build-documentation-job, lint-job, type-check-job ]
122+
needs: [ Documentation, Lint, Type-Check, Security]
123123
runs-on: ubuntu-latest
124124
env:
125125
GITHUB_TOKEN: ${{ secrets.ALTERNATIVE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}

.github/workflows/ci.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ on:
88
- "main"
99
- "master"
1010
pull_request:
11-
types: [ opened, reopened ]
11+
types: [opened, reopened]
1212
schedule:
1313
# “At 00:00 on every 7th day-of-month from 1 through 31.” (https://crontab.guru)
1414
- cron: "0 0 1/7 * *"
1515

1616
jobs:
17-
ci-job:
18-
uses: ./.github/workflows/checks.yml
1917

20-
metrics:
21-
needs: [ ci-job ]
18+
CI:
19+
uses: ./.github/workflows/merge-gate.yml
20+
secrets: inherit
21+
22+
Metrics:
23+
needs: [ CI ]
2224
uses: ./.github/workflows/report.yml

.github/workflows/merge-gate.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Merge-Gate
2+
3+
on:
4+
workflow_call:
5+
secrets:
6+
ALTERNATIVE_GITHUB_TOKEN:
7+
required: false
8+
9+
jobs:
10+
11+
fast-checks:
12+
name: Fast
13+
uses: ./.github/workflows/checks.yml
14+
15+
slow-checks:
16+
name: Slow
17+
runs-on: ubuntu-latest
18+
19+
# Even though the environment "manual-approval" will be created automatically,
20+
# it still needs to be configured to require interactive review.
21+
# See project settings on GitHub (Settings / Environments / manual-approval).
22+
environment: manual-approval
23+
24+
# Replace the steps below with the required actions
25+
# and/or add additional jobs if required
26+
# Note:
27+
# If you add additional jobs, make sure they are added as a requirement
28+
# to the approve-merge job's input requirements (needs).
29+
steps:
30+
- name: Tests
31+
run: |
32+
echo "Slow tests ran successfully"
33+
34+
35+
# This job ensures inputs have been executed successfully.
36+
approve-merge:
37+
name: Allow Merge
38+
runs-on: ubuntu-latest
39+
# If you need additional jobs to be part of the merge gate, add them below
40+
needs: [ fast-checks, slow-checks ]
41+
42+
# Each job requires a step, so we added this dummy step.
43+
steps:
44+
- name: Approve
45+
run: |
46+
echo "Merge Approved"

.github/workflows/report.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ on:
88

99
jobs:
1010

11-
report:
12-
name: Generate Status Report
11+
Report:
1312
runs-on: ubuntu-latest
1413
env:
1514
GITHUB_TOKEN: ${{ secrets.ALTERNATIVE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}

doc/_static/ci-cd-workflow.png

-82.9 KB
Binary file not shown.

doc/_static/ci-workflow.png

-75.4 KB
Binary file not shown.

doc/_static/pr-merge-workflow.png

-80.9 KB
Binary file not shown.

doc/changes/unreleased.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,26 @@
33
## ✨ Added
44

55
* Added cookiecutter-template for creating new project
6-
7-
## 🔩 Internal
8-
9-
* Update depdency constraints
10-
* Relock dependencies
6+
* [#246](https://github.com/exasol/python-toolbox/issues/246): Added standard branch protection workflow
117

128
## 🐞 Bug Fixes
139

14-
* #181 Updated metrics related workflows
15-
* #225 Fixed broken reference to version file in workflow
10+
* [#181](https://github.com/exasol/python-toolbox/issues/181): Updated metrics related workflows
11+
* [#225](https://github.com/exasol/python-toolbox/issues/225): Fixed broken reference to version file in workflow
1612
* Fixed coverage for empty project
1713

1814
## ⚒️ Refactorings
1915

20-
* #219: Updated project template configuration
16+
* [#219](https://github.com/exasol/python-toolbox/issues/219): Updated project template configuration
2117
* Updated actions/checkout to v4
2218

2319
## 📚 Documentation
2420
* Add Python Styleguide
2521
* Add Issue Guide
2622
* Updated User Documentation
23+
24+
## 🔩 Internal
25+
26+
* Update depdency constraints
27+
* Relock dependencies
28+

doc/user_guide/workflows.rst

Lines changed: 21 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,45 @@
1-
Workflows (CI/CD)
2-
=================
1+
Github Workflows
2+
================
33

4-
Generate CI & CI/CD workflows
5-
-----------------------------
6-
7-
The exasol-toolbox simplifies and supports 3 easily maintainable workflows.
8-
in order to make them work follow the description bellow.
4+
The exasol-toolbox ships with various GitHub workflows. By default, we suggest installing all of them,
5+
while the core workflows are:
96

107
**Workflows**:
118

129
* CI
13-
Verifies PR's and regularly checks the project.
10+
Verifies PRs and regularly checks the project.
1411

15-
* CI/CD
16-
Verifies and publishes releases of the project.
12+
* CD
13+
Publishes releases of the project.
1714

1815
* PR-Merge
19-
Validates merges and updates the documentation.
20-
21-
0. Determine the toolbox version
22-
++++++++++++++++++++++++++++++++
23-
One of the snippets bellow, should do the trick:
24-
25-
#.
16+
Validates merges and updates the documentation.
2617

27-
.. code-block:: shell
2818

29-
poetry show exasol-toolbox
19+
The toolbox command itself, :code:`tbx`, provides various CLI functions to help you maintain those workflows.
20+
For further help, run the command :code:`tbx workflow --help`.
3021

31-
#.
32-
33-
.. code-block:: python
22+
1. Configure your project
23+
+++++++++++++++++++++++++
3424

35-
python -c "from exasol.toolbox.version import VERSION;print(VERSION)"
25+
* Make sure your GitHub project has access to a deployment token for PyPi with the following name: **PYPI_TOKEN**. It should be available to the repository either as an Organization-, Repository-, or Environment-secret.
3626

37-
1. Configure your project
38-
++++++++++++++++++++++++++
39-
Make sure your github project has access to a deployment token for PyPi with the following name: **PYPI_TOKEN**.
40-
It should be available to the repository either as Organization-, Repository- or Environment- secret.
27+
* If your CI workflow involves slow or expensive steps you can guard these to be executed only after manual approval. The CI workflow will automaticall create a GitHub environment named :code:`manual-approval`. You only need to add reviewers in (:code:`Settings/Environments/manual-approval`) and move the steps to be guarded into the related section in job :code:`slow-checks` in file :code:`.github/workflows/merge-gate.yml`.
4128

42-
2. Add the standard workflows to your project
43-
+++++++++++++++++++++++++++++++++++++++++++++
29+
2. Add all workflows to your project
30+
++++++++++++++++++++++++++++++++++++
4431

4532
.. code-block:: shell
4633
4734
tbx workflow install all
4835
4936
.. warning::
5037

51-
If you already have various workflows you may want to run the
52-
:code:`update` instead of the :code:`install` command.
53-
54-
CI Workflow
55-
___________
56-
57-
.. figure:: ../_static/ci-workflow.png
58-
:alt: ci-workflow
59-
60-
To enable this workflow, add a file with the name *ci.yml* in your *.github/workflows* folder
61-
and add the following content:
62-
63-
.. literalinclude:: ../../exasol/toolbox/templates/github/workflows/ci.yml
64-
:language: yaml
65-
66-
CI/CD Workflow
67-
______________
68-
69-
.. attention::
70-
71-
Requires PYPI token to be available
72-
73-
.. figure:: ../_static/ci-cd-workflow.png
74-
:alt: ci-cd-workflow
75-
76-
To enable this workflow, add a file with the name *ci-cd.yml* in your *.github/workflows* folder
77-
and add the following content:
78-
79-
.. literalinclude:: ../../exasol/toolbox/templates/github/workflows/ci-cd.yml
80-
:language: yaml
81-
82-
PR-Merge Workflow
83-
_________________
84-
85-
.. figure:: ../_static/pr-merge-workflow.png
86-
:alt: pr-merge-workflow
87-
88-
To enable this workflow, add a file with the name *pr-merge.yml* in your *.github/workflows* folder
89-
and add the following content:
90-
91-
.. literalinclude:: ../../exasol/toolbox/templates/github/workflows/pr-merge.yml
92-
:language: yaml
38+
#. If you already have various workflows, you may want to run the :code:`update` command instead of the :code:`install` command.
9339

94-
In order to make merging to the main branch faster you can skip running the
95-
tests again in this workflow.
40+
#. Some workflows depend on other workflows. Please ensure you have all the required workflows if you do not install all of them.
9641

97-
Before removing the ``ci-job`` from the workflow by please make sure the
98-
following prerequisites are met, as in some circumstances these tests might be
99-
the last or even only chance to detect problems.
42+
3. Update Branch Protection
43+
++++++++++++++++++++++++++++
10044

101-
* GitHub branch protection for main branch is properly configured.
102-
* All dependencies are pointing to proper pypi packages in specific versions, i.e. no
103-
dependencies to the main branch of other git repositories.
104-
* Development branches are short-lived and merged to main branch soon after
105-
finishing tests in the context of a pull request.
45+
The best and most maintainable way to have solid branch protection (:code:`Settings/Branches/main`) is to require the workflow :code:`CI / Allow Merge` to pass successfully.

0 commit comments

Comments
 (0)