name: Package push

on:
    push:
        branches: [ master ]
    release:
        types: [ created ]

jobs:
    build:

        runs-on: ubuntu-latest

        steps:
            -   name: Setup PHP with PECL extension
                uses: shivammathur/setup-php@v2
                with:
                    php-version: '7.4'

            - name: Set git credentials
              run: git config --global user.name "Vassyli" && git config --global user.email "basilius.sauter+automated@gmail.com" && git config --global user.password "${{ secrets.GH_TOKEN }}"

            - name: Set composer token
              run: composer config -g github-oauth.github.com ${{ secrets.GH_TOKEN }}

            - name: "Checkouts satis and packages"
              run: git clone https://github.com/composer/satis && git clone https://github.com/lotgd/packages

            - name: "Install satis"
              run: cd satis && composer install && cd ..

            - name: "Build satis"
              run: satis/bin/satis build packages/satis.json packages/build

            - name: Set git url with credentials for pushing
              run: cd packages && git config remote.origin.url 'https://Vassyli:${{ secrets.GH_TOKEN }}@github.com/lotgd/packages.git' && cd ..

            - name: "Commit changes and push to origin"
              run: cd packages && git add build/* && git commit -a -m "Updated packages" && git push origin master && cd ..
