Update Submodules #236
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update Submodules | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 2 * * 5" | |
permissions: | |
actions: read | |
checks: none | |
contents: write | |
deployments: none | |
issues: read | |
packages: none | |
pull-requests: write | |
repository-projects: none | |
security-events: none | |
statuses: none | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: '5.x-dev' | |
lfs: false | |
persist-credentials: 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 "[email protected]" | |
git config --global user.name "$GITHUB_ACTOR" | |
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY | |
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 5.x-dev | |
git checkout -f upstream/5.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 5.x-dev || git checkout master; git pull --ff-only" | |
- name: Check for changes | |
id: changes | |
continue-on-error: true | |
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,}' || true ) ) | |
unset IFS | |
# 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 "message=$message" >> $GITHUB_OUTPUT | |
shell: bash | |
- name: Push changes | |
run: | | |
git commit -m "Update all submodules" | |
git push --set-upstream origin submodules | |
shell: bash | |
if: steps.changes.outputs.message | |
- 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":"5.x-dev" | |
}' \ | |
--url https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls | |
shell: bash | |
if: steps.changes.outputs.message |