Skip to content

Commit cfdf74e

Browse files
authored
Merge pull request #802 from codex-team/ci/notify-docker-tag
ci: send docker tag to chat on deploy branches
2 parents 595b6d8 + 0137eb8 commit cfdf74e

File tree

1 file changed

+40
-8
lines changed

1 file changed

+40
-8
lines changed

.github/workflows/build-and-push-docker-image.yml

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: Build and push docker image
22

3-
on: [push]
3+
on:
4+
push:
5+
workflow_dispatch:
46

57
env:
68
DOCKER_REPO: ${{ secrets.DOCKER_USERNAME }}/hawk-garage
@@ -12,13 +14,31 @@ jobs:
1214
- name: Checkout repository
1315
uses: actions/checkout@v4
1416

17+
# Compute deploy tag
18+
- name: Prepare deploy tag
19+
id: deploy
20+
shell: bash
21+
run: |
22+
set -euo pipefail
23+
24+
case "${GITHUB_REF_NAME}" in
25+
stage|prod|prod-ru)
26+
echo "is_deploy=true" >> "$GITHUB_OUTPUT"
27+
echo "tag=${GITHUB_REF_NAME}-${GITHUB_SHA::7}-$(date +%s)" >> "$GITHUB_OUTPUT"
28+
;;
29+
*)
30+
echo "is_deploy=false" >> "$GITHUB_OUTPUT"
31+
echo "tag=" >> "$GITHUB_OUTPUT"
32+
;;
33+
esac
34+
1535
- name: Set up Node.js
1636
uses: actions/setup-node@v4
1737
with:
1838
node-version: 22
1939

2040
- name: Make stage envfile
21-
if: endsWith(github.ref, '/stage')
41+
if: github.ref_name == 'stage'
2242
uses: SpicyPizza/create-envfile@v1
2343
with:
2444
envkey_VITE_HAWK_TOKEN: ${{ secrets.HAWK_TOKEN_PROD }}
@@ -32,7 +52,7 @@ jobs:
3252
# envkey_VITE_API_ENDPOINT: "https://api.stage.hawk.so"
3353

3454
- name: Make prod envfile
35-
if: endsWith(github.ref, '/prod')
55+
if: github.ref_name == 'prod'
3656
uses: SpicyPizza/create-envfile@v1
3757
with:
3858
envkey_VITE_HAWK_TOKEN: ${{ secrets.HAWK_TOKEN_PROD }}
@@ -41,8 +61,8 @@ jobs:
4161
envkey_VITE_API_ENDPOINT: "https://api.hawk.so"
4262
envkey_VITE_FREE_PLAN_ID: ${{ secrets.FREE_PLAN_ID }}
4363

44-
- name: Make prod envfile
45-
if: endsWith(github.ref, '/prod-ru')
64+
- name: Make prod-ru envfile
65+
if: github.ref_name == 'prod-ru'
4666
uses: SpicyPizza/create-envfile@v1
4767
with:
4868
envkey_VITE_HAWK_TOKEN: ${{ secrets.HAWK_TOKEN_PROD }}
@@ -55,6 +75,7 @@ jobs:
5575
uses: docker/setup-buildx-action@v3
5676

5777
- name: Login to DockerHub
78+
if: steps.deploy.outputs.is_deploy == 'true'
5879
uses: docker/login-action@v3
5980
with:
6081
username: ${{ secrets.DOCKER_USERNAME }}
@@ -69,11 +90,22 @@ jobs:
6990
type=ref,event=branch
7091
type=ref,event=pr
7192
type=raw,value=latest,enable={{is_default_branch}}
72-
type=raw,value={{branch}}-{{sha}}-{{date 'X'}},enable=${{ startsWith(github.ref, 'refs/heads') }}
93+
type=raw,value=${{ steps.deploy.outputs.tag }},enable=${{ steps.deploy.outputs.is_deploy == 'true' }}
7394
74-
- name: Build and push production image
95+
- name: Build and push image
7596
uses: docker/build-push-action@v5
7697
with:
7798
context: .
7899
tags: ${{ steps.meta.outputs.tags }}
79-
push: ${{ endsWith(github.ref, '/stage') || endsWith(github.ref, '/prod') || endsWith(github.ref, '/prod-ru') }}
100+
push: ${{ steps.deploy.outputs.is_deploy == 'true' }}
101+
102+
- name: Send docker tag to chat
103+
if: ${{ success() && steps.deploy.outputs.is_deploy == 'true' }}
104+
uses: codex-team/action-codexbot-notify@v1
105+
with:
106+
webhook: ${{ secrets.CODEXBOT_NOTIFY_WEBHOOK }}
107+
parse_mode: HTML
108+
disable_web_page_preview: true
109+
message: |
110+
<b>Docker tag</b>: <code>${{ steps.deploy.outputs.tag }}</code>
111+
<b>Image</b>: <code>${{ env.DOCKER_REPO }}:${{ steps.deploy.outputs.tag }}</code>

0 commit comments

Comments
 (0)