change tag update from version to upstream

This commit is contained in:
Alexandre
2021-02-21 08:47:19 +01:00
parent 4388ca91f0
commit ab7affe797

View File

@@ -3,8 +3,8 @@
bashio::log.info "Checking status of referenced repositoriess..." bashio::log.info "Checking status of referenced repositoriess..."
VERBOSE=$(bashio::config 'verbose') VERBOSE=$(bashio::config 'verbose')
#Defining github value #Defining github value
LOGINFO="... github authentification" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi LOGINFO="... github authentification" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi
GITUSER=$(bashio::config 'gituser') GITUSER=$(bashio::config 'gituser')
GITPASS=$(bashio::config 'gitpass') GITPASS=$(bashio::config 'gitpass')
@@ -16,94 +16,92 @@ git config --system user.password ${GITPASS}
git config --system user.email ${GITMAIL} git config --system user.email ${GITMAIL}
if bashio::config.has_value 'gitapi'; then if bashio::config.has_value 'gitapi'; then
LOGINFO="... setting github API" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi LOGINFO="... setting github API" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi
export GITHUB_API_TOKEN=$(bashio::config 'gitapi') export GITHUB_API_TOKEN=$(bashio::config 'gitapi')
fi fi
LOGINFO="... parse addons" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi LOGINFO="... parse addons" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi
for addons in $(bashio::config "addon|keys"); do for addons in $(bashio::config "addon|keys"); do
SLUG=$(bashio::config "addon[${addons}].slug") SLUG=$(bashio::config "addon[${addons}].slug")
REPOSITORY=$(bashio::config "addon[${addons}].repository") REPOSITORY=$(bashio::config "addon[${addons}].repository")
UPSTREAM=$(bashio::config "addon[${addons}].upstream") UPSTREAM=$(bashio::config "addon[${addons}].upstream")
BETA=$(bashio::config "addon[${addons}].beta") BETA=$(bashio::config "addon[${addons}].beta")
FULLTAG=$(bashio::config "addon[${addons}].fulltag") FULLTAG=$(bashio::config "addon[${addons}].fulltag")
BASENAME=$(basename "https://github.com/$REPOSITORY") BASENAME=$(basename "https://github.com/$REPOSITORY")
#Create or update local version
if [ ! -d /data/$BASENAME ]; then
LOGINFO="... $SLUG : cloning ${REPOSITORY}" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi
cd /data/
git clone "https://github.com/${REPOSITORY}"
else
LOGINFO="... $SLUG : updating ${REPOSITORY}" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi
cd "/data/$BASENAME"
git pull --rebase || git reset --hard
fi
#Define the folder addon #Create or update local version
LOGINFO="... $SLUG : checking slug exists in repo" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi if [ ! -d /data/$BASENAME ]; then
cd /data/${BASENAME}/${SLUG} || bashio::log.error "$SLUG addon not found in this repository. Exiting." exit LOGINFO="... $SLUG : cloning ${REPOSITORY}" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi
cd /data/
#Find current version git clone "https://github.com/${REPOSITORY}"
LOGINFO="... $SLUG : get current version" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi else
CURRENT=$(jq .version config.json) || bashio::log.error "$SLUG addon version in config.json not found. Exiting." exit LOGINFO="... $SLUG : updating ${REPOSITORY}" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi
cd "/data/$BASENAME"
#Prepare tag flag git pull --rebase || git reset --hard
if [ ${FULLTAG} = true ]; then fi
LOGINFO="... $SLUG : fulltag is on" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi
FULLTAG="--format tag"
else
LOGINFO="... $SLUG : fulltag is off" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi
FULLTAG=""
fi
#If beta flag, select beta version #Define the folder addon
if [ ${BETA} = true ]; then LOGINFO="... $SLUG : checking slug exists in repo" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi
LOGINFO="... $SLUG : beta is on" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi cd /data/${BASENAME}/${SLUG} || bashio::log.error "$SLUG addon not found in this repository. Exiting." exit
LASTVERSION=$(lastversion --pre "https://github.com/$UPSTREAM" $FULLTAG)
else
LOGINFO="... $SLUG : beta is off" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi
LASTVERSION=$(lastversion "https://github.com/$UPSTREAM" $FULLTAG)
fi
# Take only into account first part of tag #Find current version
# CURRENT=${CURRENT:0:${#LASTVERSION}} LOGINFO="... $SLUG : get current version" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi
CURRENT=$(jq .upstream config.json) || bashio::log.error "$SLUG addon upstream tag not found in config.json. Exiting." exit
# Add brackets #Prepare tag flag
LASTVERSION='"'$LASTVERSION'"' if [ ${FULLTAG} = true ]; then
LOGINFO="... $SLUG : fulltag is on" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi
FULLTAG="--format tag"
else
LOGINFO="... $SLUG : fulltag is off" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi
FULLTAG=""
fi
# Update if needed #If beta flag, select beta version
if [ ${CURRENT} != ${LASTVERSION} ]; then if [ ${BETA} = true ]; then
LOGINFO="... $SLUG : update from $CURRENT to $LASTVERSION" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi LOGINFO="... $SLUG : beta is on" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi
LASTVERSION=$(lastversion --pre "https://github.com/$UPSTREAM" $FULLTAG)
#Change all instances of version else
LOGINFO="... $SLUG : updating files" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi LOGINFO="... $SLUG : beta is off" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi
files=$(grep -rl ${CURRENT} /data/${BASENAME}/${SLUG}) && echo $files | xargs sed -i "s/${CURRENT}/${LASTVERSION}/g" LASTVERSION=$(lastversion "https://github.com/$UPSTREAM" $FULLTAG)
fi
#Update changelog
touch /data/${BASENAME}/${SLUG}/CHANGELOG.md # Add brackets
sed -i "1i\- Update to latest version from $UPSTREAM" /data/${BASENAME}/${SLUG}/CHANGELOG.md LASTVERSION='"'$LASTVERSION'"'
sed -i "1i\## ${LASTVERSION:1:-1}" /data/${BASENAME}/${SLUG}/CHANGELOG.md
sed -i "1i\ " /data/${BASENAME}/${SLUG}/CHANGELOG.md # Update if needed
if [ ${CURRENT} != ${LASTVERSION} ]; then
if [ $files != null ]; then LOGINFO="... $SLUG : update from $CURRENT to $LASTVERSION" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi
#Change all instances of version
LOGINFO="... $SLUG : updating files" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi
files=$(grep -rl ${CURRENT} /data/${BASENAME}/${SLUG}) && echo $files | xargs sed -i "s/${CURRENT}/${LASTVERSION}/g" # change all tags in all addon files
jq --arg LASTVERSION "$LASTVERSION" '.upstream = $LASTVERSION' /data/${BASENAME}/${SLUG}/config.json # Correct config upstream
#Update changelog
touch /data/${BASENAME}/${SLUG}/CHANGELOG.md
sed -i "1i\- Update to latest version from $UPSTREAM" /data/${BASENAME}/${SLUG}/CHANGELOG.md
sed -i "1i\## ${LASTVERSION:1:-1}" /data/${BASENAME}/${SLUG}/CHANGELOG.md
sed -i "1i\ " /data/${BASENAME}/${SLUG}/CHANGELOG.md
if [ $files != null ]; then
git commit -m "Update to $LASTVERSION" $files || true git commit -m "Update to $LASTVERSION" $files || true
git commit -m "Update to $LASTVERSION" /data/${BASENAME}/${SLUG}/CHANGELOG.md || true git commit -m "Update to $LASTVERSION" /data/${BASENAME}/${SLUG}/CHANGELOG.md || true
#Git commit and push #Git commit and push
LOGINFO="... $SLUG : push to github" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi LOGINFO="... $SLUG : push to github" && if [ $VERBOSE = true ]; then bashio::log.info $LOGINFO; fi
git remote set-url origin "https://${GITUSER}:${GITPASS}@github.com/${REPOSITORY}" | echo git remote set-url origin "https://${GITUSER}:${GITPASS}@github.com/${REPOSITORY}" | echo
git push | echo "No changes" git push | echo "No changes"
#Log #Log
bashio::log.info "$SLUG updated to $LASTVERSION" bashio::log.info "$SLUG updated to $LASTVERSION"
else else
bashio::log.error "... $SLUG : update failed" bashio::log.error "... $SLUG : update failed"
fi fi
else else
bashio::log.info "Addon $SLUG is already up-to-date" bashio::log.info "Addon $SLUG is already up-to-date"
fi fi
done done