name: Release

on:
  push:
    tags:
      - "v*"
  workflow_dispatch: {}

jobs:
  publish-cli:
    runs-on: ubuntu-latest
    env:
      VELA_VERSION: ${{ github.ref }}
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    steps:
      - name: Set up Go
        uses: actions/setup-go@v1
        with:
          go-version: 1.16
        id: go
      - name: Check out code into the Go module directory
        uses: actions/checkout@v2
      - name: Get the version
        id: get_version
        run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/}
      - name: Tag helm chart image
        run:  |
          sed -i 's/latest/${{ steps.get_version.outputs.VERSION }}/g' charts/vela-core/values.yaml
          sed -i 's/0.1.0/${{ steps.get_version.outputs.VERSION }}/g' charts/vela-core/Chart.yaml
      - name: Run cross-build
        run: make cross-build
      - name: Run compress binary
        run: make compress
      - name: Get release
        id: get_release
        uses: bruceadams/get-release@v1.2.2
      - name: Upload Vela Linux amd64 tar.gz
        uses: actions/upload-release-asset@v1.0.2
        with:
          upload_url: ${{ steps.get_release.outputs.upload_url }}
          asset_path: ./_bin/vela/vela-linux-amd64.tar.gz
          asset_name: vela-${{ steps.get_version.outputs.VERSION }}-linux-amd64.tar.gz
          asset_content_type: binary/octet-stream
      - name: Upload Vela Linux amd64 zip
        uses: actions/upload-release-asset@v1.0.2
        with:
          upload_url: ${{ steps.get_release.outputs.upload_url }}
          asset_path: ./_bin/vela/vela-linux-amd64.zip
          asset_name: vela-${{ steps.get_version.outputs.VERSION }}-linux-amd64.zip
          asset_content_type: binary/octet-stream
      - name: Upload Vela MacOS tar.gz
        uses: actions/upload-release-asset@v1.0.2
        with:
          upload_url: ${{ steps.get_release.outputs.upload_url }}
          asset_path: ./_bin/vela/vela-darwin-amd64.tar.gz
          asset_name: vela-${{ steps.get_version.outputs.VERSION }}-darwin-amd64.tar.gz
          asset_content_type: binary/octet-stream
      - name: Upload Vela MacOS zip
        uses: actions/upload-release-asset@v1.0.2
        with:
          upload_url: ${{ steps.get_release.outputs.upload_url }}
          asset_path: ./_bin/vela/vela-darwin-amd64.zip
          asset_name: vela-${{ steps.get_version.outputs.VERSION }}-darwin-amd64.zip
          asset_content_type: binary/octet-stream
      - name: Upload Vela Windows tar.gz
        uses: actions/upload-release-asset@v1.0.2
        with:
          upload_url: ${{ steps.get_release.outputs.upload_url }}
          asset_path: ./_bin/vela/vela-windows-amd64.tar.gz
          asset_name: vela-${{ steps.get_version.outputs.VERSION }}-windows-amd64.tar.gz
          asset_content_type: binary/octet-stream
      - name: Upload Vela Windows zip
        uses: actions/upload-release-asset@v1.0.2
        with:
          upload_url: ${{ steps.get_release.outputs.upload_url }}
          asset_path: ./_bin/vela/vela-windows-amd64.zip
          asset_name: vela-${{ steps.get_version.outputs.VERSION }}-windows-amd64.zip
          asset_content_type: binary/octet-stream
      - name: Upload Kubectl-Vela Linux amd64 tar.gz
        uses: actions/upload-release-asset@v1.0.2
        with:
          upload_url: ${{ steps.get_release.outputs.upload_url }}
          asset_path: ./_bin/kubectl-vela/kubectl-vela-linux-amd64.tar.gz
          asset_name: kubectl-vela-${{ steps.get_version.outputs.VERSION }}-linux-amd64.tar.gz
          asset_content_type: binary/octet-stream
      - name: Upload Kubectl-Vela Linux amd64 zip
        uses: actions/upload-release-asset@v1.0.2
        with:
          upload_url: ${{ steps.get_release.outputs.upload_url }}
          asset_path: ./_bin/kubectl-vela/kubectl-vela-linux-amd64.zip
          asset_name: kubectl-vela-${{ steps.get_version.outputs.VERSION }}-linux-amd64.zip
          asset_content_type: binary/octet-stream
      - name: Upload Kubectl-Vela MacOS tar.gz
        uses: actions/upload-release-asset@v1.0.2
        with:
          upload_url: ${{ steps.get_release.outputs.upload_url }}
          asset_path: ./_bin/kubectl-vela/kubectl-vela-darwin-amd64.tar.gz
          asset_name: kubectl-vela-${{ steps.get_version.outputs.VERSION }}-darwin-amd64.tar.gz
          asset_content_type: binary/octet-stream
      - name: Upload Kubectl-Vela MacOS zip
        uses: actions/upload-release-asset@v1.0.2
        with:
          upload_url: ${{ steps.get_release.outputs.upload_url }}
          asset_path: ./_bin/kubectl-vela/kubectl-vela-darwin-amd64.zip
          asset_name: kubectl-vela-${{ steps.get_version.outputs.VERSION }}-darwin-amd64.zip
          asset_content_type: binary/octet-stream
      - name: Upload Kubectl-Vela Windows tar.gz
        uses: actions/upload-release-asset@v1.0.2
        with:
          upload_url: ${{ steps.get_release.outputs.upload_url }}
          asset_path: ./_bin/kubectl-vela/kubectl-vela-windows-amd64.tar.gz
          asset_name: kubectl-vela-${{ steps.get_version.outputs.VERSION }}-windows-amd64.tar.gz
          asset_content_type: binary/octet-stream
      - name: Upload Kubectl-Vela Windows zip
        uses: actions/upload-release-asset@v1.0.2
        with:
          upload_url: ${{ steps.get_release.outputs.upload_url }}
          asset_path: ./_bin/kubectl-vela/kubectl-vela-windows-amd64.zip
          asset_name: kubectl-vela-${{ steps.get_version.outputs.VERSION }}-windows-amd64.zip
          asset_content_type: binary/octet-stream
      - name: Upload Checksums
        uses: actions/upload-release-asset@v1.0.2
        with:
          upload_url: ${{ steps.get_release.outputs.upload_url }}
          asset_path: ./_bin/sha256sums.txt
          asset_name: sha256sums.txt
          asset_content_type: text/plain
      - name: Update kubectl plugin version in krew-index
        uses: rajatjindal/krew-release-bot@v0.0.38
