on:
  push:

jobs:
  build:
    runs-on: container
    steps:
      - uses: actions/checkout@v4

      - uses: pnpm/action-setup@v4
        name: Install pnpm
        with:
          run_install: false

      - name: Install Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: "pnpm"

      - name: Install dependencies
        run: pnpm install

      - name: Build package (transpile ts => js)
        run: ng build

      - name: Build container
        uses: actions/buildah-build@v1
        with:
          image: treetrail-frontend
          #tags: foo # v1 ${{ github.sha }}
          containerfiles: |
            ./Containerfile

      - name: Workaround for bug of podman-login
        run: |
          mkdir -p $HOME/.docker
          echo "{ \"auths\": {} }" > $HOME/.docker/config.json

      - name: Log in to container registry (with another workaround)
        uses: actions/podman-login@v1
        with:
          registry: ${{ vars.REGISTRY }}
          username: ${{ secrets.REGISTRY_USER }}
          password: ${{ secrets.REGISTRY_PASSWORD }}
          auth_file_path: /tmp/auth.json

      - uses: actions/push-to-registry@v2
        with:
          registry: "docker://${{ vars.REGISTRY }}"
          image: treetrail-frontend
          tags: latest
