updater.sh 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. version=$(curl --silent "https://api.github.com/repos/$repo/tags?page=5" | jq -r '.[] | select( .name | contains("rc") or contains("beta") or contains("alpha") or startswith("6") | not ) | .name' | sort -V | tail -1)
  17. # Later down the script, we assume the version has only digits and dots
  18. # Sometimes the release name starts with a "v", so let's filter it out.
  19. # You may need more tweaks here if the upstream repository has different naming conventions.
  20. if [[ ${version:0:1} == "v" || ${version:0:1} == "V" ]]; then
  21. version=${version:1}
  22. fi
  23. # Setting up the environment variables
  24. echo "Current version: $current_version"
  25. echo "Latest release from upstream: $version"
  26. echo "VERSION=$version" >> $GITHUB_ENV
  27. echo "REPO=$repo" >> $GITHUB_ENV
  28. # For the time being, let's assume the script will fail
  29. echo "PROCEED=false" >> $GITHUB_ENV
  30. # Proceed only if the retrieved version is greater than the current one
  31. if ! dpkg --compare-versions "$current_version" "lt" "$version" ; then
  32. echo "::warning ::No new version available"
  33. exit 0
  34. # Proceed only if a PR for this new version does not already exist
  35. elif git ls-remote -q --exit-code --heads https://github.com/$GITHUB_REPOSITORY.git ci-auto-update-v$version ; then
  36. echo "::warning ::A branch already exists for this update"
  37. exit 0
  38. fi
  39. #=================================================
  40. # SPECIFIC UPDATE STEPS
  41. #=================================================
  42. # Any action on the app's source code can be done.
  43. # The GitHub Action workflow takes care of committing all changes after this script ends.
  44. #=================================================
  45. # GENERIC FINALIZATION
  46. #=================================================
  47. # Replace new version in manifest
  48. echo "$(jq -s --indent 4 ".[] | .version = \"$version~ynh1\"" manifest.json)" > manifest.json
  49. # No need to update the README, yunohost-bot takes care of it
  50. # The Action will proceed only if the PROCEED environment variable is set to true
  51. echo "PROCEED=true" >> $GITHUB_ENV
  52. exit 0