Skip to content

Commit

Permalink
Add auto deployment to pypi (alpacahq#612)
Browse files Browse the repository at this point in the history
* Add initial workflow file for tagged releases

* Fix yaml spacing

* temp change trigger type to test

* Attempt to fix python 3.10 being turned into 3.1

* Attempt build package run

* Add tool to auto bump and tag version

* Change trigger back to tag, and add publish step

* add v prefix to created tags
  • Loading branch information
drew887 authored Apr 27, 2022
1 parent a9055b9 commit 382fe2d
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/publish-pypi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Run tests & Publish Python 🐍 distributions 📦 to PyPI

on:
push:
tags:
- '*'

jobs:
tests-ci:
strategy:
fail-fast: false
matrix:
# you have to quote any version number ending in a 0 or gh truncates it. ie 3.10 turned into 3.1
python-version: [ 3.6, 3.8, '3.10' ]
os: [ ubuntu-latest ] #in the future we should add windows here
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: pip install
run: |
pip install -r requirements/requirements.txt
pip install -r requirements/requirements_test.txt
- name: run tests
run: pytest .

build-n-publish:
name: Build the 🐍 package and push PyPI
runs-on: ubuntu-18.04
needs: tests-ci
steps:
- uses: actions/checkout@master
- name: Set up Python 3.9
uses: actions/setup-python@v1
with:
python-version: '3.10'
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
34 changes: 34 additions & 0 deletions tools/tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

VER_FILE="alpaca_trade_api/__init__.py"

# This script simply sets up the repo for a new tag
echo "Current version number is: "

grep "__version__" $VER_FILE


read -r -p "Please enter a new version number to bump to: " VERSION

echo -e "Updating init.py to $VERSION\n"

sed -i -e "s/__version__ = .*/__version__ = '$VERSION'/" $VER_FILE

read -r -n 1 -p "Would you like to git commit and tag now? (y/N): " YN

# there are better ways to get this in but 🤷
echo ""

case $YN in
y|Y )
echo "Okay, committing this change";
git commit -m "Version bump to $VERSION" -m "This commit was auto generated by a tool!"
git tag -a "v$VERSION" -m "Version bump to $VERSION" -m "This tag was auto generated by a tool!"
git tag --sort -refname | head -n 5
echo "Done!"
;;
* )
echo -e "Okay exiting now. $VER_FILE has still been edited to contain the new version\nFair warning!"
exit 0
;;
esac

0 comments on commit 382fe2d

Please sign in to comment.