name: Update Submodules on: workflow_dispatch: schedule: - cron: "0 2 * * 5" jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 with: ref: '4.x-dev' lfs: false - name: Prepare branches run: | cat <<- EOF > $HOME/.netrc machine github.com login $GITHUB_ACTOR password $GITHUB_TOKEN machine api.github.com login $GITHUB_ACTOR password $GITHUB_TOKEN EOF chmod 600 $HOME/.netrc git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com" git config --global user.name "$GITHUB_ACTOR" git remote add upstream https://github.com/matomo-org/matomo.git git push origin --delete submodules || true git branch -D submodules || true git fetch upstream 4.x-dev git checkout -f upstream/4.x-dev git branch submodules git checkout -f submodules - name: Checkout submodules run: git submodule update --init --force - name: Update all submodules run: git submodule foreach "git checkout 4.x-dev || git checkout master; git pull --ff-only" - name: Check for changes id: changes run: | git submodule | grep -oE '^\+[0-9a-f]+ ([A-z\/\-]+)' | cut -d' ' -f 2 | xargs -r git add IFS=$'\n' changes=( $(git diff --staged --numstat | grep -oE '[A-z0-9\/\-]{2,}' ) ) # abort here if no change available if [[ ${#changes[@]} -eq 0 ]] then exit 0 fi message="Updated submodules:\n" for (( i=0; i < ${#changes[@]}; i++ )); do message="$message- ${changes[$i]}\n" done echo $message echo ::set-output name=message::$message shell: bash - name: Push changes run: | git commit -m "updates all submodules" git push --set-upstream origin submodules - name: Create PR run: | curl \ --request POST \ --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ --header 'content-type: application/json' \ --data '{ "title":"[automatic submodule updates]", "body":"${{ steps.changes.outputs.message }}", "head":"submodules", "base":"4.x-dev" }' \ --url https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls shell: bash if: steps.changes.outputs.message