Skip to content

feat: was repo의 ci를 위한 ci.yml파일 생성 #2 #1

feat: was repo의 ci를 위한 ci.yml파일 생성 #2

feat: was repo의 ci를 위한 ci.yml파일 생성 #2 #1

Workflow file for this run

name: was-ci
on:
push:
branches:
- '**'
pull_request:
branches:
- dev
- main
concurrency:
group: was-ci-${{ github.ref }}
cancel-in-progress: true
jobs:
ci:
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
outputs:
image_tag: ${{ steps.meta.outputs.image_tag }}
should_deploy: ${{ steps.meta.outputs.should_deploy }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
cache: gradle
- name: Grant gradlew permission
run: chmod +x ./gradlew
- name: Test
run: ./gradlew test
- name: Build Jar
run: ./gradlew bootJar
- name: Set deploy metadata
id: meta
shell: bash
run: |
if [[ "${GITHUB_EVENT_NAME}" == "push" && "${GITHUB_REF_NAME}" == "main" ]]; then
echo "should_deploy=true" >> "$GITHUB_OUTPUT"
echo "image_tag=main-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
else
echo "should_deploy=false" >> "$GITHUB_OUTPUT"
echo "image_tag=" >> "$GITHUB_OUTPUT"
fi
- name: Set up Docker Buildx
if: steps.meta.outputs.should_deploy == 'true'
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
if: steps.meta.outputs.should_deploy == 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push image
if: steps.meta.outputs.should_deploy == 'true'
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/withrun-was:${{ steps.meta.outputs.image_tag }}
${{ secrets.DOCKERHUB_USERNAME }}/withrun-was:main
notify-infra:
if: needs.ci.outputs.should_deploy == 'true'
needs: ci
runs-on: ubuntu-latest
steps:
- name: Trigger infra deploy
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.INFRA_REPO_DISPATCH_TOKEN }}
repository: withrun/infra
event-type: deploy-was
client-payload: >-
{"service":"was","image":"${{ secrets.DOCKERHUB_USERNAME }}/withrun-was:${{ needs.ci.outputs.image_tag }}","sha":"${{ github.sha }}","source_repo":"${{ github.repository }}"}