name: tfsec release
on:
  push:
    tags:
      - v*

jobs:
  build:
    name: releasing tfsec
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
      with:
        fetch-depth: 0
    
    - uses: actions/setup-go@v2
      with:
        stable: 'false'
        go-version: '1.16.6'
    - run: go version
    
    - name: Import GPG key
      id: import_gpg
      uses: crazy-max/ghaction-import-gpg@v3
      with:
        gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
        passphrase: ${{ secrets.GPG_PASSPHRASE }}

    - name: Login to docker.io registry
      uses: docker/login-action@v1
      with:
        username: ${{ secrets.DOCKERHUB_USER }}
        password: ${{ secrets.DOCKERHUB_TOKEN }}

    - name: Release
      uses: goreleaser/goreleaser-action@v2
      with: 
       version: latest
       args: release --rm-dist
      env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

    - name: Release Docs
      run: make publish-docs
      env:
          DOCS_GITHUB_TOKEN: ${{ secrets.DOCS_GITHUB_TOKEN }}

# temporary hack to copy over the aquasec images to legacy docker hub repo
    - name: Login to docker.io registry
      uses: docker/login-action@v1
      with:
        username: ${{ secrets.TFSEC_DOCKERHUB_USER }}
        password: ${{ secrets.TFSEC_DOCKERHUB_TOKEN }}

    - name: Tfsec image building
      run: make clone-image
