Skip to content

Commit

Permalink
Merge branch 'main' into update-changes-#74
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannis-Mittenzwei committed Oct 24, 2024
2 parents 8477693 + 5cca213 commit 9500067
Show file tree
Hide file tree
Showing 26 changed files with 417 additions and 338 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI/CD
name: CD

on:
push:
Expand All @@ -11,19 +11,8 @@ jobs:
name: Check Release Tag
uses: ./.github/workflows/check-release-tag.yml

ci-job:
name: Checks
needs: [ check-tag-version-job ]
uses: ./.github/workflows/checks.yml
secrets: inherit

cd-job:
name: Continuous Delivery
needs: [ ci-job ]
uses: ./.github/workflows/build-and-publish.yml
secrets:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}

metrics:
needs: [ ci-job ]
uses: ./.github/workflows/report.yml
30 changes: 15 additions & 15 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ on:

jobs:

version-check-job:
name: Version Check
Version-Check:
name: Version
runs-on: ubuntu-latest

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

build-documentation-job:
name: Build Documentation
needs: [ version-check-job ]
Documentation:
name: Docs
needs: [ Version-Check ]
runs-on: ubuntu-latest

steps:
Expand All @@ -40,9 +40,9 @@ jobs:
run: |
poetry run python -m nox -s build-docs
lint-job:
Lint:
name: Linting (Python-${{ matrix.python-version }})
needs: [ version-check-job ]
needs: [ Version-Check ]
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -68,9 +68,9 @@ jobs:
path: .lint.txt
include-hidden-files: true

type-check-job:
Type-Check:
name: Type Checking (Python-${{ matrix.python-version }})
needs: [ version-check-job ]
needs: [ Version-Check ]
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -89,9 +89,9 @@ jobs:
- name: Run type-check
run: poetry run nox -s type-check

security-job:
name: Security Checking (Python-${{ matrix.python-version }})
needs: [ version-check-job ]
Security:
name: Security Checks (Python-${{ matrix.python-version }})
needs: [ Version-Check ]
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -107,7 +107,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Run security
- name: Run security linter
run: poetry run nox -s security

- name: Upload Artifacts
Expand All @@ -117,9 +117,9 @@ jobs:
path: .security.json
include-hidden-files: true

tests-job:
Tests:
name: Tests (Python-${{ matrix.python-version }}, Exasol-${{ matrix.exasol-version}})
needs: [ build-documentation-job, lint-job, type-check-job ]
needs: [ Documentation, Lint, Type-Check, Security]
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.ALTERNATIVE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
Expand Down
12 changes: 7 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ on:
- "main"
- "master"
pull_request:
types: [ opened, reopened ]
types: [opened, reopened]
schedule:
# “At 00:00 on every 7th day-of-month from 1 through 31.” (https://crontab.guru)
- cron: "0 0 1/7 * *"

jobs:
ci-job:
uses: ./.github/workflows/checks.yml

metrics:
needs: [ ci-job ]
CI:
uses: ./.github/workflows/merge-gate.yml
secrets: inherit

Metrics:
needs: [ CI ]
uses: ./.github/workflows/report.yml
46 changes: 46 additions & 0 deletions .github/workflows/merge-gate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Merge-Gate

on:
workflow_call:
secrets:
ALTERNATIVE_GITHUB_TOKEN:
required: false

jobs:

fast-checks:
name: Fast
uses: ./.github/workflows/checks.yml

slow-checks:
name: Slow
runs-on: ubuntu-latest

# Even though the environment "manual-approval" will be created automatically,
# it still needs to be configured to require interactive review.
# See project settings on GitHub (Settings / Environments / manual-approval).
environment: manual-approval

# Replace the steps below with the required actions
# and/or add additional jobs if required
# Note:
# If you add additional jobs, make sure they are added as a requirement
# to the approve-merge job's input requirements (needs).
steps:
- name: Tests
run: |
echo "Slow tests ran successfully"
# This job ensures inputs have been executed successfully.
approve-merge:
name: Allow Merge
runs-on: ubuntu-latest
# If you need additional jobs to be part of the merge gate, add them below
needs: [ fast-checks, slow-checks ]

# Each job requires a step, so we added this dummy step.
steps:
- name: Approve
run: |
echo "Merge Approved"
3 changes: 1 addition & 2 deletions .github/workflows/report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ on:

jobs:

report:
name: Generate Status Report
Report:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.ALTERNATIVE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
Expand Down
Binary file removed doc/_static/ci-cd-workflow.png
Binary file not shown.
Binary file removed doc/_static/ci-workflow.png
Binary file not shown.
Binary file removed doc/_static/pr-merge-workflow.png
Binary file not shown.
2 changes: 2 additions & 0 deletions doc/changes/changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

* [unreleased](unreleased.md)
* [0.15.0](changes_0.15.0.md)
* [0.14.0](changes_0.14.0.md)
* [0.13.0](changes_0.13.0.md)
* [0.12.0](changes_0.12.0.md)
Expand All @@ -23,6 +24,7 @@
hidden:
---
unreleased
changes_0.15.0
changes_0.14.0
changes_0.13.0
changes_0.12.0
Expand Down
28 changes: 28 additions & 0 deletions doc/changes/changes_0.15.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 0.15.0 - 2024-09-27

## ✨ Added

* Added cookiecutter-template for creating new project
* [#246](https://github.com/exasol/python-toolbox/issues/246): Added standard branch protection workflow
* #74: Added security linter nox task

## 🐞 Bug Fixes

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

## ⚒️ Refactorings

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

## 📚 Documentation
* Add Python Styleguide
* Add Issue Guide
* Updated User Documentation

## 🔩 Internal

* Update depdency constraints
* Relock dependencies
22 changes: 0 additions & 22 deletions doc/changes/unreleased.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,4 @@
# Unreleased

## ✨ Added

* Added cookiecutter-template for creating new project
* #74: Added security linter nox task

## 🔩 Internal

* Update depdency constraints
* Relock dependencies

## 🐞 Bug Fixes

* #181 Updated metrics related workflows
* Fixed coverage for empty project

## ⚒️ Refactorings

* #219: Updated project template configuration
* Updated actions/checkout to v4

## 📚 Documentation
* Add Python Styleguide
* Add Issue Guide
* Updated User Documentation
102 changes: 21 additions & 81 deletions doc/user_guide/workflows.rst
Original file line number Diff line number Diff line change
@@ -1,105 +1,45 @@
Workflows (CI/CD)
=================
Github Workflows
================

Generate CI & CI/CD workflows
-----------------------------

The exasol-toolbox simplifies and supports 3 easily maintainable workflows.
in order to make them work follow the description bellow.
The exasol-toolbox ships with various GitHub workflows. By default, we suggest installing all of them,
while the core workflows are:

**Workflows**:

* CI
Verifies PR's and regularly checks the project.
Verifies PRs and regularly checks the project.

* CI/CD
Verifies and publishes releases of the project.
* CD
Publishes releases of the project.

* PR-Merge
Validates merges and updates the documentation.

0. Determine the toolbox version
++++++++++++++++++++++++++++++++
One of the snippets bellow, should do the trick:

#.
Validates merges and updates the documentation.

.. code-block:: shell

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

#.

.. code-block:: python
1. Configure your project
+++++++++++++++++++++++++

python -c "from exasol.toolbox.version import VERSION;print(VERSION)"
* 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.

1. Configure your project
++++++++++++++++++++++++++
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 Organization-, Repository- or Environment- secret.
* 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`.

2. Add the standard workflows to your project
+++++++++++++++++++++++++++++++++++++++++++++
2. Add all workflows to your project
++++++++++++++++++++++++++++++++++++

.. code-block:: shell
tbx workflow install all
.. warning::

If you already have various workflows you may want to run the
:code:`update` instead of the :code:`install` command.

CI Workflow
___________

.. figure:: ../_static/ci-workflow.png
:alt: ci-workflow

To enable this workflow, add a file with the name *ci.yml* in your *.github/workflows* folder
and add the following content:

.. literalinclude:: ../../exasol/toolbox/templates/github/workflows/ci.yml
:language: yaml

CI/CD Workflow
______________

.. attention::

Requires PYPI token to be available

.. figure:: ../_static/ci-cd-workflow.png
:alt: ci-cd-workflow

To enable this workflow, add a file with the name *ci-cd.yml* in your *.github/workflows* folder
and add the following content:

.. literalinclude:: ../../exasol/toolbox/templates/github/workflows/ci-cd.yml
:language: yaml

PR-Merge Workflow
_________________

.. figure:: ../_static/pr-merge-workflow.png
:alt: pr-merge-workflow

To enable this workflow, add a file with the name *pr-merge.yml* in your *.github/workflows* folder
and add the following content:

.. literalinclude:: ../../exasol/toolbox/templates/github/workflows/pr-merge.yml
:language: yaml
#. If you already have various workflows, you may want to run the :code:`update` command instead of the :code:`install` command.

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

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

* GitHub branch protection for main branch is properly configured.
* All dependencies are pointing to proper pypi packages in specific versions, i.e. no
dependencies to the main branch of other git repositories.
* Development branches are short-lived and merged to main branch soon after
finishing tests in the context of a pull request.
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.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup Python & Poetry Environment
uses: exasol/python-toolbox/.github/actions/python-environment@0.14.0
uses: exasol/python-toolbox/.github/actions/python-environment@0.15.0

- name: Build Artifacts
run: poetry build
Expand Down
Loading

0 comments on commit 9500067

Please sign in to comment.