Skip to content

Commit e23327c

Browse files
authored
Merge pull request #98 from puppetlabs/malikparvez-patch-1
CAT-1918 : Adding check for version from metadata.json
2 parents 25a7fb2 + 7ab57b0 commit e23327c

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

.github/workflows/module_release.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ jobs:
1414

1515
steps:
1616

17+
- name: "Set up Ruby"
18+
uses: "actions/setup-ruby@v1"
19+
with:
20+
ruby-version: "3.1"
21+
1722
- name: "Checkout"
1823
uses: "actions/checkout@v4"
1924
with:
@@ -24,7 +29,22 @@ jobs:
2429
- name: "Get version"
2530
id: "get_version"
2631
run: |
27-
echo "version=$(jq --raw-output .version metadata.json)" >> $GITHUB_OUTPUT
32+
ruby <<-EOF >> $GITHUB_OUTPUT
33+
require "json"
34+
version = JSON.parse(File.read("metadata.json"))["version"]
35+
36+
# from https://github.com/voxpupuli/metadata-json-lint/blob/b5e68049c6be58aa63263357bb0dcad8635a6829/lib/metadata-json-lint/schema.rb#L141-L150
37+
numeric = '(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)' # Major . Minor . Patch
38+
pre = '(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?' # Prerelease
39+
build = '(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?' # Build
40+
full = numeric + pre + build
41+
semver_regex = /\A#{full}\Z/
42+
if version&.match?(semver_regex)
43+
puts "version=#{version}"
44+
else
45+
raise "Version #{version} is invalid. Exiting workflow."
46+
end
47+
EOF
2848
2949
- name: "PDK build"
3050
uses: "docker://puppet/pdk:nightly"

0 commit comments

Comments
 (0)