.github/workflows/release.yaml
name: pypi-and-docker-hub-release
on:
push:
tags:
- "v*"
jobs:
deploy:
name: Python ${{ matrix.python-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
matrix:
python-version: ["3.12"]
os: [ubuntu-latest]
steps:
- name: Checkout ๐
uses: actions/checkout@v4
# PyPI release
- name: Setup Python ${{ matrix.python-version }} ๐ง
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Python Install dependencies ๐งน
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish PyPI ๐
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
- name: Sleep for 60 seconds ๐ค
run: sleep 60s
shell: bash
# Docker Hub release
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: danishi/dynamodb-csv
- name: Log in to Docker Hub ๐ช
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and Push to Docker Hub ๐
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# GitHub Packages release
- name: Set env ๐ง
run: |
OWNER=$(echo ${{ github.repository_owner }})
echo "RELEASE_OWNER=$OWNER" >> $GITHUB_ENV
IMAGE=dynamodb-csv
echo "RELEASE_IMAGE=$IMAGE" >> $GITHUB_ENV
VERSION=$(echo ${{ github.ref }} | sed -e "s#refs/tags/##g")
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
- name: Build ๐จ
run: |
docker build -t ghcr.io/${{ env.RELEASE_OWNER }}/${{ env.RELEASE_IMAGE }}:${{ env.RELEASE_VERSION }} .
- name: Login ๐ช
run: |
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ env.RELEASE_OWNER }} --password-stdin
- name: Push by tag name ๐
run: |
docker push ghcr.io/${{ env.RELEASE_OWNER }}/${{ env.RELEASE_IMAGE }}:${{ env.RELEASE_VERSION }}
- name: Push by latest ๐
run: |
docker image tag ghcr.io/${{ env.RELEASE_OWNER }}/${{ env.RELEASE_IMAGE }}:${{ env.RELEASE_VERSION }} ghcr.io/${{ env.RELEASE_OWNER }}/${{ env.RELEASE_IMAGE }}:latest
docker push ghcr.io/${{ env.RELEASE_OWNER }}/${{ env.RELEASE_IMAGE }}:latest