Updating all python modules CI github workflow

The script bellow enable to update one file across many github repositories a better alternative could be to use submodule for the github actions

#!/bin/bash # Author: Patrick Delcroix # Email: patrick.delcroix@swisstph.ch # Created Date: 17.01.2022 # Credit: https://www.middlewareinventory.com/blog/github-list-all-repositories-using-rest-api/ FILENAME=openmis-module-test.yml KEYWORD=jobs ORG=openimis USERNAME= TOKEN= userdata=`curl -u $USERNAME:$TOKEN -H "Accept: application/vnd.github.v3+json" -s "https://api.github.com/users/${USERNAME}"` echo $userdata > userdata.json useremail=$(jq -r '.email' <<< $userdata) username=$(jq -r '.name' <<< $userdata) echo $username echo $useremail git config --global credential.helper 'store --file ~/.my-credentials' echo "https://${TOKEN}:x-oauth-basic@github.com" > ~/.my-credentials git config --global user.email $useremail git config --global user.name $username # No of reposoitories per page - Maximum Limit is 100 PERPAGE=100 # Change the BASEURL to your Org or User based # Org base URL BASEURL="https://api.github.com/search/code?q=${KEYWORD}+org:${ORG}+filename:${FILENAME}" # User base URL # BASEURL="https://api.github.com/user/<your_github_username>/repos" # Calculating the Total Pages after enabling Pagination i=0 if test -f "$FILENAME"; then echo "${BASEURL}&per_page\=${PERPAGE}" #TOTALPAGES=`curl -I -i -u $USERNAME:$TOKEN -H "Accept: application/vnd.github.v3+json" -s "${BASEURL}&per_page=${PERPAGE}" | grep -i link: 2>/dev/null|sed 's/link: //g'|awk -F',' -v ORS='\n' '{ for (i = 1; i <= NF; i++) print $i }'|grep -i last|awk '{print $1}' | tr -d '\<\>' | tr '\?\&' ' '|awk '{print $3}'| tr -d '=;page'` #TOTALPAGES=0 #until [ $i -gt $TOTALPAGES ] #do echo "page=${i}" tempfile=`curl -s -u $USERNAME:$TOKEN -H 'Accept: application/vnd.github.v3+json' "${BASEURL}&per_page=${PERPAGE}&page=${i}" 2>&1` #echo $result > tempfile # get the page numer of result unset results eval "$( jq -r '@sh "results=\(.items|length)"' <<< "$tempfile" )" if [ -z "$results" ]; then echo 'Failed to parse number of results' >&2 exit 1 fi for (( l = 0; l < results; ++l )); do unset url unset path unset name eval "$( jq -r --argjson l "$l" ' .items[$l] | @sh "url=\(.repository.html_url)", @sh "path=\(.path)", @sh "repo=\(.repository.name)"' <<< "$tempfile" )" echo "url:${url}, repo:${repo}.git ${path}" git clone --depth 1 --branch develop $url $repo cd $repo BRANCH="bulk-update-${FILENAME}" git checkout -b $BRANCH cp ../$FILENAME $path -f git commit $path -m $BRANCH git push -u origin $BRANCH POST_DATA="{\"title\":\"${BRANCH}\", \"base\":\"develop\", \"head\":\"${BRANCH}\"}" echo $POST_DATA curl -H "Accept: application/vnd.github.v3+json" -u $USERNAME:$TOKEN -s "https://api.github.com/repos/${ORG}/${repo}/pulls" -d "${POST_DATA}" echo $pr cd .. done #done fi

Did you encounter a problem or do you have a suggestion?

Please contact our Service Desk



This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. https://creativecommons.org/licenses/by-sa/4.0/