-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (78 loc) · 2.59 KB
/
publish-docker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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:
if: "!contains(github.event.head_commit.message, '[docs]')"
runs-on: ubuntu-latest
outputs:
version: ${{ steps.extract_version.outputs.version }}
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
- name: Get New Version from pyproject.toml
id: extract_version
run: |
VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' pyproject.toml)
echo "Bumped to: $VERSION"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
build_and_push:
if: "!contains(github.event.head_commit.message, '[docs]')"
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 }}:${{ needs.bump_version.outputs.version }}
ghcr.io/${{ env.repo_name }}:latest
push: 'true'