Skip to content

Put that back where it was #735

Put that back where it was

Put that back where it was #735

name: Docker publish
on:
push:
# Publish `main` as Docker `latest` image.
branches:
- main
# Publish `v1.2.3` tags as releases.
tags:
- v*
# Run tests for any PRs.
pull_request:
branches: [main]
env:
IMAGE_NAME: thetagang
DOCKERHUB_ACCOUNT: brndnmtthws
DOCKER_BUILDKIT: 1
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
poetry-version: ["1.4.0"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
id: setup-python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Cache ~/.cache/pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: python-${{ steps.setup-python.outputs.python-version }}
- name: Cache ~/.cache/pypoetry
uses: actions/cache@v3
with:
path: ~/.cache/pypoetry
key: python-${{ steps.setup-python.outputs.python-version }}-poetry-${{ hashFiles('poetry.lock') }}
- name: Install poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ matrix.poetry-version }}
- name: Install dependencies
run: |
poetry install
- name: Test with pytest
run: |
poetry run py.test
build-and-push:
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v3
- name: Cache TWS
id: cache-tws
uses: actions/cache@v3
env:
cache-name: cache-tws
with:
path: tws/
key: ${{ runner.os }}-publish-${{ env.cache-name }}-${{ hashFiles('extract-installer.sh') }}
- name: Extract TWS installer
if: steps.cache-tws.outputs.cache-hit != 'true'
run: ./extract-installer.sh
- name: Set up Python ${{ matrix.python-version }}
id: setup-python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Cache ~/.cache/pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: python-${{ steps.setup-python.outputs.python-version }}
- name: Cache ~/.cache/pypoetry
uses: actions/cache@v3
with:
path: ~/.cache/pypoetry
key: python-${{ steps.setup-python.outputs.python-version }}-poetry-${{ hashFiles('poetry.lock') }}
- name: Install poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: "1.4.0"
- name: Install dependencies
run: |
poetry install --only main --no-root
- name: Build package
run: |
poetry build
# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@main
with:
cosign-release: "v1.4.0"
- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v2
with:
image: tonistiigi/binfmt:latest
platforms: all
# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ github.actor }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ github.actor }}/${{ env.IMAGE_NAME }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64/v8
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
no-cache: ${{ startsWith(github.ref, 'refs/tags/') }}