카테고리 없음

[github action] 코멘트를 이용하여 작업을 실행하는 방법

hs_seo 2025. 5. 26. 23:24

github aciton 에 맞는 yaml 파일을 .github/workflows 아래에 생성합니다.

그리고 pr 을 생성하고, comment 에 /build 를 입력하면 실행됩니다.

 

 

name: Build on Comment

on:
  issue_comment:
    types: [created]

jobs:
  build_image:
    # 코멘트가 '/build'이고, PR에 작성된 코멘트인 경우에만 실행
    if: github.event.issue.pull_request && contains(github.event.comment.body, '/build')
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Login to Docker Hub (Optional)
        # Docker Hub에 이미지를 푸시하려면 주석을 해제하고 사용자 이름과 토큰을 설정하세요.
        # Docker Hub 이외의 레지스트리를 사용하는 경우 해당 레지스트리에 맞게 수정하세요.
        # uses: docker/login-action@v3
        # with:
        #   username: ${{ secrets.DOCKERHUB_USERNAME }}
        #   password: ${{ secrets.DOCKERHUB_TOKEN }}
        run: echo "Docker login step skipped for now. Uncomment and configure if needed."

      - name: Build Docker image
        # 'DOCKERHUB_USERNAME/IMAGE_NAME:TAG' 부분을 실제 이미지 이름과 태그로 변경하세요.
        # Dockerfile의 위치가 루트 디렉토리가 아니라면 context와 file 옵션을 수정하세요.
        run: |
          docker build -t my-image:latest .
          echo "Docker image built: my-image:latest"

      # - name: Push Docker image (Optional)
      #   # 이미지를 푸시하려면 주Kk석을 해제하고 이미지 이름을 수정하세요.
      #   # run: docker push my-image:latest
      #   run: echo "Docker push step skipped for now. Uncomment if needed."

      - name: Add reaction to comment
        uses: peter-evans/create-or-update-comment@v4
        with:
          comment-id: ${{ github.event.comment.id }}
          reaction-type: '+1' # 빌드 시작을 알리는 반응 (예: 👍)

      - name: Comment on build completion (Optional)
        # 빌드 완료 후 코멘트를 남기려면 주석을 해제하세요.
        # uses: peter-evans/create-or-update-comment@v4
        # with:
        #   issue-number: ${{ github.event.issue.number }}
        #   body: |
        #     Image build triggered by @${{ github.event.comment.user.login }} has completed.
        #     Image: my-image:latest
        run: echo "Build completion comment step skipped for now. Uncomment if needed."
반응형