Skip to content

Commit

Permalink
ci: Adds version writer
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Hui committed Feb 9, 2024
1 parent 4207fd3 commit 7cea8e3
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 4 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ jobs:
fetch-depth: 0
submodules: recursive
ref: 37-feat-semver

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'pip'

- name: Install Python Dependencies
run: |
python -m pip install -r requirements.txt
- name: Set up NPM
uses: actions/setup-node@v4
Expand Down
177 changes: 174 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Created by https://www.toptal.com/developers/gitignore/api/linux,macos,windows,particle,c++
# Edit at https://www.toptal.com/developers/gitignore?templates=linux,macos,windows,particle,c++
# Created by https://www.toptal.com/developers/gitignore/api/c++,linux,macos,windows,particle,python
# Edit at https://www.toptal.com/developers/gitignore?templates=c++,linux,macos,windows,particle,python

### C++ ###
# Prerequisites
Expand Down Expand Up @@ -90,6 +90,177 @@ Temporary Items

*.bin

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

### Python Patch ###
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
poetry.toml

# ruff
.ruff_cache/

# LSP config files
pyrightconfig.json

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Expand All @@ -116,7 +287,7 @@ $RECYCLE.BIN/
# Windows shortcuts
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/linux,macos,windows,particle,c++
# End of https://www.toptal.com/developers/gitignore/api/c++,linux,macos,windows,particle,python
smartfin-fw3.cpp
target/
*.bin
Expand Down
2 changes: 1 addition & 1 deletion .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[
"@semantic-release/exec",
{
"prepareCmd": "echo ${nextRelease.version} ${branch.name} ${commits.length} ${Date.now()}"
"prepareCmd": "python semantic_release_prepare.py ${nextRelease.version} ${branch.name} src/vers.hpp"
}
]
]
Expand Down
8 changes: 8 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Semantic Release",
"type": "debugpy",
"request": "launch",
"program": "semantic_release_prepare.py",
"console": "integratedTerminal",
"args": ["1.2.3", "37-feat-semver", "src/vers.hpp"]
},
{
"type": "cortex-debug",
"request": "attach",
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
semantic-version
41 changes: 41 additions & 0 deletions semantic_release_prepare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'''Prepares the version information
'''
import argparse
import re
from pathlib import Path

import semantic_version


def main():
"""Places the version number into the version file
"""
parser = argparse.ArgumentParser()
parser.add_argument('version')
parser.add_argument('branch')
parser.add_argument('vers_header', type=Path)
args = parser.parse_args()
version = semantic_version.Version(args.version)
version_header = args.vers_header


major_regex = r'#define FW_MAJOR_VERSION\s*\d*'
minor_regex = r'#define FW_MINOR_VERSION\s*\d*'
patch_regex = r'#define FW_BUILD_NUM\s*\d*'
major_subst = f'#define FW_MAJOR_VERSION {version.major}'
minor_subst = f'#define FW_MINOR_VERSION {version.minor}'
patch_subst = f'#define FW_BUILD_NUM {version.patch}'

new_lines = []
with open(version_header, 'r', encoding='utf-8') as handle:
for line in handle:
line = re.sub(major_regex, major_subst, line)
line = re.sub(minor_regex, minor_subst, line)
line = re.sub(patch_regex, patch_subst, line)
new_lines.append(line)

with open(version_header, 'w', encoding='utf-8') as handle:
handle.writelines(new_lines)

if __name__ == '__main__':
main()

0 comments on commit 7cea8e3

Please sign in to comment.