updater.sh 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/bash
  2. #=================================================
  3. # PACKAGE UPDATING HELPER
  4. #=================================================
  5. # This script is meant to be run by GitHub Actions
  6. # The YunoHost-Apps organisation offers a template Action to run this script periodically
  7. # Since each app is different, maintainers can adapt its contents so as to perform
  8. # automatic actions when a new upstream release is detected.
  9. #=================================================
  10. # FETCHING LATEST RELEASE AND ITS ASSETS
  11. #=================================================
  12. # Fetching information
  13. current_version=$(cat manifest.json | jq -j '.version|split("~")[0]')
  14. repo=$(cat manifest.json | jq -j '.upstream.code|split("https://github.com/")[1]')
  15. # Some jq magic is needed, because the latest upstream release is not always the latest version (e.g. security patches for older versions)
  16. i=1
  17. version=$(curl --silent "https://api.github.com/repos/$repo/tags?page=$i" | jq -r '.[] | select( .name | contains("rc") or contains("beta") or contains("alpha") or startswith("6") or startswith("7") | not ) | .name' | sort -V | tail -1)
  18. while [ -z $version ] ; do
  19. sleep 10
  20. i=$(($i + 1))
  21. version=$(curl --silent "https://api.github.com/repos/$repo/tags?page=$i" | jq -r '.[] | select( .name | contains("rc") or contains("beta") or contains("alpha") or startswith("6") or startswith("7") | not ) | .name' | sort -V | tail -1)
  22. done
  23. # Later down the script, we assume the version has only digits and dots
  24. # Sometimes the release name starts with a "v", so let's filter it out.
  25. # You may need more tweaks here if the upstream repository has different naming conventions.
  26. if [[ ${version:0:1} == "v" || ${version:0:1} == "V" ]]; then
  27. version=${version:1}
  28. fi
  29. # Setting up the environment variables
  30. echo "Current version: $current_version"
  31. echo "Latest release from upstream: $version"
  32. echo "VERSION=$version" >> $GITHUB_ENV
  33. echo "REPO=$repo" >> $GITHUB_ENV
  34. # For the time being, let's assume the script will fail
  35. echo "PROCEED=false" >> $GITHUB_ENV
  36. # Proceed only if the retrieved version is greater than the current one
  37. if ! dpkg --compare-versions "$current_version" "lt" "$version" ; then
  38. echo "::warning ::No new version available"
  39. exit 0
  40. # Proceed only if a PR for this new version does not already exist
  41. elif git ls-remote -q --exit-code --heads https://github.com/$GITHUB_REPOSITORY.git ci-auto-update-v$version ; then
  42. echo "::warning ::A branch already exists for this update"
  43. exit 0
  44. fi
  45. #=================================================
  46. # SPECIFIC UPDATE STEPS
  47. #=================================================
  48. # Any action on the app's source code can be done.
  49. # The GitHub Action workflow takes care of committing all changes after this script ends.
  50. #=================================================
  51. # GENERIC FINALIZATION
  52. #=================================================
  53. # Replace new version in manifest
  54. echo "$(jq -s --indent 4 ".[] | .version = \"$version~ynh1\"" manifest.json)" > manifest.json
  55. # No need to update the README, yunohost-bot takes care of it
  56. # The Action will proceed only if the PROCEED environment variable is set to true
  57. echo "PROCEED=true" >> $GITHUB_ENV
  58. exit 0