name: joinApps.sh

on:
  push:
    branches:
    - '**'
  #schedule:
  #- cron:  '15 0 * * *'
env:
 appsfolder: template/apps
 ptArm32: template/portainer-v2-arm32.json
 ptArm64: template/portainer-v2-arm64.json
 ptAmd64: template/portainer-v2-amd64.json
 README: docs/README.md
 README_TEMPLATE: build/templates/template_README.md
 TOOLSREADME: tools/README.md
 TOOLSREADME_TEMPLATE: build/templates/template_tools_README.md
 AppList: docs/AppList.md
 AppList_TEMPLATE: build/templates/template_AppList.md
 DocList: docs/DocumentList.md
 DocList_TEMPLATE: build/templates/template_DocumentList.md
 appinfo: build/info.json
 Scripts: ../tools/
 Extras: ../tools/
 Docs: ../docs/
 verificationFile: build/tmp/lastrun.sha256


jobs:
  run_joinApps:
    name: Run joinApps.sh script
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    #- uses: cardinalby/export-env-action@v1
    #  with:
    #    envFile: 'build/env-workflow.sh'
    - name: Check
      run: |
           pwd
           env
    - name: Joining Apps
      run: build/joinApps.sh
    - name: Generate App List
      run: build/generators/generateAppList.sh
    - name: Generate Doc List
      run: build/generators/generateDocList.sh
    - name: Generate README
      run: build/generators/generateREADME.sh
    - name: Generate README Tools
      run: build/generators/generateToolsREADME.sh
    - name: Commit files
      run: |
        git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
        git config --global user.name "github-actions[bot]"
        git add -- "$ptArm32"
        git add -- "$ptArm64"
        git add -- "$ptAmd64"
        git add ./pi-hosted_template/template/portainer-v2.json
        git add -- "$README"
        git add -- "$TOOLSREADME"
        git add -- "$AppList"
        git add -- "$DocList"
        git commit -m "Build App list and docs" || echo "No new apps detected"
    - name: Push changes
      uses: ad-m/github-push-action@master
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        force: true
        branch: ${{ github.ref }}
