Skip to content

Commit c6283e0

Browse files
committed
🔨 update: cd pipelines
1 parent 66e37fa commit c6283e0

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

.github/workflows/cd.yaml

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ name: "CD"
22

33
on:
44
push:
5-
branches:
6-
- main
7-
paths:
8-
- "app/**"
5+
tags:
6+
- "v*"
97

108
jobs:
119
image-build:
@@ -15,20 +13,6 @@ jobs:
1513
- name: Checkout repository
1614
uses: actions/checkout@v4
1715

18-
# - name: Determine new tag
19-
# id: new-tag
20-
# run: |
21-
# apiResponse=$(curl -s "https://hub.docker.com/v2/repositories/${{ secrets.DOCKER_USERNAME }}/${{ matrix.directory }}/tags/?page_size=100")
22-
# if echo "$apiResponse" | grep -q "httperror 404"; then
23-
# newTag="v1.0.0"
24-
# else
25-
# currentTag=$(echo "$apiResponse" | jq -r '.results[].name' | sort -V | grep v | tail -n 1)
26-
# version=$(echo "$currentTag" | sed 's/[^0-9.]//g')
27-
# IFS='.' read -r major minor patch <<< "$version"
28-
# newTag="v${major}.${minor}.$((patch + 1))"
29-
# fi
30-
# echo "new_tag=$newTag" >> $GITHUB_ENV
31-
3216
- name: Login to DockerHub
3317
uses: docker/login-action@v3
3418
with:
@@ -42,17 +26,26 @@ jobs:
4226
username: ${{ secrets.GH_USERNAME }}
4327
password: ${{ secrets.GH_TOKEN }}
4428

29+
- name: Set tag based on ref
30+
run: |
31+
if [[ $GITHUB_REF == refs/tags/* ]]; then
32+
TAG_NAME=${GITHUB_REF#refs/tags/}
33+
echo "Tag name is $TAG_NAME"
34+
else
35+
TAG_NAME=${GITHUB_SHA}
36+
echo "Using commit SHA as tag: $TAG_NAME"
37+
fi
38+
echo "tag_name=$TAG_NAME" >> $GITHUB_ENV
39+
4540
- name: Build and push image
4641
uses: docker/build-push-action@v6
4742
with:
4843
push: true
49-
# ${{ secrets.DOCKER_USERNAME }}/fastapi-cookbook:${{ env.new_tag }},
50-
# ghcr.io/${{ secrets.GH_USERNAME }}/fastapi-cookbook:${{ env.new_tag }},
5144
tags: |
5245
${{ secrets.DOCKER_USERNAME }}/fastapi-cookbook:latest,
53-
${{ secrets.DOCKER_USERNAME }}/fastapi-cookbook:${{ github.sha }},
46+
${{ secrets.DOCKER_USERNAME }}/fastapi-cookbook:${{ env.tag_name }},
5447
ghcr.io/${{ secrets.GH_USERNAME }}/fastapi-cookbook:latest,
55-
ghcr.io/${{ secrets.GH_USERNAME }}/fastapi-cookbook:${{ github.sha }}
48+
ghcr.io/${{ secrets.GH_USERNAME }}/fastapi-cookbook:${{ env.tag_name }}
5649
5750
- name: Slack webhook
5851
uses: 8398a7/action-slack@v3
@@ -77,16 +70,17 @@ jobs:
7770

7871
- name: Change manifest
7972
run: |
80-
sed -i 's|${{ secrets.DOCKER_USERNAME }}/fastapi-cookbook:[^ ]*|${{ secrets.DOCKER_USERNAME }}/fastapi-cookbook:${{ github.sha }}|' k8s/postgresql/fastapi.yaml
73+
sed -i 's|${{ secrets.DOCKER_USERNAME }}/fastapi-cookbook:[^ ]*|${{ secrets.DOCKER_USERNAME }}/fastapi-cookbook:${{ env.tag_name }}|' k8s/postgresql/fastapi.yaml
8174
8275
- name: git push
8376
run: |
8477
git config user.name ${{ secrets.GH_USERNAME }}
8578
git config user.email "[email protected]"
8679
git config credential.helper store
8780
git add k8s/postgresql/fastapi.yaml
88-
git commit -m ":tada: deploy: fastapi-cookbook [${{ github.sha }}]"
89-
git push origin ${{ github.ref_name }}
81+
git commit -m ":tada: deploy: fastapi-cookbook [${{ env.tag_name }}]"
82+
git checkout main
83+
git push origin main
9084
9185
- name: Slack webhook
9286
uses: 8398a7/action-slack@v3

0 commit comments

Comments
 (0)