1+ name : was-ci
2+
3+ on :
4+ push :
5+ branches :
6+ - ' **'
7+ pull_request :
8+ branches :
9+ - dev
10+ - main
11+
12+ concurrency :
13+ group : was-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 Java
30+ uses : actions/setup-java@v4
31+ with :
32+ distribution : temurin
33+ java-version : ' 21'
34+ cache : gradle
35+
36+ - name : Grant gradlew permission
37+ run : chmod +x ./gradlew
38+
39+ - name : Test
40+ run : ./gradlew test
41+
42+ - name : Build Jar
43+ run : ./gradlew bootJar
44+
45+ - name : Set deploy metadata
46+ id : meta
47+ shell : bash
48+ run : |
49+ if [[ "${GITHUB_EVENT_NAME}" == "push" && "${GITHUB_REF_NAME}" == "main" ]]; then
50+ echo "should_deploy=true" >> "$GITHUB_OUTPUT"
51+ echo "image_tag=main-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
52+ else
53+ echo "should_deploy=false" >> "$GITHUB_OUTPUT"
54+ echo "image_tag=" >> "$GITHUB_OUTPUT"
55+ fi
56+
57+ - name : Set up Docker Buildx
58+ if : steps.meta.outputs.should_deploy == 'true'
59+ uses : docker/setup-buildx-action@v3
60+
61+ - name : Login to Docker Hub
62+ if : steps.meta.outputs.should_deploy == 'true'
63+ uses : docker/login-action@v3
64+ with :
65+ username : ${{ secrets.DOCKERHUB_USERNAME }}
66+ password : ${{ secrets.DOCKERHUB_TOKEN }}
67+
68+ - name : Build and push image
69+ if : steps.meta.outputs.should_deploy == 'true'
70+ uses : docker/build-push-action@v6
71+ with :
72+ context : .
73+ file : ./Dockerfile
74+ push : true
75+ tags : |
76+ ${{ secrets.DOCKERHUB_USERNAME }}/withrun-was:${{ steps.meta.outputs.image_tag }}
77+ ${{ secrets.DOCKERHUB_USERNAME }}/withrun-was:main
78+
79+ notify-infra :
80+ if : needs.ci.outputs.should_deploy == 'true'
81+ needs : ci
82+ runs-on : ubuntu-latest
83+ steps :
84+ - name : Trigger infra deploy
85+ uses : peter-evans/repository-dispatch@v3
86+ with :
87+ token : ${{ secrets.INFRA_REPO_DISPATCH_TOKEN }}
88+ repository : withrun/infra
89+ event-type : deploy-was
90+ client-payload : >-
91+ {"service":"was","image":"${{ secrets.DOCKERHUB_USERNAME }}/withrun-was:${{ needs.ci.outputs.image_tag }}","sha":"${{ github.sha }}","source_repo":"${{ github.repository }}"}
0 commit comments