name: Unstable Build

on:
  schedule:
    - cron: "0 5 * * *"
  workflow_dispatch:

jobs:
  version:
    runs-on: ubuntu-latest
    outputs:
      base: unstable
      date: unstable-${{ steps.date.outputs.date }}
      prosody_version: prosody-${{ steps.prosody_version.outputs.version }}
      jicofo_version: jicofo-${{ steps.jicofo_version.outputs.version }}
      web_version: web-${{ steps.web_version.outputs.version }}
      jvb_version: jvb-${{ steps.jvb_version.outputs.version }}
      jibri_version: jibri-${{ steps.jibri_version.outputs.version }}
      jigasi_version: jigasi-${{ steps.jigasi_version.outputs.version }}
    steps:
      - name: Get current date
        id: date
        run: echo "date=$(date +%F)">> $GITHUB_OUTPUT
      - name: Prosody gpg key
        id: prosody_gpg_key
        run: curl --location --silent --show-error https://prosody.im/files/prosody-debian-packages.key | sudo dd of=/etc/apt/keyrings/prosody.gpg
      - name: Prosody dsa1024 key support
        run: echo 'APT::Key::Assert-Pubkey-Algo ">=rsa2048,ed25519,ed448,dsa1024";' | sudo tee /etc/apt/apt.conf.d/99weakkey-warning
      - name: Prosody repo
        id: prosody_repo
        run: echo "deb [signed-by=/etc/apt/keyrings/prosody.gpg] https://packages.prosody.im/debian bookworm main" | sudo tee /etc/apt/sources.list.d/prosody.list
      - name: Jitsi repo
        uses: myci-actions/add-deb-repo@43408b9f0225d1c64ba667d59e337c6140383bbe  # 11
        with:
          repo: deb https://download.jitsi.org/ unstable/
          repo-name: jitsi
          keys-asc: https://download.jitsi.org/jitsi-key.gpg.key
      - name: Get current jicofo versions
        id: jicofo_version
        run: echo "version=$( apt-cache show jitsi-meet | head -10 | grep '^Depends:' | tr ',' '\n' | grep jicofo | cut -d'=' -f2 | tr -d ')' | awk '{print $1}' )" >> $GITHUB_OUTPUT
      - name: Get current jitsi-meet-web versions
        id: web_version
        run: echo "version=$( apt-cache show jitsi-meet | head -10 | grep '^Depends:' | tr ',' '\n' | grep 'jitsi-meet-web ' | cut -d'=' -f2 | tr -d ')' | awk '{print $1}' )" >> $GITHUB_OUTPUT
      - name: Get current jvb versions
        id: jvb_version
        run: echo "version=$( apt-cache show jitsi-meet | head -10 | grep '^Pre-Depends:'| tr ',' '\n' | grep 'jitsi-videobridge2' | cut -d'=' -f2 | tr -d ')' | awk '{print $1}' )" >> $GITHUB_OUTPUT
      - name: Get current prosody versions
        id: prosody_version
        run: echo "version=$( apt-cache madison prosody | awk '{print $3;}' | head -1 |  cut -d'-' -f1 )" >> $GITHUB_OUTPUT
      - name: Get current jibri version
        id: jibri_version
        run: echo "version=$( apt-cache show jibri | head -10 | grep Version | awk '{print $2}' )" >> $GITHUB_OUTPUT
      - name: Get current jigasi version
        id: jigasi_version
        run: echo "version=$( apt-cache show jigasi | head -10 | grep Version | awk '{print $2}' )" >> $GITHUB_OUTPUT

  base-arch:
    runs-on: ${{ matrix.config.os }}
    strategy:
        fail-fast: false
        matrix:
          config:
            - { os: ubuntu-24.04, arch: amd64 }
            - { os: ubuntu-24.04-arm, arch: arm64 }
    needs: version
    steps:
      - name: Check out code
        uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5  # v4
      - name: Setup Docker Buildx
        uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f  # v3
        with:
          driver: docker
      - name: Login to DockerHub
        uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9  # v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Build and push
        uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8  # v6
        with:
          push: true
          context: ./base
          tags: |
            ${{ secrets.JITSI_REPO }}/base:${{ needs.version.outputs.base }}-${{ matrix.config.arch }}
            ${{ secrets.JITSI_REPO }}/base:${{ needs.version.outputs.date }}-${{ matrix.config.arch }}
          build-args: |
            JITSI_RELEASE=unstable

  base:
    runs-on: ubuntu-latest
    needs: [version, base-arch]
    steps:
      - name: Login to DockerHub
        uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9  # v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Create Docker Manifest
        uses: int128/docker-manifest-create-action@44422a4b046d55dc036df622039ed3aec43c613c  # v2
        with:
          tags: |
            ${{ secrets.JITSI_REPO }}/base:${{ needs.version.outputs.base }}
            ${{ secrets.JITSI_REPO }}/base:${{ needs.version.outputs.date }}
          sources: |
            ${{ secrets.JITSI_REPO }}/base:${{ needs.version.outputs.base }}-amd64
            ${{ secrets.JITSI_REPO }}/base:${{ needs.version.outputs.base }}-arm64

  base-java-arch:
    runs-on: ${{ matrix.config.os }}
    strategy:
        fail-fast: false
        matrix:
          config:
            - { os: ubuntu-24.04, arch: amd64 }
            - { os: ubuntu-24.04-arm, arch: arm64 }
    needs: [version, base]
    steps:
      - name: Check out code
        uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5  # v4
      - name: Setup Docker Buildx
        uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f  # v3
        with:
          driver: docker
      - name: Login to DockerHub
        uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9  # v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Build and push
        uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8  # v6
        with:
          push: true
          context: ./base-java
          tags: |
            ${{ secrets.JITSI_REPO }}/base-java:${{ needs.version.outputs.base }}-${{ matrix.config.arch }}
            ${{ secrets.JITSI_REPO }}/base-java:${{ needs.version.outputs.date }}-${{ matrix.config.arch }}
          build-args: |
            JITSI_REPO=${{ secrets.JITSI_REPO }}
            BASE_TAG=${{ needs.version.outputs.base }}

  base-java:
    runs-on: ubuntu-latest
    needs: [version, base-java-arch]
    steps:
      - name: Login to DockerHub
        uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9  # v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Create Docker Manifest
        uses: int128/docker-manifest-create-action@44422a4b046d55dc036df622039ed3aec43c613c  # v2
        with:
          tags: |
            ${{ secrets.JITSI_REPO }}/base-java:${{ needs.version.outputs.base }}
            ${{ secrets.JITSI_REPO }}/base-java:${{ needs.version.outputs.date }}
          sources: |
            ${{ secrets.JITSI_REPO }}/base-java:${{ needs.version.outputs.base }}-amd64
            ${{ secrets.JITSI_REPO }}/base-java:${{ needs.version.outputs.base }}-arm64

  jibri-arch:
    runs-on: ${{ matrix.config.os }}
    strategy:
        fail-fast: false
        matrix:
          config:
            - { os: ubuntu-24.04, arch: amd64 }
            - { os: ubuntu-24.04-arm, arch: arm64 }
    needs: [version, base-java]
    steps:
      - name: Check out code
        uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5  # v4
      - name: Setup Docker Buildx
        uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f  # v3
        with:
          driver: docker
      - name: Login to DockerHub
        uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9  # v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Build and push
        uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8  # v6
        with:
          push: true
          context: ./jibri
          tags: |
            ${{ secrets.JITSI_REPO }}/jibri:${{ needs.version.outputs.base }}-${{ matrix.config.arch }}
            ${{ secrets.JITSI_REPO }}/jibri:${{ needs.version.outputs.date }}-${{ matrix.config.arch }}
            ${{ secrets.JITSI_REPO }}/jibri:${{ needs.version.outputs.jibri_version }}-${{ matrix.config.arch }}
          build-args: |
            JITSI_REPO=${{ secrets.JITSI_REPO }}
            BASE_TAG=${{ needs.version.outputs.base }}

  jibri:
    runs-on: ubuntu-latest
    needs: [version, jibri-arch]
    steps:
      - name: Login to DockerHub
        uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9  # v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Create Docker Manifest
        uses: int128/docker-manifest-create-action@44422a4b046d55dc036df622039ed3aec43c613c  # v2
        with:
          tags: |
            ${{ secrets.JITSI_REPO }}/jibri:${{ needs.version.outputs.base }}
            ${{ secrets.JITSI_REPO }}/jibri:${{ needs.version.outputs.date }}
            ${{ secrets.JITSI_REPO }}/jibri:${{ needs.version.outputs.jibri_version }}
          sources: |
            ${{ secrets.JITSI_REPO }}/jibri:${{ needs.version.outputs.base }}-amd64
            ${{ secrets.JITSI_REPO }}/jibri:${{ needs.version.outputs.base }}-arm64

  jicofo-arch:
    runs-on: ${{ matrix.config.os }}
    strategy:
        fail-fast: false
        matrix:
          config:
            - { os: ubuntu-24.04, arch: amd64 }
            - { os: ubuntu-24.04-arm, arch: arm64 }
    needs: [version, base-java]
    steps:
      - name: Check out code
        uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5  # v4
      - name: Setup Docker Buildx
        uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f  # v3
        with:
          driver: docker
      - name: Login to DockerHub
        uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9  # v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Build and push
        uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8  # v6
        with:
          push: true
          context: ./jicofo
          tags: |
            ${{ secrets.JITSI_REPO }}/jicofo:${{ needs.version.outputs.base }}-${{ matrix.config.arch }}
            ${{ secrets.JITSI_REPO }}/jicofo:${{ needs.version.outputs.date }}-${{ matrix.config.arch }}
            ${{ secrets.JITSI_REPO }}/jicofo:${{ needs.version.outputs.jicofo_version }}-${{ matrix.config.arch }}
          build-args: |
            JITSI_REPO=${{ secrets.JITSI_REPO }}
            BASE_TAG=${{ needs.version.outputs.base }}

  jicofo:
    runs-on: ubuntu-latest
    needs: [version, jicofo-arch]
    steps:
      - name: Login to DockerHub
        uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9  # v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Create Docker Manifest
        uses: int128/docker-manifest-create-action@44422a4b046d55dc036df622039ed3aec43c613c  # v2
        with:
          tags: |
            ${{ secrets.JITSI_REPO }}/jicofo:${{ needs.version.outputs.base }}
            ${{ secrets.JITSI_REPO }}/jicofo:${{ needs.version.outputs.date }}
            ${{ secrets.JITSI_REPO }}/jicofo:${{ needs.version.outputs.jicofo_version }}
          sources: |
            ${{ secrets.JITSI_REPO }}/jicofo:${{ needs.version.outputs.base }}-amd64
            ${{ secrets.JITSI_REPO }}/jicofo:${{ needs.version.outputs.base }}-arm64

  jigasi-arch:
    runs-on: ${{ matrix.config.os }}
    strategy:
        fail-fast: false
        matrix:
          config:
            - { os: ubuntu-24.04, arch: amd64 }
            - { os: ubuntu-24.04-arm, arch: arm64 }
    needs: [version, base-java]
    steps:
      - name: Check out code
        uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5  # v4
      - name: Setup Docker Buildx
        uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f  # v3
        with:
          driver: docker
      - name: Login to DockerHub
        uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9  # v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Build and push
        uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8  # v6
        with:
          push: true
          context: ./jigasi
          tags: |
            ${{ secrets.JITSI_REPO }}/jigasi:${{ needs.version.outputs.base }}-${{ matrix.config.arch }}
            ${{ secrets.JITSI_REPO }}/jigasi:${{ needs.version.outputs.date }}-${{ matrix.config.arch }}
            ${{ secrets.JITSI_REPO }}/jigasi:${{ needs.version.outputs.jigasi_version }}-${{ matrix.config.arch }}
          build-args: |
            JITSI_REPO=${{ secrets.JITSI_REPO }}
            BASE_TAG=${{ needs.version.outputs.base }}

  jigasi:
    runs-on: ubuntu-latest
    needs: [version, jigasi-arch]
    steps:
      - name: Login to DockerHub
        uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9  # v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Create Docker Manifest
        uses: int128/docker-manifest-create-action@44422a4b046d55dc036df622039ed3aec43c613c  # v2
        with:
          tags: |
            ${{ secrets.JITSI_REPO }}/jigasi:${{ needs.version.outputs.base }}
            ${{ secrets.JITSI_REPO }}/jigasi:${{ needs.version.outputs.date }}
            ${{ secrets.JITSI_REPO }}/jigasi:${{ needs.version.outputs.jigasi_version }}
          sources: |
            ${{ secrets.JITSI_REPO }}/jigasi:${{ needs.version.outputs.base }}-amd64
            ${{ secrets.JITSI_REPO }}/jigasi:${{ needs.version.outputs.base }}-arm64

  jvb-arch:
    runs-on: ${{ matrix.config.os }}
    strategy:
        fail-fast: false
        matrix:
          config:
            - { os: ubuntu-24.04, arch: amd64 }
            - { os: ubuntu-24.04-arm, arch: arm64 }
    needs: [version, base-java]
    steps:
      - name: Check out code
        uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5  # v4
      - name: Setup Docker Buildx
        uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f  # v3
        with:
          driver: docker
      - name: Login to DockerHub
        uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9  # v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Build and push
        uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8  # v6
        with:
          push: true
          context: ./jvb
          tags: |
            ${{ secrets.JITSI_REPO }}/jvb:${{ needs.version.outputs.base }}-${{ matrix.config.arch }}
            ${{ secrets.JITSI_REPO }}/jvb:${{ needs.version.outputs.date }}-${{ matrix.config.arch }}
            ${{ secrets.JITSI_REPO }}/jvb:${{ needs.version.outputs.jvb_version }}-${{ matrix.config.arch }}
          build-args: |
            JITSI_REPO=${{ secrets.JITSI_REPO }}
            BASE_TAG=${{ needs.version.outputs.base }}

  jvb:
    runs-on: ubuntu-latest
    needs: [version, jvb-arch]
    steps:
      - name: Login to DockerHub
        uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9  # v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Create Docker Manifest
        uses: int128/docker-manifest-create-action@44422a4b046d55dc036df622039ed3aec43c613c  # v2
        with:
          tags: |
            ${{ secrets.JITSI_REPO }}/jvb:${{ needs.version.outputs.base }}
            ${{ secrets.JITSI_REPO }}/jvb:${{ needs.version.outputs.date }}
            ${{ secrets.JITSI_REPO }}/jvb:${{ needs.version.outputs.jvb_version }}
          sources: |
            ${{ secrets.JITSI_REPO }}/jvb:${{ needs.version.outputs.base }}-amd64
            ${{ secrets.JITSI_REPO }}/jvb:${{ needs.version.outputs.base }}-arm64

  prosody-arch:
    runs-on: ${{ matrix.config.os }}
    strategy:
        fail-fast: false
        matrix:
          config:
            - { os: ubuntu-24.04, arch: amd64 }
            - { os: ubuntu-24.04-arm, arch: arm64 }
    needs: [version, base]
    steps:
      - name: Check out code
        uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5  # v4
      - name: Setup Docker Buildx
        uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f  # v3
        with:
          driver: docker
      - name: Login to DockerHub
        uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9  # v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Build and push
        uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8  # v6
        with:
          push: true
          context: ./prosody
          tags: |
            ${{ secrets.JITSI_REPO }}/prosody:${{ needs.version.outputs.base }}-${{ matrix.config.arch }}
            ${{ secrets.JITSI_REPO }}/prosody:${{ needs.version.outputs.date }}-${{ matrix.config.arch }}
            ${{ secrets.JITSI_REPO }}/prosody:${{ needs.version.outputs.prosody_version }}-${{ matrix.config.arch }}
          build-args: |
            JITSI_REPO=${{ secrets.JITSI_REPO }}
            BASE_TAG=${{ needs.version.outputs.base }}

  prosody:
    runs-on: ubuntu-latest
    needs: [version, prosody-arch]
    steps:
      - name: Login to DockerHub
        uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9  # v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Create Docker Manifest
        uses: int128/docker-manifest-create-action@44422a4b046d55dc036df622039ed3aec43c613c  # v2
        with:
          tags: |
            ${{ secrets.JITSI_REPO }}/prosody:${{ needs.version.outputs.base }}
            ${{ secrets.JITSI_REPO }}/prosody:${{ needs.version.outputs.date }}
            ${{ secrets.JITSI_REPO }}/prosody:${{ needs.version.outputs.prosody_version }}
          sources: |
            ${{ secrets.JITSI_REPO }}/prosody:${{ needs.version.outputs.base }}-amd64
            ${{ secrets.JITSI_REPO }}/prosody:${{ needs.version.outputs.base }}-arm64

  web-arch:
    runs-on: ${{ matrix.config.os }}
    strategy:
        fail-fast: false
        matrix:
          config:
            - { os: ubuntu-24.04, arch: amd64 }
            - { os: ubuntu-24.04-arm, arch: arm64 }
    needs: [version, base]
    steps:
      - name: Check out code
        uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5  # v4
      - name: Setup Docker Buildx
        uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f  # v3
        with:
          driver: docker
      - name: Login to DockerHub
        uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9  # v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Build and push
        uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8  # v6
        with:
          push: true
          context: ./web
          tags: |
            ${{ secrets.JITSI_REPO }}/web:${{ needs.version.outputs.base }}-${{ matrix.config.arch }}
            ${{ secrets.JITSI_REPO }}/web:${{ needs.version.outputs.date }}-${{ matrix.config.arch }}
            ${{ secrets.JITSI_REPO }}/web:${{ needs.version.outputs.web_version }}-${{ matrix.config.arch }}
          build-args: |
            JITSI_REPO=${{ secrets.JITSI_REPO }}
            BASE_TAG=${{ needs.version.outputs.base }}

  web:
    runs-on: ubuntu-latest
    needs: [version, web-arch]
    steps:
      - name: Login to DockerHub
        uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9  # v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Create Docker Manifest
        uses: int128/docker-manifest-create-action@44422a4b046d55dc036df622039ed3aec43c613c  # v2
        with:
          tags: |
            ${{ secrets.JITSI_REPO }}/web:${{ needs.version.outputs.base }}
            ${{ secrets.JITSI_REPO }}/web:${{ needs.version.outputs.date }}
            ${{ secrets.JITSI_REPO }}/web:${{ needs.version.outputs.web_version }}
          sources: |
            ${{ secrets.JITSI_REPO }}/web:${{ needs.version.outputs.base }}-amd64
            ${{ secrets.JITSI_REPO }}/web:${{ needs.version.outputs.base }}-arm64
