Skip to content

fix: add version tag #8

fix: add version tag

fix: add version tag #8

name: Bump Version and Publish Docker Image
on:
push:
branches:
- main # Runs on pushes to the main branch
workflow_dispatch:
permissions:
packages: write
contents: write
jobs:
bump_version:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install Poetry
run: |
pip install poetry
poetry install
- name: Install bump2version
run: |
pip install bump2version
- name: Determine version bump type
id: version_type
run: |
if [[ "${{ github.event.head_commit.message }}" =~ "major" ]]; then
echo "bump_type=major" >> $GITHUB_ENV
elif [[ "${{ github.event.head_commit.message }}" =~ "minor" ]]; then
echo "bump_type=minor" >> $GITHUB_ENV
else
echo "bump_type=patch" >> $GITHUB_ENV
fi
- name: Bump Version
id: bumpversion
run: |
git config user.name "GitHub Actions"
git config user.email "[email protected]"
bump2version ${{ env.bump_type }}
git push --follow-tags
echo "version=$(bump2version --dry-run --list | grep new_version | sed -r s,'^.*=',,)" >> $GITHUB_ENV
build_and_push:
runs-on: ubuntu-latest
needs: bump_version # Wait for the version bump job to finish
steps:
- name: Checkout the repository
uses: actions/checkout@v3
- name: Set Repository Name
id: repo_name
run: |
REPO_NAME=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
echo "repo_name=$REPO_NAME" >> $GITHUB_ENV
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Docker image
uses: docker/build-push-action@v5
with:
context: .
tags: |
ghcr.io/${{ env.repo_name }}:${{ env.version }}
ghcr.io/${{ env.repo_name }}:latest