name: Nightly build

# Trigger the workflow every day at 5 AM (UTC).
on:
  schedule:
    - cron: '0 5 * * *'
  workflow_dispatch:

jobs:
  nightly-build:
    runs-on: ubuntu-24.04
    steps:
      - name: Check out lingua-franca repository
        uses: actions/checkout@v3
        with:
          submodules: recursive
          fetch-depth: 0
      - name: Prepare build environment
        uses: ./.github/actions/prepare-build-env
      - name: Modify property file to contain the commit SHA
        shell: bash
        run: |
          TIMESTAMP="$(date +'%Y-%m-%d')"
          SHA="$(git rev-parse --short HEAD)"
          sed --regexp-extended --in-place "s/^(VERSION = .*)$/\1 ${SHA} ${TIMESTAMP}/" core/src/main/resources/org/lflang/StringsBundle.properties
      - name: Build and package lf cli tools (nightly build)
        shell: bash
        run: |
          export TIMESTAMP="$(date +'%Y%m%d%H%M%S')"
          ./gradlew build -Pnightly=$TIMESTAMP -PtargetOS=Linux -PtargetArch=x86_64
          ./gradlew assemble -Pnightly=$TIMESTAMP -PtargetOS=Linux -PtargetArch=aarch64
          ./gradlew assemble -Pnightly=$TIMESTAMP -PtargetOS=MacOS -PtargetArch=x86_64
          ./gradlew assemble -Pnightly=$TIMESTAMP -PtargetOS=MacOS -PtargetArch=aarch64
          ./gradlew assemble -Pnightly=$TIMESTAMP -PtargetOS=Windows -PtargetArch=x86_64
      - name: Deploy nightly release
        uses: marvinpinto/action-automatic-releases@latest
        with:
          repo_token: "${{ secrets.NIGHTLY_BUILD }}"
          automatic_release_tag: 'nightly'
          prerelease: true
          title: "Lingua Franca Nightly"
          files: |
            build/distributions/*
