name: ci
on: push
jobs:
  kubeconform-test:
    runs-on: ubuntu-latest
    steps:
    - name: checkout
      uses: actions/checkout@v4

    - name: test
      run: make docker-test

    - name: build
      run: make goreleaser-build-static

    - name: acceptance-test
      run: make docker-acceptance

  openapi2jsonschema-test:
    runs-on: ubuntu-latest
    steps:
      - name: checkout
        uses: actions/checkout@v4

      - name: test
        working-directory: ./scripts
        run: make docker-test docker-acceptance

  goreleaser:
    runs-on: ubuntu-latest
    needs:
      - kubeconform-test
      - openapi2jsonschema-test
    if: startsWith(github.ref, 'refs/tags/v')
    steps:
      - name: checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0 # https://github.com/goreleaser/goreleaser-action/issues/56

      - uses: docker/setup-qemu-action@v3
      - uses: docker/setup-buildx-action@v3

      - name: goreleaser
        run: |
          echo "${{ github.token }}" | docker login https://ghcr.io -u ${GITHUB_ACTOR} --password-stdin
          GITHUB_ACTOR=$(echo ${GITHUB_ACTOR} | tr '[:upper:]' '[:lower:]')
          GIT_OWNER=${GITHUB_ACTOR} make release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
