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

name: Synfig (stable)

# Controls when the action will run.
on:
  # Triggers the workflow on push or pull request events but only for the master branch
  push:
    branches: [ v1.4.x ]
  pull_request:
    branches: [ v1.4.x ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  build:
    runs-on: ${{ matrix.os }}
    continue-on-error: ${{ matrix.allow_failures }}
    name: ${{ matrix.name }}
    strategy:
      matrix:
        include:
        - os: macos-11
          name: macOS 11 Big Sur (Autotools)
          toolchain: autotools-release
          allow_failures: false
        - os: ubuntu-20.04
          name: Ubuntu 20.04 Focal (Autotools)
          allow_failures: false
          toolchain: autotools-release

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v4

      - name: Download ccache archive
        id: ccache-archive-restore
        uses: actions/cache/restore@v4
        with:
          path: .ccache
          key: synfig-ccache-${{ matrix.os }}-${{ matrix.toolchain }}
          restore-keys:
            synfig-ccache-${{ matrix.os }}-${{ matrix.toolchain }}

      - name: Install dependencies (Brew)
        if: runner.os == 'macOS'
        env:
          HOMEBREW_NO_AUTO_UPDATE: 1
          HOMEBREW_NO_ANALYTICS: 1
        run: ./1-setup-osx-brew.sh

      - name: Install dependencies (apt)
        if: runner.os == 'Linux'
        run: |
          ./1-setup-linux-native.sh
          sudo apt-get install ccache ninja-build

      - name: Setup ccache parameters and show statistics
        run: |
          ccache --set-config=compression=true
          ccache --set-config=cache_dir=${GITHUB_WORKSPACE}/.ccache
          ccache --show-stats
          ccache -p

      - name: Build (Autotools+Make)
        if: matrix.toolchain == 'autotools-release'
        run: |
          export PATH="/usr/lib/ccache/:${PATH}"
          echo ${PATH}
          ./autobuild/synfigstudio-release.sh

      - name: ccache statistics
        run: ccache --show-stats

      - name: Save cache (only for master branch)
        id: ccache-archive-save
        if: github.ref_name == 'master'
        uses: actions/cache/save@v4
        with:
          path: .ccache
          key: synfig-ccache-${{ matrix.os }}-${{ matrix.toolchain }}

