#
# Copyright 2021 The Sigstore Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: CI-Validate-Release-Job

on:
  push:
    branches:
      - main
      - release-*
  pull_request:

jobs:
  validate-release-job:
    runs-on: ubuntu-latest

    permissions:
      actions: none
      checks: none
      contents: none
      deployments: none
      issues: none
      packages: none
      pull-requests: none
      repository-projects: none
      security-events: none
      statuses: none

    env:
      CROSS_BUILDER_IMAGE: ghcr.io/gythialy/golang-cross:v1.17.11-0@sha256:b0c3083b0a420ff649d5a5bfd7e0a96719ab0a7b3f99a049a4950d836a72637a
      COSIGN_IMAGE: gcr.io/projectsigstore/cosign:v1.8.0@sha256:12b4d428529654c95a7550a936cbb5c6fe93a046ea7454676cb6fb0ce566d78c

    steps:
      - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2
      - name: Extract version of Go to use
        run: echo "GOVERSION=$(cat Dockerfile|grep golang | awk ' { print $2 } ' | cut -d '@' -f 1 | cut -d ':' -f 2 | uniq)" >> $GITHUB_ENV
      - uses: actions/setup-go@84cbf8094393cdc5fe1fe1671ff2647332956b1a # v3.1.0
        with:
          go-version: ${{ env.GOVERSION }}
      - uses: anchore/sbom-action/download-syft@bb716408e75840bbb01e839347cd213767269d4a # v0.10.0
      - name: Install GoReleaser
        uses: goreleaser/goreleaser-action@68acf3b1adf004ac9c2f0a4259e85c5f66e99bef # v3.0.0
        with:
          install-only: true

      - name: Check Signature
        run: |
          docker run --rm \
          -e COSIGN_EXPERIMENTAL=true \
          -e TUF_ROOT=/tmp \
          $COSIGN_IMAGE \
          verify \
          $CROSS_BUILDER_IMAGE

      - name: snaphot
        run: make snapshot
        env:
          PROJECT_ID: honk-fake-project
          RUNTIME_IMAGE: gcr.io/distroless/static:debug-nonroot

      - name: check binaries
        run: |
          ./dist/rekor-server-linux-amd64 version
          ./dist/rekor-cli-linux-amd64 version
