name: bun-dockerhub
on:
  push:
    paths:
      - dockerhub/Dockerfile
    branches:
      - main
  pull_request:
    paths:
      - dockerhub/Dockerfile
    branches:
      - main
  release:
    types:
      - published
jobs:
  docker:
    runs-on: ubuntu-latest
    if: github.repository_owner == 'oven-sh'
    steps:
      - name: Checkout repo
        uses: actions/checkout@v3
      - name: Collect metadata
        id: meta
        uses: docker/metadata-action@v4
        with:
          images: |
            ${{ secrets.DOCKERHUB_USERNAME }}/bun
          tags: |
            type=match,pattern=bun-v(\d.\d.\d),group=1
            type=match,pattern=bun-v(\d.\d),group=1
            type=match,pattern=bun-v(\d),group=1
            type=ref,event=branch
            type=ref,event=pr
      - name: Login to DockerHub
        if: github.event_name == 'release'
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Build image
        uses: docker/build-push-action@v3
        with:
          context: ./dockerhub
          push: ${{ github.event_name == 'release' }}
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
