0

In a CI pipeline (Azure DevOPS) I would like to read the current version of a private Podspec. The content of my Podspec looks like this

Pod::Spec.new do |spec|
    spec.name                     = 'ExampleShared'
    spec.version                  = '1.0.2'
    spec.homepage                 = 'https://example.com'
    spec.source                   = { :git => 'https://dev.azure.com/example/ONE/_git/Cocoapods', :tag => '1.0.2'}
    spec.authors                  = ''
    spec.license                  = { :type => 'Commercial', :text => 'Copyright (c) ...' }
    spec.summary                  = 'Some summary'
    spec.vendored_frameworks      = 'bin/ExampleShared/1.0.2/ExampleShared.xcframework'
    spec.libraries                = 'c++'
    spec.ios.deployment_target = '12.4'
end

I tried to use Cocoapod command like pod spec cat which writes the content above to the console or just directly using the Podspec along with some grep and Regex, but I failed. Only got to the point where I captured the line where I can get the version from, but I only really need the 1.0.2 value from that line. This is my grep line

grep -o -E "spec\.version\s+=\s'([0-9\.]+)'" ExampleShared.podspec

which results in

spec.version = '1.0.2'

But as mentioned above I just need

1.0.2 as result.

How do I do that?

Kai
  • 1,277
  • 2
  • 15
  • 25
  • `\s` is not necessarily supported with `grep -E` – tripleee Sep 26 '22 at 16:10
  • Thanks @tripleee. I tried the solution provided in the other question, but the lookbehind doesn't seem to work for me, because if the whitespace quantifier before the equals sign. Multiple regex tools give me a similar error like this: *A quantifier inside a lookbehind makes it non-fixed width* That's what I tried: `(?<=spec\.version\s+=\s')[0-9\.]+(?=')` – Kai Sep 26 '22 at 19:50
  • Yeah, you need a fixed-width assertion in most tools. Python's third-party `regex` library is one which supports arbitrary lookaheads, but if you're targeting `grep -P` you will get regular PCRE (and even that is a nonstandard GNU extension). In many cases, you can just relax the lookahead slightly, or split it up into parts. – tripleee Sep 27 '22 at 04:18
  • 1
    The `sed` solution is still viable, though. `sed -En "s/spec\.version[[:space:]]+=[[:space:]]+'([0-9\.]+)'.*/\\1/p" ExampleShared` – tripleee Sep 27 '22 at 04:22
  • Thanks @tripleee , that led me to a working solution! – Kai Sep 27 '22 at 10:02

0 Answers0