Skip to content

Instantly share code, notes, and snippets.

@jakecyr
Last active March 23, 2023 04:23
Show Gist options
  • Select an option

  • Save jakecyr/f57646a724fa4af2ae5acc4c686b3fb6 to your computer and use it in GitHub Desktop.

Select an option

Save jakecyr/f57646a724fa4af2ae5acc4c686b3fb6 to your computer and use it in GitHub Desktop.
Python Semantic Release
image: python:3.9
stages:
- build
- test
- release
- sphinx
variables:
NEXUS_URL: "https://your-nexus-url.com"
NEXUS_USERNAME: "your-nexus-username"
NEXUS_PASSWORD: "your-nexus-password"
before_script:
- python -V
- pip install -r pyproject.toml
build:
stage: build
script:
- python setup.py bdist_wheel
test:
stage: test
script:
- pytest
release:
stage: release
only:
- master
script:
- pip install python-semantic-release
- semantic-release version
- export VERSION=$(semantic-release print-version)
- echo "New version: $VERSION"
- semantic-release changelog
- git config user.name "Your GitLab Username"
- git config user.email "your.email@example.com"
# - sed -i "s/version = .*/version = \"$VERSION\"/" pyproject.toml
- sed -i "" "s/\(^version = \).*/\1\"$VERSION\"/" pyproject.toml
- git add CHANGELOG.md pyproject.toml
- git commit -m "Update CHANGELOG.md and pyproject.toml [skip ci]"
- git tag "v$VERSION"
- git remote set-url origin "https://oauth2:${GITLAB_TOKEN}@gitlab.com/your-username/your-repo.git"
- git push origin master --tags
- python setup.py bdist_wheel
- pip install twine
- twine upload --repository-url $NEXUS_URL --username $NEXUS_USERNAME --password $NEXUS_PASSWORD dist/*
sphinx:
stage: sphinx
script:
- git fetch
- git checkout master
- export VERSION=$(grep -oP '(?<=version = ")[^"]*' pyproject.toml)
- echo "Current version: $VERSION"
- pip install sphinx
- sphinx-build -b html docs/source docs/build/html
artifacts:
paths:
- docs/build/html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment