Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add make step to help finding the correct stable branch #1096

Closed
wants to merge 1 commit into from

Conversation

nickvergessen
Copy link
Member

No description provided.

@nickvergessen nickvergessen self-assigned this Jan 8, 2024
@max-nextcloud
Copy link

Snippet to test if branch supports nextcloud version

git show origin/stable1:appinfo/info.xml | xmllint --xpath '//dependencies/nextcloud[@min-version<=23][23<=@max-version]' -
  <nextcloud min-version="23" max-version="24"/>
git show origin/stable1:appinfo/info.xml | xmllint --xpath '//dependencies/nextcloud[@min-version<=26][26<=@max-version]' -
  XPath set is empty

@nickvergessen
Copy link
Member Author

The problem is some apps do stableX, some stable-X some stable-A.B and it's impossible to guess/iterate in scripts over all branches, or even having to clone/download them all.

@max-nextcloud
Copy link

max-nextcloud commented Jan 8, 2024

Would this do the trick?

export REPO='nextcloud/collectives'
export VERSION=23
git clone --depth=1 https://github.com/$REPO.git
cd collectives
for branch in `git ls-remote -q --heads  | grep -o 'refs\/heads\/stable.*' | grep -o stable.* | sort -nr`
  do
  curl -s https://raw.githubusercontent.com/$REPO/$branch/appinfo/info.xml \
  | xmllint --xpath '//dependencies/nextcloud[@min-version<=$VERSION][$VERSION<=@max-version]' - \
  && echo $branch
done

@nickvergessen
Copy link
Member Author

nickvergessen commented Jan 8, 2024

Thanks for all the pointing. That contained some useful hints and I now have a universal thing that works with already locally cloned fork based on git show $REF_ID:appinfo/info.xml

#!/bin/bash
#
# Checkout the newest matching stable branch

VERSION=$1

DEFAULT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')

# Check default (main/master) branch 
git fetch -q origin $DEFAULT_BRANCH
REF_ID=$(git ls-remote -q --heads | grep "refs\/heads\/$DEFAULT_BRANCH\$" | tail | awk '{ print $1 }')

MATCHES=$(git show $REF_ID:appinfo/info.xml | xmllint --nowarning --xpath "count(/info/dependencies/nextcloud[@min-version<=$VERSION][$VERSION<=@max-version])" -)

if [ "$MATCHES" == "1" ]; then
  echo $DEFAULT_BRANCH
  exit 0
fi

# Short cut to stableX when X is the version we are looking for
MATCHES=$(git ls-remote -q --heads | grep "refs\/heads\/stable$VERSION\$" | wc -l)
if [ "$MATCHES" == "1" ]; then
  echo "stable$VERSION"
  exit 0
fi

for branch in `git ls-remote -q --heads  | grep -o 'refs\/heads\/stable.*' | grep -o stable.* | sort -nr`
do
  git fetch -q origin $branch
  REF_ID=$(git ls-remote -q --heads | grep "refs\/heads\/$branch\$" | tail | awk '{ print $1 }')

  MATCHES=$(git show $REF_ID:appinfo/info.xml | xmllint --nowarning --xpath "count(/info/dependencies/nextcloud[@min-version<=$VERSION][$VERSION<=@max-version])" -)

  if [ "$MATCHES" == "1" ]; then
    echo $branch
    exit 0
  fi

done

exit 1

@nickvergessen nickvergessen deleted the feat/noid/stable-helper branch January 15, 2024 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants