Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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
env:
FILENAME: test.txt
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# version-check
Checks if version is upgraded when updating the repository
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/.
25 changes: 25 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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: "package"
color: "red"
runs:
using: "composite"
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'
- run: ruby main.rb
env:
VERSION_REGEX: ${{ inputs.version-regex }}
FILENAME: ${{ inputs.filename }}
53 changes: 53 additions & 0 deletions main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/ruby

class Project

attr_reader :code_tags, :git_tags

def initialize(filename, version_regex)
# variables
@filename = filename
@version_regex = version_regex
# upon init
@code_tags = []
@git_tags = []
read_versions
get_tags
end

def read_versions()
File.open(@filename, "r") do |f|
f.each_line do |line|
@code_tags += line.scan(@version_regex)
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/"
filename = ENV["FILENAME"] || ""

if filename.empty?
raise "No filename passed as env."
end

project = Project.new(filename, eval(regex))
if not project.version_updated
raise "Version in code not updated."
end
end
10 changes: 10 additions & 0 deletions test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
something
something
something
something
version=v1.0.0
something
else


version=v1.0.1
Loading