Update python-ci.yml #11
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
name: Python CI/CD | |
on: | |
push: | |
branches: | |
- main # Change this to your default branch if it's not 'main' | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Python 3.8 | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.8' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Run tests with pytest | |
run: pytest | |
bump_version: | |
needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Install GitHub CLI | |
run: | | |
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo gpg --dearmor -o /usr/share/keyrings/githubcli-archive-keyring.gpg | |
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null | |
sudo apt update | |
sudo apt install gh | |
- name: Bump version and create a pull request | |
id: bump_version | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
# Create a new branch with a unique name | |
NEW_VERSION=$(python -c 'version = open("VERSION").read().strip().split("."); version[-1] = str(int(version[-1]) + 1); print(".".join(version))') | |
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV | |
echo "NEW_VERSION=$NEW_VERSION" # To make sure it's set correctly | |
echo "::set-output name=version::$NEW_VERSION" | |
git checkout -b bump-version-$NEW_VERSION | |
echo $NEW_VERSION > VERSION | |
git add VERSION | |
git commit -m "Bump version to $NEW_VERSION" | |
git push origin bump-version-$NEW_VERSION | |
# Create a pull request using GitHub CLI | |
gh pr create --base main --head bump-version-$NEW_VERSION --title "Bump version to $NEW_VERSION" --body "Automatic version bump to $NEW_VERSION" | |
create_release: | |
needs: bump_version | |
runs-on: ubuntu-latest | |
steps: | |
- name: Create GitHub Release | |
uses: actions/create-release@v1 | |
with: | |
tag_name: ${{ needs.bump_version.outputs.version }} # Access output variable from bump_version job | |
release_name: Release ${{ needs.bump_version.outputs.version }} | |
draft: false | |
prerelease: false | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
deploy-pypi: | |
needs: create_release | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.x' | |
- name: Install twine | |
run: pip install twine | |
- name: Build and Publish | |
env: | |
PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }} | |
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} | |
run: | | |
python setup.py sdist bdist_wheel | |
twine upload dist/* -u $PYPI_USERNAME -p $PYPI_PASSWORD | |
deploy-conda: | |
needs: create_release | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Conda | |
run: | | |
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh | |
bash miniconda.sh -b -p $HOME/miniconda | |
source "$HOME/miniconda/etc/profile.d/conda.sh" | |
conda config --set always_yes yes --set changeps1 no | |
conda update -q conda | |
- name: Build and Publish to Anaconda | |
env: | |
ANACONDA_USERNAME: ${{ secrets.ANACONDA_USERNAME }} | |
ANACONDA_PASSWORD: ${{ secrets.ANACONDA_PASSWORD }} | |
run: | | |
conda build . | |
anaconda login --user $ANACONDA_USERNAME --password $ANACONDA_PASSWORD | |
anaconda upload $HOME/miniconda/conda-bld/**/artifician*.tar.bz2 |