Skip to content

Commit 9da8d1c

Browse files
lsteinLincoln Stein
andauthored
split deployments into two actions (#76)
Co-authored-by: Lincoln Stein <[email protected]>
1 parent 3473525 commit 9da8d1c

File tree

3 files changed

+76
-27
lines changed

3 files changed

+76
-27
lines changed

.github/workflows/deploy.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Deploy to PyPI and DockerHub
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
pypi-deploy:
8+
uses: ./.github/workflows/pypi.yml
9+
10+
dockerhub-deploy:
11+
needs: pypi
12+
uses: ./.github/workflows/dockerhub.yml

.github/workflows/dockerhub.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Deploy To DockerHub
2+
3+
on:
4+
workflow_call:
5+
workflow_dispatch:
6+
7+
jobs:
8+
dockerhub-deploy:
9+
runs-on: ubuntu-latest
10+
environment: dockerhub
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: '3.12'
20+
21+
- name: Extract version from pyproject.toml
22+
id: get_version
23+
run: |
24+
VERSION=$(python -c "
25+
try:
26+
import tomllib
27+
with open('pyproject.toml', 'rb') as f:
28+
data = tomllib.load(f)
29+
print(data['project']['version'])
30+
except Exception as e:
31+
print(f'Error reading version: {e}', file=sys.stderr)
32+
exit(1)
33+
")
34+
echo "version=$VERSION" >> $GITHUB_OUTPUT
35+
36+
- name: Log in to DockerHub
37+
uses: docker/login-action@v3
38+
with:
39+
username: ${{ secrets.DOCKERHUB_USERNAME }}
40+
password: ${{ secrets.DOCKERHUB_TOKEN }}
41+
42+
- name: Build and push Docker image
43+
uses: docker/build-push-action@v5
44+
with:
45+
context: .
46+
file: docker/Dockerfile
47+
push: true
48+
tags: |
49+
${{ secrets.DOCKERHUB_USERNAME }}/photomapai:${{ steps.get_version.outputs.version }}
50+
${{ secrets.DOCKERHUB_USERNAME }}/photomapai:latest
Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
name: Release to PyPi & DockerHub
1+
name: Release to PyPi
22

33
on:
4+
workflow_call:
45
workflow_dispatch:
56

67
jobs:
7-
release:
8+
pypi-deploy:
89
runs-on: ubuntu-latest
910
environment: pypi
1011

@@ -24,7 +25,16 @@ jobs:
2425
- name: Extract version from pyproject.toml
2526
id: get_version
2627
run: |
27-
VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
28+
VERSION=$(python -c "
29+
try:
30+
import tomllib
31+
with open('pyproject.toml', 'rb') as f:
32+
data = tomllib.load(f)
33+
print(data['project']['version'])
34+
except Exception as e:
35+
print(f'Error reading version: {e}', file=sys.stderr)
36+
exit(1)
37+
")
2838
echo "version=$VERSION" >> $GITHUB_OUTPUT
2939
3040
- name: Tag the release
@@ -50,27 +60,4 @@ jobs:
5060
- name: Publish to PyPI
5161
uses: pypa/gh-action-pypi-publish@release/v1
5262
with:
53-
repository-url: https://upload.pypi.org/legacy/
54-
# env:
55-
# TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
56-
57-
- name: Log in to DockerHub
58-
uses: docker/login-action@v3
59-
with:
60-
username: ${{ secrets.DOCKERHUB_USERNAME }}
61-
password: ${{ secrets.DOCKERHUB_TOKEN }}
62-
63-
- name: Build Docker image
64-
run: |
65-
VERSION=${{ steps.get_version.outputs.version }}
66-
docker build -f docker/Dockerfile -t ${{ secrets.DOCKERHUB_USERNAME }}/photomapai:${VERSION} .
67-
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/photomapai:${VERSION} ${{ secrets.DOCKERHUB_USERNAME }}/photomapai:latest
68-
69-
- name: Push Docker image (versioned)
70-
run: |
71-
VERSION=${{ steps.get_version.outputs.version }}
72-
docker push ${{ secrets.DOCKERHUB_USERNAME }}/photomapai:${VERSION}
73-
74-
- name: Push Docker image (latest)
75-
run: |
76-
docker push ${{ secrets.DOCKERHUB_USERNAME }}/photomapai:latest
63+
repository-url: https://upload.pypi.org/legacy/

0 commit comments

Comments
 (0)