aequitas / concourse-ftp-resource

Concourse resource to interact with FTP servers.
https://hub.docker.com/r/aequitas/ftp-resource/
MIT License
3 stars 6 forks source link

Allow or ignore "0.91.112.0.0" version #10

Closed drnic closed 5 years ago

drnic commented 5 years ago

I am trying this resource for ftp://ftp.freetds.org/pub/freetds/stable/ and check/ftp.py is failing on file ftp://ftp.freetds.org/pub/freetds/stable/freetds-0.91.112.0.0.tar.gz because its version 0.91.112.0.0.

My resource is:

  - name: freetsd
    type: ftp
    source:
      uri: ftp://ftp.freetds.org/pub/freetds/stable/
      regex: (?P<file>freetds-(?P<version>.*).tar.gz)

The error is:

resource script '/opt/resource/check []' failed: exit status 1

stderr:
connecting to ftp server
logging in
changing to directory /pub/freetds/stable/
Traceback (most recent call last):
  File "/opt/resource/check", line 242, in <module>
    print(FTPResource().run(os.path.basename(__file__), sys.stdin.read(), sys.argv[1:]))
  File "/opt/resource/check", line 73, in run
    output = self.cmd_check(version=data.get('version', {}))
  File "/opt/resource/check", line 124, in cmd_check
    versions = self._versions_to_output(self._matching_versions(self.listdir()))
  File "/opt/resource/check", line 217, in _versions_to_output
    versions.sort(key=lambda x: semver.parse_version_info(x[self.version_key]))
  File "/opt/resource/check", line 217, in <lambda>
    versions.sort(key=lambda x: semver.parse_version_info(x[self.version_key]))
  File "/usr/local/lib/python3.6/site-packages/semver.py", line 131, in parse_version_info
    parts = parse(version)
  File "/usr/local/lib/python3.6/site-packages/semver.py", line 52, in parse
    raise ValueError('%s is not valid SemVer string' % version)
ValueError: 0.91.112.0.0 is not valid SemVer string

Could we support this or ignore it? (in my particular case, we don't need this old 0.91.112.0.0, since latest is 1.1.6)

aequitas commented 5 years ago

I think best would be to add an option to allow ignoring invalid version. I'll get back on this.

aequitas commented 5 years ago

I was working on solving this, but instead of introducing this as a new feature I suggest adjusting the version regex to match only valid semver versions, eg:

      regex: (?P<file>freetds-(?P<version>[0-9]+\.[0-9]+\.[0-9]+).tar.gz)
drnic commented 5 years ago

My workaround regex is:

regex: (?P<file>freetds-(?P<version>[1-9][0-9]*\.[1-9][0-9]*\.[0-9]+).*.tar.gz)

The .*.tar.gz allows for the known .0.0.tar.gz one-time edge case.

From https://github.com/starkandwayne/freetds-buildpack/blob/52b07cb1cd4546cc7f1171ba1b799cc2549ad5db/ci/pipeline.yml#L164-L169

aequitas commented 5 years ago

The work I've done so far is this: https://github.com/aequitas/concourse-ftp-resource/compare/wip_ignore_versions?expand=1 but I don't intend to develop it further as I have not touched this code in a while and don't feel like introducing new bugs or exploring all the test edge cases. Feel free to incorporate the code in a build of your own. I'm gonna close the issue now since a workaround is available.