name: Publish docker images
on:
  workflow_dispatch:
jobs:
  docker-publish:
    name: Docker publish
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

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

      - name: Login to DockerHub
        run: echo ${{ secrets.DOCKER_ACCESS_TOKEN }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin

      - name: Build docker image
        run: docker build -t discordjs/proxy:latest -f packages/proxy-container/Dockerfile .

      - name: Tag image with major
        run: docker tag discordjs/proxy discordjs/proxy:$(cut -d '.' -f1 <<< $(jq --raw-output '.version' packages/proxy-container/package.json))

      - name: Push image to DockerHub
        run: docker push --all-tags discordjs/proxy
