name: com.angoosh.RDPConnect deploy
run-name: ${{ gitea.actor }}
on:
  push:
    branches: [main]
    paths:
      - com.angoosh.RDPConnect/**
jobs:
  flatpak:
    name: "Flatpak"
    runs-on: ubuntu-latest
    container: 
      image: bilelmoussaoui/flatpak-github-actions:gnome-44
      options: --privileged

    steps:
    - run: sudo dnf install -y nodejs
    - name: "Check out repo code"
      uses: actions/checkout@v4
    - name: Import GPG key
      uses: crazy-max/ghaction-import-gpg@v6
      with:
        gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
        passphrase: ${{ secrets.GPG_PRIVATE_KEY_PASS }}

    - name: "Build"
      uses: flatpak/flatpak-github-actions/flatpak-builder@v6
      with:
        build-bundle: false
        upload-artifact: false
        cache: false
        restore-cache: false
        manifest-path: com.angoosh.RDPConnect/com.angoosh.RDPConnect.yml
        cache-key: flatpak-builder-${{ gitea.sha }}
        gpg-sign: kaplanantonin@gmail.com

    - name: Push flatpak to repo
      run: |
        git clone https://github.com/flatpak/flat-manager.git
        export REPO_TOKEN=${{ secrets.FLATMAN_API_TOKEN }}
        export FLATMAN_URL=$(./flat-manager/flat-manager-client create https://flatpak.angoosh.com stable)
        echo $REPO_TOKEN
        echo $FLATMAN_URL
        ./flat-manager/flat-manager-client push --commit $FLATMAN_URL repo
        ./flat-manager/flat-manager-client publish $FLATMAN_URL
