name: Packaging(MacOS)

on:
  push:
    branches:
      - master
      - feature/RND-680-macos-.dmg-package-build
    paths-ignore:
      - 'README.md'
      - 'LICENSE'

  pull_request:
    paths-ignore:
      - 'README.md'
      - 'LICENSE'

env:
  PRODUCT: flameshot

jobs:
  catalina:
    name: macOS Catalina 10.15
    runs-on: macos-10.15

    env:
      APP_NAME: flameshot
      DIR_BULD: build
      DIR_PKG: build/src
      HELPERS_SCRIPTS_PATH: ../../packaging/macos
      # Apple developer identity, example: "Developer ID Application: <user name> (code)"
      # Note: no signing and notarization will be be proceed if this variable is not set
      APPLE_DEV_IDENTITY: ${{ secrets.APPLE_DEV_IDENTITY }}
      # Apple ID user
      APPLE_DEV_USER: ${{ secrets.APPLE_DEV_USER }}
      # Apple ID user password
      APPLE_DEV_PASS: ${{ secrets.APPLE_DEV_PASS }}
      # Apple certificate with private and public keys in base64 format
      APPLE_DEVELOPER_ID_APPLICATION_CERT_DATA: ${{ secrets.APPLE_DEVELOPER_ID_APPLICATION_CERT_DATA }}
      # Apple certificate password
      APPLE_DEVELOPER_ID_APPLICATION_CERT_PASS: ${{ secrets.APPLE_DEVELOPER_ID_APPLICATION_CERT_PASS }}
      # Any temporary password for keychain, which will be created on github actions CI
      APPLE_TEMP_CI_KEYCHAIN_PASS: ${{ secrets.APPLE_TEMP_CI_KEYCHAIN_PASS }}
      # Temporary variable for internal use, it will be set on the "Build dmg" step
      NOTARIZATION_CHECK: false

    steps:
      - name: Checkout Source code
        uses: actions/checkout@v1

      - name: Install Qt
        run: brew install qt@5 cmake

      - name: Configure
        run: |
          mkdir -p "${DIR_BULD}"
          cd "${DIR_BULD}"
          rm -rf ./src/flameshot.dmg ./src/flameshot.app/
          cmake .. -DQt5_DIR=$(brew --prefix qt5)/lib/cmake/Qt5 -DUSE_MONOCHROME_ICON=True

      - name: Compile
        run: |
          cd "${DIR_BULD}"
          make

      - name: Create key-chain and import certificate
        run: |
          cd "${DIR_PKG}"
          ${HELPERS_SCRIPTS_PATH}/create_keychain.sh flameshot

      - name: Build dmg package
        run: |
          cd "${DIR_PKG}"
          ${HELPERS_SCRIPTS_PATH}/sign_qtapp.sh flameshot

      - name: Upload dmg package
        shell: bash
        run: |
          python3 -m pip install -U -q requests
          echo "================MacOS dmg image download link================"
          echo $(python3 $GITHUB_WORKSPACE/scripts/upload_services/transferwee.py upload $GITHUB_WORKSPACE/build/src/flameshot.dmg)
          echo "=====no operation for you can see link in the log console====="

      - name: Artifact Upload
        uses: actions/upload-artifact@v2
        with:
          name: MacOS-artifact
          path: ${{ github.workspace }}/build/src/flameshot.dmg

      - name: Notarization status
        shell: bash
        run: |
          if [[ "${NOTARIZATION_CHECK}" == "true" ]]; then
            echo "Notarization check succeed"
          else
            echo "::warning Notarization check failed"
            # exit 1
          fi
