Skip to content

Commit 7ab57b0

Browse files
committed
Adding check for version from metadata.json. This implementation involves retrieving the version information from the metadata.json file and validating it to contain only numeric characters. This enhancement aims to improve the reliability and consistency of the release workflow by preventing the inclusion of invalid or malformed version identifiers.
Also regex is considered from https://github.com/voxpupuli/metadata-json-lint/blob/b5e68049c6be58aa63263357bb0dcad8635a6829/lib/metadata-json-lint/schema.rb#L141-L150
1 parent 25a7fb2 commit 7ab57b0

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)