Skip to content

Python package

Python package #379

# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Python package
on:
release:
types:
- created
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Get version values
id: vars
run: |
echo ::set-output name=version::$(cat src/tesla_ce/lib/data/VERSION)
echo ::set-output name=tag::${GITHUB_REF#refs/*/}
- name: Show captured versions
run: |
echo 'Version in source code: ${{ steps.vars.outputs.version }}'
echo 'Release version: ${{ steps.vars.outputs.tag }}'
- name: Check version tag
uses: nick-invision/assert-action@v1.1.0
with:
expected: ${{ steps.vars.outputs.tag }}
actual: ${{ steps.vars.outputs.version }}
comparison: exact
build:
needs: check
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [3.9, ]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get version value
id: vars
run: |
echo ::set-output name=version::$(cat src/tesla_ce/lib/data/VERSION)
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest pip-tools pytest-mock mock
if [ -f requirements.in ]; then pip-compile; fi
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Install TeSLA CE Package
run: |
python setup.py install
- name: Fossa update license analysis
if: matrix.python-version == 3.9
continue-on-error: true
run: |
curl -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/fossas/fossa-cli/master/install-latest.sh | bash
# fossa init
FOSSA_API_KEY=${{ secrets.FOSSA_API_KEY}} fossa analyze
publish:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Store version
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
- name: Build package
run: |
# Build requirements
python -m pip install --upgrade pip
python -m pip install pip-tools twine
pip-compile
# Set the version
echo '${{ steps.vars.outputs.tag }}' > src/tesla_ce/lib/data/VERSION
# Build wheel
python setup.py sdist bdist_wheel
# Publish the package
python -m twine upload dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
docker_tag:
needs: publish
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Store version
id: vars
run: |
echo ::set-output name=tag::${GITHUB_REF#refs/*/}
- name: Whait package to be available
run: |
sudo apt-get install -y jq
while [ $(curl -Ls https://pypi.org/pypi/tesla-ce/json | jq -r .info.version) != ${{ steps.vars.outputs.tag }} ]; do echo "Waiting package to be available...."; sleep 10s; done
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2.5.0
with:
push: true
tags: teslace/core:${{ steps.vars.outputs.tag }}, teslace/core:latest
file: docker/Dockerfile
build-args: TESLA_CE_VERSION=${{ steps.vars.outputs.tag }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
- name: Login to TeSLA CE Registry
uses: docker/login-action@v1
with:
username: ${{ secrets.TESLA_CE_REGISTRY_USERNAME }}
password: ${{ secrets.TESLA_CE_REGISTRY_TOKEN }}
registry: registry.tesla-ce.eu
- name: Push to TeSLA CE registry
run: |
docker pull teslace/core:${{ steps.vars.outputs.tag }}
docker tag teslace/core:${{ steps.vars.outputs.tag }} registry.tesla-ce.eu/tesla-ce/core:${{ steps.vars.outputs.tag }}
docker push registry.tesla-ce.eu/tesla-ce/core:${{ steps.vars.outputs.tag }}
docker tag teslace/core:${{ steps.vars.outputs.tag }} registry.tesla-ce.eu/tesla-ce/core:latest
docker push registry.tesla-ce.eu/tesla-ce/core:latest