name: "Sync Apps List"

on:
  push:
    branches: main
    paths:
      - programs/x86_64-apps
      - programs/i686-apps
      - programs/aarch64-apps

  workflow_dispatch:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  sync-files:
    name: "Run sync"
    runs-on: ubuntu-22.04
    steps:
      - name: "Checkout source repository"
        uses: actions/checkout@v4

      - name: "Run lister"
        run: |
          cd programs
          ./appimage-lister-uniq.sh

      - name: "Push to Source"
        run: |
          # You have to create PAT (Personal Access Token) with repo and workflow scopes enabled
          # Save it as secret in repository where action will run (source) with name 'TARGET_REPO_TOKEN'
          # Change your email, then should work as expected
          git config --global user.name "ivan-hc"
          git config --global user.email "noreply@github.com"
          git add programs/x86_64-appimages programs/i686-appimages programs/aarch64-appimages
          if git diff-index --quiet HEAD; then
            echo "No changes to commit." >> $GITHUB_STEP_SUMMARY
          else
            git commit -m "Sync files from source repository"
            git push && echo "Sync to Source succeeded" >> $GITHUB_STEP_SUMMARY
          fi
