From 1831beaa309f9d133d53879d085088d46c6eba84 Mon Sep 17 00:00:00 2001 From: "Jade D. Kharats" Date: Thu, 8 Oct 2020 22:32:16 +0200 Subject: [PATCH 1/7] bump crystal version to 0.35.1 and fix build --- shard.yml | 4 ++-- src/guardian/watcher.cr | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/shard.yml b/shard.yml index 621136f..5549d8e 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: guardian -version: 0.0.5 +version: 0.0.6 authors: - Fatih Kadir Akın @@ -9,6 +9,6 @@ targets: guardian: main: src/guardian.cr -crystal: 0.33.0 +crystal: 0.35.1 license: MIT diff --git a/src/guardian/watcher.cr b/src/guardian/watcher.cr index a41a434..3300fc6 100644 --- a/src/guardian/watcher.cr +++ b/src/guardian/watcher.cr @@ -4,12 +4,14 @@ require "file" module Guardian class WatcherYML - YAML.mapping({ - files: String, - run: String, - }) + include YAML::Serializable + + property files : String + property run : String end + + class Watcher setter files From 6d3372f2566b4e3e74b898063d3501eb005e3bc1 Mon Sep 17 00:00:00 2001 From: Jade Kharats Date: Thu, 8 Oct 2020 22:41:45 +0200 Subject: [PATCH 2/7] Add CI with Github Action --- .github/workflows/crystal.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/crystal.yml diff --git a/.github/workflows/crystal.yml b/.github/workflows/crystal.yml new file mode 100644 index 0000000..8c616bb --- /dev/null +++ b/.github/workflows/crystal.yml @@ -0,0 +1,22 @@ +name: Crystal CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + container: + image: crystallang/crystal + + steps: + - uses: actions/checkout@v2 + - name: Install dependencies + run: shards install + - name: Run tests + run: crystal build src/guardian.cr From 594b0a06c2731c62648d4599e0c015c88a280e48 Mon Sep 17 00:00:00 2001 From: "Jade D. Kharats" Date: Thu, 8 Oct 2020 22:44:18 +0200 Subject: [PATCH 3/7] rename step build --- .github/workflows/crystal.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/crystal.yml b/.github/workflows/crystal.yml index 8c616bb..dd3d90a 100644 --- a/.github/workflows/crystal.yml +++ b/.github/workflows/crystal.yml @@ -18,5 +18,5 @@ jobs: - uses: actions/checkout@v2 - name: Install dependencies run: shards install - - name: Run tests + - name: Run build run: crystal build src/guardian.cr From 4de013303109c9042e595c52cbf46c5cd1cd255d Mon Sep 17 00:00:00 2001 From: "Jade D. Kharats" Date: Thu, 8 Oct 2020 22:49:22 +0200 Subject: [PATCH 4/7] add schedule build --- .github/workflows/crystal.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/crystal.yml b/.github/workflows/crystal.yml index dd3d90a..d9a19b3 100644 --- a/.github/workflows/crystal.yml +++ b/.github/workflows/crystal.yml @@ -5,6 +5,8 @@ on: branches: [ master ] pull_request: branches: [ master ] + schedule: + - cron: '0 5 * * 0' jobs: build: From 2828f12d616ae42470cd19c70f78cf2a887778cc Mon Sep 17 00:00:00 2001 From: "Jade D. Kharats" Date: Tue, 5 Dec 2023 13:40:57 +0100 Subject: [PATCH 5/7] fix format --- src/guardian/watcher.cr | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/guardian/watcher.cr b/src/guardian/watcher.cr index 99df2e7..d495cac 100644 --- a/src/guardian/watcher.cr +++ b/src/guardian/watcher.cr @@ -10,8 +10,6 @@ module Guardian property run : String end - - class Watcher setter files From e26571b1604e8d8e6053d36c15ddf21052def482 Mon Sep 17 00:00:00 2001 From: "Jade D. Kharats" Date: Tue, 5 Dec 2023 13:44:23 +0100 Subject: [PATCH 6/7] fix ameba style --- src/guardian/watcher.cr | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/guardian/watcher.cr b/src/guardian/watcher.cr index d495cac..2c272ce 100644 --- a/src/guardian/watcher.cr +++ b/src/guardian/watcher.cr @@ -38,7 +38,7 @@ module Guardian if @ignore_executables return !File.executable? file end - return true + true end def start_watching @@ -52,7 +52,7 @@ module Guardian end def file_creation_date(file : String) - stat = File.info(file).modification_time + File.info(file).modification_time end def collect_files @@ -66,10 +66,10 @@ module Guardian @files << file @timestamps[file] = file_creation_date(file) - unless @runners.has_key? file - @runners[file] = [watcher.run] - else + if @runners.has_key? file @runners[file] << watcher.run + else + @runners[file] = [watcher.run] end end end From 71663f6c00bbd852edd7a443028f98c13520db39 Mon Sep 17 00:00:00 2001 From: "Jade D. Kharats" Date: Tue, 5 Dec 2023 14:07:17 +0100 Subject: [PATCH 7/7] added choice of guardian file location --- src/guardian/watcher.cr | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/guardian/watcher.cr b/src/guardian/watcher.cr index 2c272ce..c8206de 100644 --- a/src/guardian/watcher.cr +++ b/src/guardian/watcher.cr @@ -12,28 +12,38 @@ module Guardian class Watcher setter files + LOCAL_FILE = "./guardian.yml" + HOME_FILE = "#{Path.home}/guardian.yml" + ENV_FILE = "GUARDIAN_FILE" def initialize(@ignore_executables = true, @clear_on_action = false) - file = "./guardian.yml" + file = guardian_file @files = [] of String @runners = {} of String => Array(String) @timestamps = {} of String => Time @watchers = [] of WatcherYML - if File.exists?(file) || File.exists?(file = file.insert(2, '.')) + if file.nil? + puts "Guardian file not found. you can create local file with `guardian -i`" + exit 1 + else + puts "Guardian file found : #{file}" YAML.parse_all(File.read(file)).each do |yaml| @watchers << WatcherYML.from_yaml(yaml.to_yaml) end - else - puts "#{"guardian.yml".colorize(:red)} does not exist!" - exit 1 end collect_files start_watching end + def guardian_file + return LOCAL_FILE if File.exists?(LOCAL_FILE) + return ENV[ENV_FILE] if ENV[ENV_FILE]? && File.exists?(ENV[ENV_FILE]) + return HOME_FILE if File.exists?(HOME_FILE) + end + def watch_file?(file) if @ignore_executables return !File.executable? file