Should allow to update the yaml file without manually editing

I would like snapcraft to update the yaml file without manually editing it.

My use cases include

  • Being able to bump the version number through a script
  • To update the source URL

Currently I am keeping a script like this in my projects but things could definitely be simplified if snapcraft supported that.

For nested updates, we could use dot notation like:
snapcraft update-yaml version=xx parts.android-studio.source=<my_new_source>

Setting the version of the snap is possible via version-script which would look like:

name: example
version: latest
version-script: |
  python get-latest-version-number.py

And you’d include in your repository a file called get-latest-version-number.py with similar contents as you already created in your get-latest.py.

import re
import sys
import urllib.request

URL_STUDIO_HOME = 'https://developer.android.com/studio/index.html'


def get_latest_studio_url():
    with urllib.request.urlopen(URL_STUDIO_HOME) as response:
        html = response.read().decode()

    matched = re.findall('"((https)?://.*linux.zip)"', html)
    # Ensure unique and then convert to a list of easy access.
    links = list(set(matched))

    if len(links) == 0:
        raise ValueError('Url matching our query not found.')
    elif len(links) > 1:
        raise RuntimeError('Multiple urls found, expected only one, urls are: {}'.format(
            ' '.join(links)))

    url = links[0][0]
    version = url.split('/')[-2]
    return version, url


def fetch_latest_version_details():
    version, url = get_latest_studio_url()
    sys.stdout.write(version) # snapcraft reads the version from the standard output of the version-script

if __name__ == '__main__':
    fetch_latest_version_details()

Thanks, I am aware of that and have found that to not serve my use case, check my comment here.

I can probably do a PoC python script that achieves what I talked about above, but having something inside snapcraft will make everyone’s life easier.