# This is a basic workflow to help you get started with Actions

name: Build-Stage

on:
#  push:
#    branches: [master, stage]

  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      asset-path: ${GITHUB_REF##*/}/static/js/

    steps:
      - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c  # v3.3.0

      - name: Setup Java JDK
        uses: actions/setup-java@v1.4.3
        with:
          java-version: 1.8

      - name: Set up Node
        uses: actions/setup-node@v3
        with:
            node-version: 18

      - name: Install clojure
        run: |
          curl -O https://download.clojure.org/install/linux-install-1.10.1.763.sh
          chmod +x linux-install-1.10.1.763.sh
          sudo ./linux-install-1.10.1.763.sh

      - name: Fetch yarn deps
        run: yarn cache clean && yarn install --frozen-lockfile

      - name: Build Released-Web
        run: |
          yarn gulp:build && clojure -M:cljs release app  --config-merge '{:asset-path "${{env.asset-path}}" :compiler-options {:source-map-include-sources-content false :source-map-detail-level :symbols}}'
          ls -ah ./static/js

      - name: Publish to Cloudflare Pages
        uses: cloudflare/pages-action@1
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          accountId: 2553ea8236c11ea0f88de28fce1cbfee
          projectName: 'logseq-demo'
          directory: 'static'
          gitHubToken: ${{ secrets.GITHUB_TOKEN }}
          branch: 'production'
