name: build

on:
  push:
    branches: 
      - main
  pull_request:
    branches:
      - main
  release:
    types:
      - created
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      
      - name: Prepare Lattice Diamond license
        env:
          ENCODED_LICENSE: ${{ secrets.LATTICE_DIAMOND_LICENSE }}
        run: |
          mkdir -p ./flexlm
          echo "$ENCODED_LICENSE" > ./flexlm/encoded_license
          base64 -d ./flexlm/encoded_license > ./flexlm/license.dat

      - name: Build script
        env:
          MAC_ADDRESS: ${{ secrets.LATTICE_DIAMOND_MAC }}
        run: ./docker_build.sh release --force-clean

      - name: Upload artifact
        uses: actions/upload-artifact@v2
        with:
          name: SC64
          path: SC64.zip

      - name: Get release
        if: github.event_name == 'release' && github.event.action == 'created'
        id: get_release
        uses: bruceadams/get-release@v1.2.2
        env:
          GITHUB_TOKEN: ${{ github.token }}

      - name: Upload release asset
        if: github.event_name == 'release' && github.event.action == 'created'
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ github.token }}
        with:
          upload_url: ${{ steps.get_release.outputs.upload_url }}
          asset_path: SC64.zip
          asset_name: SC64.zip
          asset_content_type: application/zip
