From 2dc01c3a2b26bac881b4859a3cb3cf03b6c9c10f Mon Sep 17 00:00:00 2001 From: TimoKats Date: Wed, 25 Dec 2024 13:39:13 +0100 Subject: [PATCH 1/9] basic version --- .github/workflows/test.yml | 17 ++++++++++++ README.md | 3 +- main.rb | 57 ++++++++++++++++++++++++++++++++++++++ test.txt | 10 +++++++ 4 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test.yml create mode 100644 main.rb create mode 100644 test.txt diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..d37a445 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,17 @@ +name: Tests + +on: + pull_request: + types: [opened, reopened, synchronize] + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.3' + - run: ruby main.rb diff --git a/README.md b/README.md index 6e7b125..bdae84d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # version-check -Checks if version is upgraded when updating the repository +Checks if version is upgraded when updating the repository. Pass regex string as env +and filenames as parameters. diff --git a/main.rb b/main.rb new file mode 100644 index 0000000..f8340b4 --- /dev/null +++ b/main.rb @@ -0,0 +1,57 @@ +#!/usr/bin/ruby + +class Project + + attr_reader :code_tags, :git_tags + + def initialize(files, version_regex) + # variables + @files = files + @version_regex = version_regex + # upon init + @code_tags = [] + @git_tags = [] + read_versions + get_tags + end + + def read_versions() + for file in @files do + begin + File.open(file, "r") do |f| + f.each_line do |line| + @code_tags += line.scan(@version_regex) + end + end + rescue Errno::ENOENT + puts "File not found: #{file}" + end + end + end + + def get_tags() + @git_tags = Dir.entries(".git/refs/tags/").select{ |i| i[@version_regex] } + end + + def version_updated() + for code_tag in @code_tags do + if not @git_tags.include? code_tag + return true + end + end + return false + end + +end + +begin + regex = ENV['VERSION_REGEX'] || "/[v]\d.\d.\d/" + puts "Using regex: " + regex + if ARGV.size == 0 + raise "No filenames passed as params." + end + project = Project.new(ARGV, eval(regex)) + if not project.version_updated + raise "Version in code not updated." + end +end \ No newline at end of file diff --git a/test.txt b/test.txt new file mode 100644 index 0000000..5b213d6 --- /dev/null +++ b/test.txt @@ -0,0 +1,10 @@ +something +something +something +something +version=v1.0.0 +something +else + + +version=v1.0.1 From f081698b81eec26135c699380de5629e299ada9e Mon Sep 17 00:00:00 2001 From: TimoKats Date: Wed, 25 Dec 2024 13:41:52 +0100 Subject: [PATCH 2/9] add params to workflow --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d37a445..fa80e1c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,4 +14,4 @@ jobs: - uses: ruby/setup-ruby@v1 with: ruby-version: '3.3' - - run: ruby main.rb + - run: ruby main.rb test.txt test1.txt From 214c0077c3974af1b1d9ddfe37438e97a8054d96 Mon Sep 17 00:00:00 2001 From: TimoKats Date: Wed, 25 Dec 2024 13:46:16 +0100 Subject: [PATCH 3/9] small gixes --- main.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.rb b/main.rb index f8340b4..8d0fad4 100644 --- a/main.rb +++ b/main.rb @@ -45,7 +45,7 @@ def version_updated() end begin - regex = ENV['VERSION_REGEX'] || "/[v]\d.\d.\d/" + regex = ENV["VERSION_REGEX"] || "/[v]\\d.\\d.\\d/" puts "Using regex: " + regex if ARGV.size == 0 raise "No filenames passed as params." From 7b02616acd9ebb361b6d27bef73a9967bb7f27a4 Mon Sep 17 00:00:00 2001 From: TimoKats Date: Wed, 25 Dec 2024 18:45:36 +0100 Subject: [PATCH 4/9] some changes --- .github/workflows/test.yml | 5 +++-- action.yml | 24 ++++++++++++++++++++++++ main.rb | 26 +++++++++++--------------- 3 files changed, 38 insertions(+), 17 deletions(-) create mode 100644 action.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fa80e1c..649972c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,8 +10,9 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: ruby-version: '3.3' - - run: ruby main.rb test.txt test1.txt + - run: ruby main.rb + env: + FILENAME: test.txt diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..bbb111e --- /dev/null +++ b/action.yml @@ -0,0 +1,24 @@ +name: "version-checker" +description: "Checks if you updated the version in your code." +inputs: + filename: + description: "Filename that contains the version." + required: true + version-regex: + description: "Ruby regex of the versions (e.g. /[v]\d.\d for v1.0)" + required: false + default: "/[v]\\d.\\d.\\d/" + +branding: + icon: "alert-octagon" + color: "red" +runs: + using: "composite" + steps: + - uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.3' + - run: ruby main.rb + env: + VERSION_REGEX: ${{ inputs.version-regex }} + FILENAME: ${{ inputs.filename}} diff --git a/main.rb b/main.rb index 8d0fad4..66b5b18 100644 --- a/main.rb +++ b/main.rb @@ -4,9 +4,9 @@ class Project attr_reader :code_tags, :git_tags - def initialize(files, version_regex) + def initialize(filename, version_regex) # variables - @files = files + @filename = filename @version_regex = version_regex # upon init @code_tags = [] @@ -16,15 +16,9 @@ def initialize(files, version_regex) end def read_versions() - for file in @files do - begin - File.open(file, "r") do |f| - f.each_line do |line| - @code_tags += line.scan(@version_regex) - end - end - rescue Errno::ENOENT - puts "File not found: #{file}" + File.open(@filename, "r") do |f| + f.each_line do |line| + @code_tags += line.scan(@version_regex) end end end @@ -46,11 +40,13 @@ def version_updated() begin regex = ENV["VERSION_REGEX"] || "/[v]\\d.\\d.\\d/" - puts "Using regex: " + regex - if ARGV.size == 0 - raise "No filenames passed as params." + filename = ENV["FILENAME"] || "" + + if filename.empty? + raise "No filename passed as params." end - project = Project.new(ARGV, eval(regex)) + + project = Project.new(filename, eval(regex)) if not project.version_updated raise "Version in code not updated." end From 6d9eb6e7603ba8d76db791fe1a32723d7a2177f8 Mon Sep 17 00:00:00 2001 From: TimoKats Date: Wed, 25 Dec 2024 18:53:21 +0100 Subject: [PATCH 5/9] some test --- .github/workflows/test.yml | 2 -- main.rb | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 649972c..a90bf5a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,5 +14,3 @@ jobs: with: ruby-version: '3.3' - run: ruby main.rb - env: - FILENAME: test.txt diff --git a/main.rb b/main.rb index 66b5b18..c9db91e 100644 --- a/main.rb +++ b/main.rb @@ -43,7 +43,7 @@ def version_updated() filename = ENV["FILENAME"] || "" if filename.empty? - raise "No filename passed as params." + raise "No filename passed as env." end project = Project.new(filename, eval(regex)) From ac1ff949b2452f22c86580a2e074ec5dde23b00d Mon Sep 17 00:00:00 2001 From: TimoKats Date: Wed, 25 Dec 2024 18:54:50 +0100 Subject: [PATCH 6/9] added checks --- .github/workflows/test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a90bf5a..950fe51 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,4 +13,7 @@ jobs: - uses: ruby/setup-ruby@v1 with: ruby-version: '3.3' - - run: ruby main.rb + - run: | + ls + pwd + ruby main.rb From 53ff8265f6fa7133a79ca5fa5d86cdcb5ea37494 Mon Sep 17 00:00:00 2001 From: TimoKats Date: Wed, 25 Dec 2024 18:55:33 +0100 Subject: [PATCH 7/9] added checks --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 950fe51..d617f6e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,6 +10,7 @@ jobs: test: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: ruby-version: '3.3' From 183b07db6d612f2c09e5539a9ac1199202037a42 Mon Sep 17 00:00:00 2001 From: TimoKats Date: Wed, 25 Dec 2024 18:57:16 +0100 Subject: [PATCH 8/9] added envs --- .github/workflows/test.yml | 7 +++---- action.yml | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d617f6e..ffe3662 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,6 @@ jobs: - uses: ruby/setup-ruby@v1 with: ruby-version: '3.3' - - run: | - ls - pwd - ruby main.rb + - run: ruby main.rb + env: + FILENAME: test.txt diff --git a/action.yml b/action.yml index bbb111e..62c8507 100644 --- a/action.yml +++ b/action.yml @@ -21,4 +21,4 @@ runs: - run: ruby main.rb env: VERSION_REGEX: ${{ inputs.version-regex }} - FILENAME: ${{ inputs.filename}} + FILENAME: ${{ inputs.filename }} From 77e7ce929d18a0593f776d9954e7dabfba84d675 Mon Sep 17 00:00:00 2001 From: TimoKats Date: Thu, 26 Dec 2024 14:09:16 +0100 Subject: [PATCH 9/9] update readme --- README.md | 7 +++++-- action.yml | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bdae84d..77394ad 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # version-check -Checks if version is upgraded when updating the repository. Pass regex string as env -and filenames as parameters. +Checks if version is upgraded when updating the repository. Pass regex for version strings and a filename to test if it has been updated. + +## Set version format regex + +I use ruby regex (rubular) for the version strings. The default value is `/[v]\d.\d.\d/` (which means e.g. v1.0.0). You can test your own formats at: https://rubular.com/. diff --git a/action.yml b/action.yml index 62c8507..6ec865a 100644 --- a/action.yml +++ b/action.yml @@ -7,14 +7,15 @@ inputs: version-regex: description: "Ruby regex of the versions (e.g. /[v]\d.\d for v1.0)" required: false - default: "/[v]\\d.\\d.\\d/" + default: "/[v]\d.\d.\d/" branding: - icon: "alert-octagon" + icon: "package" color: "red" runs: using: "composite" steps: + - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: ruby-version: '3.3'