Skip to content

Commit 94a20f2

Browse files
committed
[ci] Added GitHub workflow to replicate commits to version branch
Created re-usable workflow for replication commits from the master branch to version branch.
1 parent 43d94cd commit 94a20f2

File tree

4 files changed

+121
-0
lines changed

4 files changed

+121
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Replicate Commits to Version Branch
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
module_name:
7+
description: 'The name of the module'
8+
required: true
9+
type: string
10+
11+
jobs:
12+
replicate:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v2
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v2
21+
with:
22+
python-version: '3.x'
23+
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
28+
- name: Get version
29+
id: get_version
30+
run: |
31+
VERSION=$(python -c "
32+
from ${{ inputs.module_name }} import VERSION
33+
print(f'{VERSION[0]}.{VERSION[1]}')
34+
")
35+
echo "VERSION=$VERSION" >> $GITHUB_ENV
36+
37+
- name: Configure Git
38+
run: |
39+
git config --global user.name 'github-actions[bot]'
40+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
41+
42+
- name: Rebase changes onto version branch
43+
run: |
44+
if git ls-remote --heads origin $VERSION | grep -sw $VERSION; then
45+
git fetch origin --unshallow
46+
git checkout -b $VERSION origin/$VERSION
47+
git rebase origin/master
48+
else
49+
git checkout -b $VERSION
50+
fi
51+
git push origin $VERSION
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Replicate Commits to Version Branch
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
version-branch:
10+
uses: openwisp/openwisp-utils/.github/workflows/reusable-version-branch.yml@master
11+
with:
12+
module_name: openwisp_utils

docs/developer/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Developer Docs
1616
./admin-utilities.rst
1717
./test-utilities.rst
1818
./other-utilities.rst
19+
./reusable-workflows.rst
1920

2021
Other useful resources:
2122

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
Re-usable GitHub Workflows
2+
==========================
3+
4+
Replicate Commits to Version Branch
5+
-----------------------------------
6+
7+
This re-usable workflow replicates commits from the ``master`` branch to a
8+
version branch. The version branch name is derived from the version of the
9+
Python package specified in the workflow.
10+
11+
Version branches are essential during development to ensure that each
12+
OpenWISP module depends on compatible versions of its OpenWISP
13+
dependencies. Without version branches, modules depending on the
14+
``master`` branch of other modules may encounter errors, as the ``master``
15+
branch could include future changes that are incompatible with previous
16+
versions. This makes it impossible to build a specific commit reliably
17+
after such changes.
18+
19+
To address this, we use version branches so that each module can depend on
20+
a compatible version of its dependencies during development. Managing
21+
these version branches manually is time-consuming, which is why this
22+
re-usable GitHub workflow automates the process of keeping version
23+
branches synchronized with the ``master`` branch.
24+
25+
You can invoke this workflow from another workflow using the following
26+
example:
27+
28+
.. code-block:: yaml
29+
30+
name: Replicate Commits to Version Branch
31+
32+
on:
33+
push:
34+
branches:
35+
- master
36+
37+
jobs:
38+
version-branch:
39+
uses: openwisp/openwisp-utils/.github/workflows/reusable-version-branch.yml@master
40+
with:
41+
# The name of the Python package (required)
42+
module_name: openwisp_utils
43+
44+
.. note::
45+
46+
If the ``master`` branch is force-pushed, this workflow will fail due
47+
to conflicts. To resolve this, you must manually synchronize the
48+
version branch with the ``master`` branch. You can use the following
49+
commands to perform this synchronization:
50+
51+
.. code-block:: bash
52+
53+
VERSION=<enter-version-number> # e.g. 1.2
54+
git fetch origin
55+
git checkout $VERSION
56+
git reset --hard origin/master
57+
git push origin $VERSION --force-with-lease

0 commit comments

Comments
 (0)