name: Build and Push frp Docker Image

on:
  push:
    branches: [ main ]
    paths:
      - 'dockerfiles/frps/*'
      - 'dockerfiles/frpc/*'

jobs:
  build-and-push:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Log in to GitHub Container Registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build and push frps Docker image
        uses: docker/build-push-action@v6
        with:
          context: ./dockerfiles/frps
          push: true
          tags: ghcr.io/${{ github.repository_owner }}/frps:latest

      - name: Build and push frpc Docker image
        uses: docker/build-push-action@v6
        with:
          context: ./dockerfiles/frpc
          push: true
          tags: ghcr.io/${{ github.repository_owner }}/frpc:latest