name: master actions
run-name: build with docker
on:
  push:
    branches:
      - master
    tags:
      - v*

jobs:

    gettag:
        runs-on: ubuntu-latest
        outputs:
          version_tag: ${{ steps.set_version.outputs.VERSION }}
        steps:
        - name: 'Set Version Tag'
          id: set_version
          run: |
              if [ "${{ github.ref_type }}" == "tag" ]; then
                VERSION=${{ github.ref_name }}
              else
                VERSION="latest"
              fi
              echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
        - name: 'Use Version Tag'
          run: |
            echo "The determined version tag is: ${{ steps.set_version.outputs.VERSION }}"

    linux-image-deploy:
        runs-on: ubuntu-latest
        needs: gettag
        steps:
            - name: Check out code
              uses: actions/checkout@v3
              with:
                fetch-depth: 0
            - name: build  image
              run: docker build -t gpac-ubuntu -f build/docker/ubuntu.Dockerfile .
            - name: check docker images
              run: docker image list
            - name: check docker run
              run: docker run gpac-ubuntu || true
            - name: login docker hub
              run: docker login --username gpac  --password ${{secrets.DOCKER_HUB_TOKEN}}
            - name: tag docker image
              run: docker tag gpac-ubuntu gpac/ubuntu:${{ needs.gettag.outputs.version_tag }}
            - name: push docker image
              run: docker push gpac/ubuntu:${{ needs.gettag.outputs.version_tag }}


    wasm-image-deploy:
        runs-on: ubuntu-latest
        needs: gettag
        steps:
            - name: Check out code
              uses: actions/checkout@v3
              with:
                fetch-depth: 0
            - name: build image
              run: docker build -t gpac-wasm -f build/docker/wasm.Dockerfile .
            - name: check docker images
              run: docker image list
            - name: check docker run
              run: docker run gpac-wasm || true
            - name: login docker hub
              run: docker login --username gpac  --password ${{secrets.DOCKER_HUB_TOKEN}}
            - name: tag docker image
              run: docker tag gpac-wasm gpac/wasm:${{ needs.gettag.outputs.version_tag }}
            - name: push docker image
              run: docker push gpac/wasm:${{ needs.gettag.outputs.version_tag }}
