name: Jekyll site CI

on:
  push:
    branches: [ "main" ]

jobs:
  docker:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v4
        
    - name: Debug - Print Gitea context
      run: |
        echo "LOCAL_REGISTRY variable is: ${{ vars.LOCAL_REGISTRY }}"
        echo "Gitea Actor: ${{ gitea.actor }}"
        echo "Repository Owner: ${{ gitea.repository_owner }}"
        echo "Repository Name: ${{ gitea.repository_name }}"
        echo "SHA: ${{ gitea.sha }}"
        echo "Ref: ${{ gitea.ref }}"
        echo "Ref Name: ${{ gitea.ref_name }}"
        echo "Ref Type: ${{ gitea.ref_type }}"
    
    - name: Login to Gitea Package Registry
      # (Test credentials early, befor failing late in the process.)
      uses: docker/login-action@v3
      with:
        registry: ${{vars.LOCAL_REGISTRY}}
        username: ${{ VARS.USER }}
        password: ${{ secrets.TOKEN }}
    
    - name: Setup Ruby
      uses: ruby/setup-ruby@v1
      with:
        ruby-version: '3.3'
        
    - name: Install GEM bundle 
      run: bundle install
      
    - name: Build Website using Jekyll
      run: JEKYLL_ENV=production bundle exec jekyll build --trace --future

    - name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v3
        
    - name: Build and push
      uses: docker/build-push-action@v5
      with:
        context: .
        platforms: linux/amd64 # ,linux/arm64
        push: true
        tags: |
            ${{ vars.LOCAL_REGISTRY }}/${{ gitea.repository_owner }}/website:latest
            ${{ vars.LOCAL_REGISTRY }}/${{ gitea.repository_owner }}/website:${{ gitea.sha }}