name: Continuous Delivery

on:
  release:
    types: [published]

permissions:
  contents: read

jobs:
  release_amd64:
    name: Release linux/amd64
    runs-on: ubuntu-latest
    outputs:
      tags: ${{ steps.build_push.outputs.tags }}
      tags_chromium: ${{ steps.build_push.outputs.tags_chromium }}
      tags_libreoffice: ${{ steps.build_push.outputs.tags_libreoffice }}
      tags_cloud_run: ${{ steps.build_push.outputs.tags_cloud_run }}
      tags_cloud_run_chromium: ${{ steps.build_push.outputs.tags_cloud_run_chromium }}
      tags_cloud_run_libreoffice: ${{ steps.build_push.outputs.tags_cloud_run_libreoffice }}
      tags_aws_lambda: ${{ steps.build_push.outputs.tags_aws_lambda }}
      tags_aws_lambda_chromium: ${{ steps.build_push.outputs.tags_aws_lambda_chromium }}
      tags_aws_lambda_libreoffice: ${{ steps.build_push.outputs.tags_aws_lambda_libreoffice }}
    steps:
      - name: Checkout source code
        uses: actions/checkout@v6

      - name: Build and push
        id: build_push
        uses: ./.github/actions/build-test-push
        with:
          docker_hub_username: ${{ secrets.DOCKERHUB_USERNAME }}
          docker_hub_password: ${{ secrets.DOCKERHUB_TOKEN }}
          version: ${{ github.event.release.tag_name }}
          platform: linux/amd64
          skip_integrations_tests: true

  release_386:
    name: Release linux/386
    runs-on: ubuntu-latest
    outputs:
      tags: ${{ steps.build_push.outputs.tags }}
      tags_chromium: ${{ steps.build_push.outputs.tags_chromium }}
      tags_libreoffice: ${{ steps.build_push.outputs.tags_libreoffice }}
      tags_cloud_run: ${{ steps.build_push.outputs.tags_cloud_run }}
      tags_cloud_run_chromium: ${{ steps.build_push.outputs.tags_cloud_run_chromium }}
      tags_cloud_run_libreoffice: ${{ steps.build_push.outputs.tags_cloud_run_libreoffice }}
      tags_aws_lambda: ${{ steps.build_push.outputs.tags_aws_lambda }}
      tags_aws_lambda_chromium: ${{ steps.build_push.outputs.tags_aws_lambda_chromium }}
      tags_aws_lambda_libreoffice: ${{ steps.build_push.outputs.tags_aws_lambda_libreoffice }}
    steps:
      - name: Checkout source code
        uses: actions/checkout@v6

      - name: Build and push
        id: build_push
        uses: ./.github/actions/build-test-push
        with:
          docker_hub_username: ${{ secrets.DOCKERHUB_USERNAME }}
          docker_hub_password: ${{ secrets.DOCKERHUB_TOKEN }}
          version: ${{ github.event.release.tag_name }}
          platform: linux/386
          skip_integrations_tests: true

  release_ppc64le:
    name: Release linux/ppc64le
    runs-on: ubuntu-24.04-ppc64le
    outputs:
      tags: ${{ steps.build_push.outputs.tags }}
      tags_chromium: ${{ steps.build_push.outputs.tags_chromium }}
      tags_libreoffice: ${{ steps.build_push.outputs.tags_libreoffice }}
      tags_cloud_run: ${{ steps.build_push.outputs.tags_cloud_run }}
      tags_cloud_run_chromium: ${{ steps.build_push.outputs.tags_cloud_run_chromium }}
      tags_cloud_run_libreoffice: ${{ steps.build_push.outputs.tags_cloud_run_libreoffice }}
      tags_aws_lambda: ${{ steps.build_push.outputs.tags_aws_lambda }}
      tags_aws_lambda_chromium: ${{ steps.build_push.outputs.tags_aws_lambda_chromium }}
      tags_aws_lambda_libreoffice: ${{ steps.build_push.outputs.tags_aws_lambda_libreoffice }}
    steps:
      - name: Checkout source code
        uses: actions/checkout@v6

      - name: Build and push
        id: build_push
        uses: ./.github/actions/build-test-push
        with:
          docker_hub_username: ${{ secrets.DOCKERHUB_USERNAME }}
          docker_hub_password: ${{ secrets.DOCKERHUB_TOKEN }}
          version: ${{ github.event.release.tag_name }}
          platform: linux/ppc64le
          skip_integrations_tests: true

  release_arm64:
    name: Release linux/arm64
    runs-on: ubuntu-24.04-arm
    outputs:
      tags: ${{ steps.build_push.outputs.tags }}
      tags_chromium: ${{ steps.build_push.outputs.tags_chromium }}
      tags_libreoffice: ${{ steps.build_push.outputs.tags_libreoffice }}
      tags_cloud_run: ${{ steps.build_push.outputs.tags_cloud_run }}
      tags_cloud_run_chromium: ${{ steps.build_push.outputs.tags_cloud_run_chromium }}
      tags_cloud_run_libreoffice: ${{ steps.build_push.outputs.tags_cloud_run_libreoffice }}
      tags_aws_lambda: ${{ steps.build_push.outputs.tags_aws_lambda }}
      tags_aws_lambda_chromium: ${{ steps.build_push.outputs.tags_aws_lambda_chromium }}
      tags_aws_lambda_libreoffice: ${{ steps.build_push.outputs.tags_aws_lambda_libreoffice }}
    steps:
      - name: Checkout source code
        uses: actions/checkout@v6

      - name: Build and push
        id: build_push
        uses: ./.github/actions/build-test-push
        with:
          docker_hub_username: ${{ secrets.DOCKERHUB_USERNAME }}
          docker_hub_password: ${{ secrets.DOCKERHUB_TOKEN }}
          version: ${{ github.event.release.tag_name }}
          platform: linux/arm64
          skip_integrations_tests: true

  release_arm_v7:
    name: Release linux/arm/v7
    runs-on: ubuntu-24.04-arm
    outputs:
      tags: ${{ steps.build_push.outputs.tags }}
      tags_chromium: ${{ steps.build_push.outputs.tags_chromium }}
      tags_libreoffice: ${{ steps.build_push.outputs.tags_libreoffice }}
      tags_cloud_run: ${{ steps.build_push.outputs.tags_cloud_run }}
      tags_cloud_run_chromium: ${{ steps.build_push.outputs.tags_cloud_run_chromium }}
      tags_cloud_run_libreoffice: ${{ steps.build_push.outputs.tags_cloud_run_libreoffice }}
      tags_aws_lambda: ${{ steps.build_push.outputs.tags_aws_lambda }}
      tags_aws_lambda_chromium: ${{ steps.build_push.outputs.tags_aws_lambda_chromium }}
      tags_aws_lambda_libreoffice: ${{ steps.build_push.outputs.tags_aws_lambda_libreoffice }}
    steps:
      - name: Checkout source code
        uses: actions/checkout@v6

      - name: Build and push
        id: build_push
        uses: ./.github/actions/build-test-push
        with:
          docker_hub_username: ${{ secrets.DOCKERHUB_USERNAME }}
          docker_hub_password: ${{ secrets.DOCKERHUB_TOKEN }}
          version: ${{ github.event.release.tag_name }}
          platform: linux/arm/v7
          skip_integrations_tests: true

  merge_clean_release_tags:
    needs:
      - release_amd64
      - release_386
      - release_ppc64le
      - release_arm64
      - release_arm_v7
    name: Merge and clean release tags
    runs-on: ubuntu-latest
    steps:
      - name: Checkout source code
        uses: actions/checkout@v6

      - name: Merge
        uses: ./.github/actions/merge
        with:
          docker_hub_username: ${{ secrets.DOCKERHUB_USERNAME }}
          docker_hub_password: ${{ secrets.DOCKERHUB_TOKEN }}
          tags: "${{ needs.release_amd64.outputs.tags }},${{ needs.release_386.outputs.tags }},${{ needs.release_ppc64le.outputs.tags }},${{ needs.release_arm64.outputs.tags }},${{ needs.release_arm_v7.outputs.tags }}"

      - name: Merge Chromium
        uses: ./.github/actions/merge
        with:
          docker_hub_username: ${{ secrets.DOCKERHUB_USERNAME }}
          docker_hub_password: ${{ secrets.DOCKERHUB_TOKEN }}
          tags: "${{ needs.release_amd64.outputs.tags_chromium }},${{ needs.release_386.outputs.tags_chromium }},${{ needs.release_ppc64le.outputs.tags_chromium }},${{ needs.release_arm64.outputs.tags_chromium }},${{ needs.release_arm_v7.outputs.tags_chromium }}"

      - name: Merge LibreOffice
        uses: ./.github/actions/merge
        with:
          docker_hub_username: ${{ secrets.DOCKERHUB_USERNAME }}
          docker_hub_password: ${{ secrets.DOCKERHUB_TOKEN }}
          tags: "${{ needs.release_amd64.outputs.tags_libreoffice }},${{ needs.release_386.outputs.tags_libreoffice }},${{ needs.release_ppc64le.outputs.tags_libreoffice }},${{ needs.release_arm64.outputs.tags_libreoffice }},${{ needs.release_arm_v7.outputs.tags_libreoffice }}"

      - name: Merge AWS Lambda
        uses: ./.github/actions/merge
        with:
          docker_hub_username: ${{ secrets.DOCKERHUB_USERNAME }}
          docker_hub_password: ${{ secrets.DOCKERHUB_TOKEN }}
          tags: "${{ needs.release_amd64.outputs.tags_aws_lambda }},${{ needs.release_arm64.outputs.tags_aws_lambda }}"

      - name: Merge AWS Lambda Chromium
        uses: ./.github/actions/merge
        with:
          docker_hub_username: ${{ secrets.DOCKERHUB_USERNAME }}
          docker_hub_password: ${{ secrets.DOCKERHUB_TOKEN }}
          tags: "${{ needs.release_amd64.outputs.tags_aws_lambda_chromium }},${{ needs.release_arm64.outputs.tags_aws_lambda_chromium }}"

      - name: Merge AWS Lambda LibreOffice
        uses: ./.github/actions/merge
        with:
          docker_hub_username: ${{ secrets.DOCKERHUB_USERNAME }}
          docker_hub_password: ${{ secrets.DOCKERHUB_TOKEN }}
          tags: "${{ needs.release_amd64.outputs.tags_aws_lambda_libreoffice }},${{ needs.release_arm64.outputs.tags_aws_lambda_libreoffice }}"

      - name: Clean
        uses: ./.github/actions/clean
        with:
          docker_hub_username: ${{ secrets.DOCKERHUB_USERNAME }}
          docker_hub_password: ${{ secrets.DOCKERHUB_TOKEN }}
          tags: "${{ needs.release_amd64.outputs.tags }},${{ needs.release_386.outputs.tags }},${{ needs.release_ppc64le.outputs.tags }},${{ needs.release_arm64.outputs.tags }},${{ needs.release_arm_v7.outputs.tags }},${{ needs.release_amd64.outputs.tags_chromium }},${{ needs.release_386.outputs.tags_chromium }},${{ needs.release_ppc64le.outputs.tags_chromium }},${{ needs.release_arm64.outputs.tags_chromium }},${{ needs.release_arm_v7.outputs.tags_chromium }},${{ needs.release_amd64.outputs.tags_libreoffice }},${{ needs.release_386.outputs.tags_libreoffice }},${{ needs.release_ppc64le.outputs.tags_libreoffice }},${{ needs.release_arm64.outputs.tags_libreoffice }},${{ needs.release_arm_v7.outputs.tags_libreoffice }},${{ needs.release_amd64.outputs.tags_aws_lambda }},${{ needs.release_arm64.outputs.tags_aws_lambda }},${{ needs.release_amd64.outputs.tags_aws_lambda_chromium }},${{ needs.release_arm64.outputs.tags_aws_lambda_chromium }},${{ needs.release_amd64.outputs.tags_aws_lambda_libreoffice }},${{ needs.release_arm64.outputs.tags_aws_lambda_libreoffice }}"
