Skip to content

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

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

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

Workflow file for this run

name: web-ci
on:
push:
branches:
- '**'
pull_request:
branches:
- dev
- main
concurrency:
group: web-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 Node
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'
- name: Enable Corepack
run: corepack enable
- name: Install
run: pnpm install --frozen-lockfile
- name: Test
run: pnpm test --if-present
- name: Build
run: pnpm build
- 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-web:${{ steps.meta.outputs.image_tag }}
${{ secrets.DOCKERHUB_USERNAME }}/withrun-web: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: with-run/infra
event-type: deploy-web
client-payload: >-
{"service":"web","image":"${{ secrets.DOCKERHUB_USERNAME }}/withrun-web:${{ needs.ci.outputs.image_tag }}","sha":"${{ github.sha }}","source_repo":"${{ github.repository }}"}