name: "Release Stable"

on:
  workflow_dispatch:
    inputs:
      version:
        description: Version number
        required: true
        type: string
jobs:
  gh-release:
    runs-on: ubuntu-latest
    needs: [base, base-java, jibri, jicofo, jigasi, jvb, prosody, web]
    permissions:
      # Give the default GITHUB_TOKEN write permission to commit and push the changed files back to the repository.
      contents: write
    steps:
      - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5  # v4
      - run: |
          sed -i".bak" -e "s/unstable/stable-${{ github.event.inputs.version }}/" *.yml
      - uses: stefanzweifel/git-auto-commit-action@b863ae1933cb653a53c021fe36dbb774e1fb9403  # v5
        with:
            commit_message: "release: stable-${{ github.event.inputs.version }}"
      - name: release
        uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65  # v2
        with:
            tag_name: stable-${{ github.event.inputs.version }}
            generate_release_notes: true
            make_latest: true
      - run: |
          sed -i".bak" -e "s/stable-${{ github.event.inputs.version }}/unstable/" *.yml
      - uses: stefanzweifel/git-auto-commit-action@b863ae1933cb653a53c021fe36dbb774e1fb9403  # v5
        with:
            commit_message: "misc: working on unstable"

  base:
    runs-on: ubuntu-latest
    steps:
      - name: Check out code
        uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5  # v4
      - name: Set up QEMU
        uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130  # v3
        with:
          platforms: linux/amd64,linux/arm64
      - name: Setup Docker Buildx
        uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f  # v3
      - 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:stable-${{ github.event.inputs.version }}
            ${{ secrets.JITSI_REPO }}/base:stable
          build-args: |
            JITSI_RELEASE=stable
          platforms: linux/amd64,linux/arm64
          cache-from: type=gha
          cache-to: type=gha,mode=max

  base-java:
    runs-on: ubuntu-latest
    needs: base
    steps:
      - name: Check out code
        uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5  # v4
      - name: Set up QEMU
        uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130  # v3
        with:
          platforms: linux/amd64,linux/arm64
      - name: Setup Docker Buildx
        uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f  # v3
      - 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:stable-${{ github.event.inputs.version }}
            ${{ secrets.JITSI_REPO }}/base-java:stable
          build-args: |
            JITSI_REPO=${{ secrets.JITSI_REPO }}
            BASE_TAG=stable-${{ github.event.inputs.version }}
          platforms: linux/amd64,linux/arm64
          cache-from: type=gha
          cache-to: type=gha,mode=max

  jibri:
    runs-on: ubuntu-latest
    needs: base-java
    steps:
      - name: Check out code
        uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5  # v4
      - name: Set up QEMU
        uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130  # v3
        with:
          platforms: linux/amd64,linux/arm64
      - name: Setup Docker Buildx
        uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f  # v3
      - 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:stable-${{ github.event.inputs.version }}
            ${{ secrets.JITSI_REPO }}/jibri:stable
          build-args: |
            JITSI_REPO=${{ secrets.JITSI_REPO }}
            BASE_TAG=stable-${{ github.event.inputs.version }}
          platforms: linux/amd64,linux/arm64
          cache-from: type=gha
          cache-to: type=gha,mode=max

  jicofo:
    runs-on: ubuntu-latest
    needs: base-java
    steps:
      - name: Check out code
        uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5  # v4
      - name: Set up QEMU
        uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130  # v3
        with:
          platforms: linux/amd64,linux/arm64
      - name: Setup Docker Buildx
        uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f  # v3
      - 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:stable-${{ github.event.inputs.version }}
            ${{ secrets.JITSI_REPO }}/jicofo:stable
          build-args: |
            JITSI_REPO=${{ secrets.JITSI_REPO }}
            BASE_TAG=stable-${{ github.event.inputs.version }}
          platforms: linux/amd64,linux/arm64
          cache-from: type=gha
          cache-to: type=gha,mode=max

  jigasi:
    runs-on: ubuntu-latest
    needs: base-java
    steps:
      - name: Check out code
        uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5  # v4
      - name: Set up QEMU
        uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130  # v3
        with:
          platforms: linux/amd64,linux/arm64
      - name: Setup Docker Buildx
        uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f  # v3
      - 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:stable-${{ github.event.inputs.version }}
            ${{ secrets.JITSI_REPO }}/jigasi:stable
          build-args: |
            JITSI_REPO=${{ secrets.JITSI_REPO }}
            BASE_TAG=stable-${{ github.event.inputs.version }}
          platforms: linux/amd64,linux/arm64
          cache-from: type=gha
          cache-to: type=gha,mode=max

  jvb:
    runs-on: ubuntu-latest
    needs: base-java
    steps:
      - name: Check out code
        uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5  # v4
      - name: Set up QEMU
        uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130  # v3
        with:
          platforms: linux/amd64,linux/arm64
      - name: Setup Docker Buildx
        uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f  # v3
      - 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:stable-${{ github.event.inputs.version }}
            ${{ secrets.JITSI_REPO }}/jvb:stable
          build-args: |
            JITSI_REPO=${{ secrets.JITSI_REPO }}
            BASE_TAG=stable-${{ github.event.inputs.version }}
          platforms: linux/amd64,linux/arm64
          cache-from: type=gha
          cache-to: type=gha,mode=max

  prosody:
    runs-on: ubuntu-latest
    needs: base
    steps:
      - name: Check out code
        uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5  # v4
      - name: Set up QEMU
        uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130  # v3
        with:
          platforms: linux/amd64,linux/arm64
      - name: Setup Docker Buildx
        uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f  # v3
      - 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:stable-${{ github.event.inputs.version }}
            ${{ secrets.JITSI_REPO }}/prosody:stable
          build-args: |
            JITSI_REPO=${{ secrets.JITSI_REPO }}
            BASE_TAG=stable-${{ github.event.inputs.version }}
          platforms: linux/amd64,linux/arm64
          cache-from: type=gha
          cache-to: type=gha,mode=max

  web:
    runs-on: ubuntu-latest
    needs: base
    steps:
      - name: Check out code
        uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5  # v4
      - name: Set up QEMU
        uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130  # v3
        with:
          platforms: linux/amd64,linux/arm64
      - name: Setup Docker Buildx
        uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f  # v3
      - 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:stable-${{ github.event.inputs.version }}
            ${{ secrets.JITSI_REPO }}/web:stable
          build-args: |
            JITSI_REPO=${{ secrets.JITSI_REPO }}
            BASE_TAG=stable-${{ github.event.inputs.version }}
          platforms: linux/amd64,linux/arm64
          cache-from: type=gha
          cache-to: type=gha,mode=max
