danishi/dynamodb-csv

View on GitHub
.github/workflows/release.yaml

Summary

Maintainability
Test Coverage
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