-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add python CI to support automatic release
- Loading branch information
1 parent
b168ace
commit 85a4282
Showing
4 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
name: Python CI/CD with Automatic and Manual Versioning | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
description: 'Version to release (e.g., 2024.2.11)' | ||
required: false | ||
default: '' | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout source code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install setuptools wheel twine | ||
pip install -r requirements.txt | ||
- name: Run tests | ||
run: | | ||
python -m pip install pytest | ||
pytest | ||
deploy: | ||
runs-on: ubuntu-latest | ||
|
||
needs: build | ||
|
||
steps: | ||
- name: Checkout source code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Determine Version to Release | ||
id: determine_version | ||
run: | | ||
if [ -z "${{ github.event.inputs.version }}" ]; then | ||
# No version provided, use version.txt | ||
VERSION=$(cat version.txt) | ||
else | ||
# Use the manually provided version | ||
VERSION="${{ github.event.inputs.version }}" | ||
fi | ||
echo "version=$VERSION" >> $GITHUB_ENV | ||
- name: Build distribution | ||
run: | | ||
python setup.py sdist bdist_wheel | ||
- name: Deploy to PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
password: ${{ secrets.PYPI_API_TOKEN }} | ||
|
||
- name: Tag Release in GitHub | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
VERSION=${{ env.version }} | ||
git tag -a "$VERSION" -m "Release $VERSION" | ||
git push origin "$VERSION" | ||
increment-version: | ||
runs-on: ubuntu-latest | ||
|
||
needs: deploy | ||
|
||
steps: | ||
- name: Checkout source code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Increment Version | ||
id: increment_version | ||
run: | | ||
VERSION=${{ env.version }} | ||
YEAR=$(date +%Y) | ||
RELEASE=$(echo $VERSION | cut -d '.' -f 2) | ||
# Increment the release version after deployment | ||
NEW_VERSION="$YEAR.$((RELEASE + 1)).1" | ||
echo $NEW_VERSION > version.txt | ||
echo "new_version=$NEW_VERSION" >> $GITHUB_ENV | ||
sed -i "s/version=.*,/version='$NEW_VERSION',/" setup.py | ||
- name: Commit and Push Incremented Version | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
git config --global user.name "GitHub Actions" | ||
git config --global user.email "[email protected]" | ||
git add version.txt setup.py | ||
git commit -m "Increment version to ${{ env.new_version }}" | ||
git push origin main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Test Pull Request | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout source code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: Run Tests | ||
run: | | ||
python -m pip install pytest | ||
pytest | ||
- name: Report Test Results | ||
if: failure() | ||
run: | | ||
echo "::error::Some tests failed. Check the logs for details." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,12 @@ | |
with open("README.md", "r") as f: | ||
long_description = f.read() | ||
|
||
with open("version.txt", "r") as f: | ||
version = f.read() | ||
|
||
setup( | ||
name="watergate_local_api", # Replace with your own username | ||
version="2024.2.1", | ||
version=version, | ||
author="Watergate", | ||
author_email="[email protected]", | ||
description="Python package to interact with the Watergate Local API.", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2024.3.1 |