Skip to content

Commit 406d38b

Browse files
committed
ci(Versioning): semantic release setup and github action workflow
1 parent 40acc49 commit 406d38b

File tree

5 files changed

+136
-1
lines changed

5 files changed

+136
-1
lines changed

.github/workflows/ci-cd.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: CI-CD
2+
3+
# Controls when the action will run.
4+
on:
5+
# Triggers the workflow on push or pull request events but only for the main branch
6+
push:
7+
branches: [main]
8+
pull_request:
9+
branches: [main]
10+
11+
# Allows you to run this workflow manually from the Actions tab
12+
workflow_dispatch:
13+
14+
jobs:
15+
# check if everything works first
16+
tests:
17+
uses: ./.github/workflows/tests.yml
18+
19+
# make a new version next, release or prerelease
20+
release:
21+
needs: [tests]
22+
uses: ./.github/workflows/release.yml

.github/workflows/release.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Release
2+
3+
# Controls when the action will run.
4+
on:
5+
workflow_call:
6+
7+
jobs:
8+
# make a new version first, release or prerelease
9+
release:
10+
# Only run this job if new work is pushed to "main"
11+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
12+
runs-on: ubuntu-latest
13+
steps:
14+
15+
- name: Checking out the repo
16+
uses: actions/checkout@v4
17+
with:
18+
ref: main
19+
20+
- name: Setup git user
21+
shell: sh
22+
run: |
23+
git config user.name "${GITHUB_ACTOR}"
24+
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
25+
26+
- name: Setting up Python
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: 3.12
30+
cache: pip
31+
cache-dependency-path: requirements.txt
32+
33+
- name: Determine the next version number
34+
env:
35+
GH_TOKEN: {{'${{ secrets.GITHUB_TOKEN }}'}}
36+
shell: sh
37+
run: |
38+
set -x
39+
python -m pip install python-semantic-release
40+
NEWVER=$(semantic-release version --print)
41+
# version number updates with regexp which is not supported by
42+
# semantic_release.version_variables in pyproject.toml
43+
sed -i -e "s/v\([0-9]\+\.\)\{3\}/v$NEWVER./" README.md
44+
git add README.md
45+
# creates a release only if there are relevant changes/commits starting with 'fix/feat()'
46+
semantic-release version

.github/workflows/tests.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Tests
2+
3+
# Controls when the action will run.
4+
on:
5+
# Allows you to run this workflow manually from the Actions tab
6+
workflow_dispatch:
7+
8+
workflow_call:
9+
10+
jobs:
11+
# defining this job separately allows to refer to it later as job.needs dependency
12+
tests:
13+
timeout-minutes: 30
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
python_arch: ['x64']
18+
python:
19+
- 3.12
20+
# os: ['ubuntu', 'windows', 'macos']
21+
os: ['ubuntu']
22+
env:
23+
PYTHON: "${{ join(matrix.python, '.') }}" # e.g. '3.11'
24+
TOX_ENV: "${{ format('{0}{1}', 'py', join(matrix.python, '')) }}" # e.g. 'py311'
25+
runs-on: "${{ format('{0}-latest', matrix.os) }}"
26+
name: '"Test py-${{ join(matrix.python, \'.\') }} (${{ matrix.os }})"'
27+
steps:
28+
29+
- name: Checking out the repo
30+
uses: actions/checkout@v4
31+
with:
32+
ref: main
33+
34+
- name: Setting up Python
35+
uses: actions/setup-python@v5
36+
with:
37+
python-version: ${{ env.PYTHON }}
38+
architecture: ${{ matrix.python_arch }}
39+
cache: pip
40+
cache-dependency-path: "requirements.txt"
41+
42+
- name: Show installed package details
43+
shell: sh
44+
run: |
45+
pip list --format=freeze
46+
47+
- name: Run tests
48+
shell: sh
49+
run: |
50+
echo copier copy yapy-copier-template my-test-project

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# yapy-copier-template
1+
# yapy-copier-template (v1.0.0)
22

33
Yet Another Python [Copier][1] template for a Python modules and applications focussing on data science, processing and analysis.
44

semantic-release.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[semantic_release]
2+
version_variables = [ # version location
3+
]
4+
5+
[semantic_release.remote]
6+
ignore_token_for_push = true
7+
8+
[semantic_release.commit_parser_options] # same as in the template itself
9+
allowed_tags = ["build", "chore", "ci", "docs", "feat", "enh", "fix", "perf", "style", "refactor", "test"]
10+
minor_tags = ["feat", "enh"]
11+
patch_tags = ["fix", "perf"]
12+
13+
[semantic_release.changelog]
14+
exclude_commit_patterns = ["chore", ".*\\bGHA\\b.*", ".*\\b[gG][hH] actions?\\b.*"]
15+
16+
[semantic_release.publish]
17+
upload_to_vcs_release = false

0 commit comments

Comments
 (0)