1+ name : web-ci
2+
3+ on :
4+ push :
5+ branches :
6+ - ' **'
7+ pull_request :
8+ branches :
9+ - dev
10+ - main
11+
12+ concurrency :
13+ group : web-ci-${{ github.ref }}
14+ cancel-in-progress : true
15+
16+ jobs :
17+ ci :
18+ runs-on : ubuntu-latest
19+ permissions :
20+ contents : read
21+ packages : read
22+ outputs :
23+ image_tag : ${{ steps.meta.outputs.image_tag }}
24+ should_deploy : ${{ steps.meta.outputs.should_deploy }}
25+ steps :
26+ - name : Checkout
27+ uses : actions/checkout@v4
28+
29+ - name : Setup Node
30+ uses : actions/setup-node@v4
31+ with :
32+ node-version : ' 20'
33+ cache : ' pnpm'
34+
35+ - name : Enable Corepack
36+ run : corepack enable
37+
38+ - name : Install
39+ run : pnpm install --frozen-lockfile
40+
41+ - name : Test
42+ run : pnpm test --if-present
43+
44+ - name : Build
45+ run : pnpm build
46+
47+ - name : Set deploy metadata
48+ id : meta
49+ shell : bash
50+ run : |
51+ if [[ "${GITHUB_EVENT_NAME}" == "push" && "${GITHUB_REF_NAME}" == "main" ]]; then
52+ echo "should_deploy=true" >> "$GITHUB_OUTPUT"
53+ echo "image_tag=main-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
54+ else
55+ echo "should_deploy=false" >> "$GITHUB_OUTPUT"
56+ echo "image_tag=" >> "$GITHUB_OUTPUT"
57+ fi
58+
59+ - name : Set up Docker Buildx
60+ if : steps.meta.outputs.should_deploy == 'true'
61+ uses : docker/setup-buildx-action@v3
62+
63+ - name : Login to Docker Hub
64+ if : steps.meta.outputs.should_deploy == 'true'
65+ uses : docker/login-action@v3
66+ with :
67+ username : ${{ secrets.DOCKERHUB_USERNAME }}
68+ password : ${{ secrets.DOCKERHUB_TOKEN }}
69+
70+ - name : Build and push image
71+ if : steps.meta.outputs.should_deploy == 'true'
72+ uses : docker/build-push-action@v6
73+ with :
74+ context : .
75+ file : ./Dockerfile
76+ push : true
77+ tags : |
78+ ${{ secrets.DOCKERHUB_USERNAME }}/withrun-web:${{ steps.meta.outputs.image_tag }}
79+ ${{ secrets.DOCKERHUB_USERNAME }}/withrun-web:main
80+
81+ notify-infra :
82+ if : needs.ci.outputs.should_deploy == 'true'
83+ needs : ci
84+ runs-on : ubuntu-latest
85+ steps :
86+ - name : Trigger infra deploy
87+ uses : peter-evans/repository-dispatch@v3
88+ with :
89+ token : ${{ secrets.INFRA_REPO_DISPATCH_TOKEN }}
90+ repository : with-run/infra
91+ event-type : deploy-web
92+ client-payload : >-
93+ {"service":"web","image":"${{ secrets.DOCKERHUB_USERNAME }}/withrun-web:${{ needs.ci.outputs.image_tag }}","sha":"${{ github.sha }}","source_repo":"${{ github.repository }}"}
0 commit comments