openSUSE / obs-service-set_version

An OBS source service: Update spec file version
GNU General Public License v2.0
5 stars 38 forks source link

Extended set_version script to work with #!RemoteAssetUrl provided scripts. #79

Open mcepl opened 2 years ago

mcepl commented 2 years ago

The idea is that aside from setting the version, it is possible to replace the typical _service file, but there is only functionality missing:

 <service name="set_version" mode="buildtime"/>

It seems it shouldn't be that complicated to add new method of VersionDetector, which would essentially run git rev-parse --verify --short HEAD and compose the version number from that.

mcepl commented 2 years ago

Functionally I would expect something like this:

#!/bin/sh
set -eu

usage() {
echo >&2 "$(basename $0): spec-file repo-dir version-base commit-id"
exit 5
}

[ $# -eq 4 ] || usage

SPEC_FILE=$1
REPO=$2
VERSION_BASE=$3
COMMIT_ID=$4

IFS='' VERSION=$VERSION_BASE"git."$(cd $REPO ; git show -q --format=format:%ct.%h $COMMIT_ID)
# Version:        0.8.0~git.1658078013.13abe20b5
sed -i -e 's/^\(Version:[[:blank:]]\+\).*$/\1'$VERSION'/' $SPEC_FILE
dcermak commented 2 years ago

Could you elaborate a bit more what you are trying to achieve here? I am not exactly sure what you are expecting from the service.

mcepl commented 2 years ago
  1. With #!RemoteAssetUrl: we don’t have _service file anymore, and that’s fine.
  2. For the most time. We don’t have <service name="set_version" mode="buildtime"/> (we truly don’t because, if you have this one-line _service file, the script doesn’t have anywhere to get the metadata from).
  3. This is the ugly workaround which I came with, respectively I have now in the source code git repository this post-checkout hook:
    #!/bin/sh
    IFS='' VERSION="0.7+git."$(git show -q --format=format:%ct.%h sourcehut/master)
    sed -i -e 's/^\(Version:[[:blank:]]\+\).*$/\1'$VERSION'/' $(/bin/ls ../*.spec|head -n1)

    but it is an exceedingly ugly hack.