name: Build/release

on:
  workflow_dispatch:
  push:
    branches:
      - 'main'
    tags:
      - '*'

env:
  DEBIAN_FRONTEND: "noninteractive"
  GH_TOKEN: "${{ secrets.GH_TOKEN || secrets.GITEA_TOKEN }}"
  VERSION: "v0.1.0"
  YARN_URL: "https://github.com/yarnpkg/yarn/releases/download/v1.22.22/yarn-1.22.22.js"

jobs:
  action-release:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v6

      - name: Enable Corepack for Yarn
        run: corepack enable

      - name: Install NodeJS and NPM
        uses: actions/setup-node@v6
        with:
          node-version: latest

      - name: Install system build dependencies
        run: |
          mv /etc/apt/sources.list.d/microsoft-prod.list /etc/apt/sources.list.d/microsoft-prod.list.disabled

          until apt-get update; do
            echo -e "-----\napt-get update failed, retrying in 1s...\n-----"
            sleep 1s
          done

          apt-get install -y \
            dpkg \
            libglib2.0-dev \
            wget \
            curl \
            fakeroot \
            xvfb

      - name: Install NPM dependencies
        run: |
          yarn install

      - name: Build the electron app
        run: |
          yarn build

      - name: upload the building actifacts
        uses: actions/upload-artifact@v3
        with:
          name: packages
          path:  |
            ./release/*.deb
            ./release/*.rpm
            ./release/*.flatpak
            ./release/latest-linux.yml
          retention-days: 7
          overwrite: true
