name: Fleetbase CI

on:
  push:
    branches: [ main ]
    tags:
      - 'v*'
  pull_request:
    branches: [ main ]

jobs:
  build:
    name: Build and Start Docker Services
    runs-on: ubuntu-latest

    steps:
    - name: Checkout Code
      uses: actions/checkout@v3
      with:
        submodules: recursive

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

    - name: Prepare Composer Auth Secret
      run: |
        if [[ -n "${{ secrets._GITHUB_AUTH_TOKEN }}" ]]; then
          echo '{"github-oauth": {"github.com": "'${{ secrets._GITHUB_AUTH_TOKEN }}'"}}' > composer-auth.json
        else
          echo '{}' > composer-auth.json
        fi

    - name: Build and Release
      uses: docker/bake-action@v2
      with:
        files: |
          ./docker-bake.hcl
