asgard 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1c25b1efcac0de2f525140327f64753c1cb7b0cf82904ea6c4e1be1114b619bf
4
+ data.tar.gz: 857e98381996d06968944ed6bafb6b35d86073523672ac6d987ce2fb85a8cc79
5
+ SHA512:
6
+ metadata.gz: 383ececde0765e801b1e84dc239895ee0d2ffe491fc6d0c0c4d3a583f0a0912f64ca8dc4a4a6469f12efcae93358302ada9aeb648b6a95ada4fe866c205306b0
7
+ data.tar.gz: 3d2ecd3d0dcc3acdaa1ecd6dd6457ce02c23b086c36f178b9aa378ec620069ae99e9ecae3d824d26f0d22fb5906a4b34bc1831a2040abf24bab81833080b470e
data/.envrc ADDED
@@ -0,0 +1 @@
1
+ export RR=`pwd`
data/.loki ADDED
@@ -0,0 +1,34 @@
1
+ # default task filename for the asgard task runner
2
+
3
+ class Tasks < Asgard::Base
4
+ var :gem_name, "asgard"
5
+ var :version, -> { Asgard::VERSION }
6
+
7
+ desc "test", "Run the test suite"
8
+ def test
9
+ sh "bundle exec rake test"
10
+ end
11
+
12
+ depends_on :test
13
+ desc "quality", "Run tests then flog"
14
+ def quality
15
+ sh "flog lib/"
16
+ end
17
+
18
+ desc "build", "Build the gem package"
19
+ def build
20
+ sh "bundle exec rake build"
21
+ end
22
+
23
+ depends_on :test
24
+ desc "install", "Build and install gem locally"
25
+ def install
26
+ sh "bundle exec rake install"
27
+ end
28
+
29
+ depends_on :quality
30
+ desc "release", "Release to RubyGems"
31
+ def release
32
+ sh "bundle exec rake release"
33
+ end
34
+ end
data/CHANGELOG.md ADDED
@@ -0,0 +1,29 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0] - 2026-05-28
11
+
12
+ ### Added
13
+
14
+ - `Asgard::Base` — Thor subclass providing the task DSL
15
+ - `depends_on` — declare recipe dependencies resolved via `SimpleFlow::DependencyGraph`; dependencies run at most once per invocation
16
+ - `var` — declare static or lazy-evaluated variables available to all recipes
17
+ - `import` — flat-merge a task module into the current class
18
+ - `dotenv` — load a `.env` file into the environment
19
+ - `sh` — run a shell command or multiline heredoc script; exits with the command's status on failure
20
+ - `shebang` — write a script body to a tempfile and execute it with a given interpreter (`:python3`, `:node`, `:ruby`, `:perl`, `:bash`, `:sh`, or any custom interpreter)
21
+ - `Asgard.find_task_files` — search current directory and ancestors for task files
22
+ - Task file resolution: `.loki` takes priority; falls back to all `*.loki` files sorted alphabetically
23
+ - `asgard` executable — finds task files, validates dependency graph, dispatches via Thor
24
+ - Circular dependency detection via `SimpleFlow::DependencyGraph` at startup
25
+ - 100% test coverage enforced via SimpleCov (95% minimum threshold)
26
+ - Quality task in `.loki` runs flog after tests
27
+
28
+ [Unreleased]: https://github.com/MadBomber/asgard/compare/v0.1.0...HEAD
29
+ [0.1.0]: https://github.com/MadBomber/asgard/releases/tag/v0.1.0
data/COMMITS.md ADDED
@@ -0,0 +1,196 @@
1
+ ---
2
+ url: https://www.conventionalcommits.org/en/v1.0.0/
3
+ title: Conventional Commits
4
+ description: A specification for adding human and machine readable meaning to commit messages
5
+ access_date: 2025-07-31T20:51:29.000Z
6
+ current_date: 2025-07-31T20:51:29.601Z
7
+ ---
8
+
9
+ # Conventional Commits
10
+
11
+ A specification for adding human and machine readable meaning to commit messages
12
+
13
+ Quick Summary Full Specification Contribute
14
+
15
+ # Conventional Commits 1.0.0
16
+
17
+ ## Summary
18
+
19
+ The Conventional Commits specification is a lightweight convention on top of commit messages. It provides an easy set of rules for creating an explicit commit history; which makes it easier to write automated tools on top of. This convention dovetails with SemVer, by describing the features, fixes, and breaking changes made in commit messages.
20
+
21
+ The commit message should be structured as follows:
22
+
23
+ ---
24
+
25
+ ```
26
+ <type>[optional scope]: <description>
27
+
28
+ [optional body]
29
+
30
+ [optional footer(s)]
31
+
32
+ ```
33
+
34
+ ---
35
+
36
+ The commit contains the following structural elements, to communicate intent to the consumers of your library:
37
+
38
+ 1. **fix:** a commit of the _type_ `fix` patches a bug in your codebase (this correlates with `PATCH` in Semantic Versioning).
39
+ 2. **feat:** a commit of the _type_ `feat` introduces a new feature to the codebase (this correlates with `MINOR` in Semantic Versioning).
40
+ 3. **BREAKING CHANGE:** a commit that has a footer `BREAKING CHANGE:`, or appends a `!` after the type/scope, introduces a breaking API change (correlating with `MAJOR` in Semantic Versioning). A BREAKING CHANGE can be part of commits of any _type_.
41
+ 4. _types_ other than `fix:` and `feat:` are allowed, for example @commitlint/config-conventional (based on the Angular convention) recommends `build:`, `chore:`,`ci:`, `docs:`, `style:`, `refactor:`, `perf:`, `test:`, and others.
42
+ 5. _footers_ other than `BREAKING CHANGE: <description>` may be provided and follow a convention similar to git trailer format.
43
+
44
+ Additional types are not mandated by the Conventional Commits specification, and have no implicit effect in Semantic Versioning (unless they include a BREAKING CHANGE). A scope may be provided to a commit’s type, to provide additional contextual information and is contained within parenthesis, e.g., `feat(parser): add ability to parse arrays`.
45
+
46
+ ## Examples
47
+
48
+ ### Commit message with description and breaking change footer
49
+
50
+ ```
51
+ feat: allow provided config object to extend other configs
52
+
53
+ BREAKING CHANGE: `extends` key in config file is now used for extending other config files
54
+
55
+ ```
56
+
57
+ ### Commit message with `!` to draw attention to breaking change
58
+
59
+ ```
60
+ feat!: send an email to the customer when a product is shipped
61
+
62
+ ```
63
+
64
+ ### Commit message with scope and `!` to draw attention to breaking change
65
+
66
+ ```
67
+ feat(api)!: send an email to the customer when a product is shipped
68
+
69
+ ```
70
+
71
+ ### Commit message with both `!` and BREAKING CHANGE footer
72
+
73
+ ```
74
+ chore!: drop support for Node 6
75
+
76
+ BREAKING CHANGE: use JavaScript features not available in Node 6.
77
+
78
+ ```
79
+
80
+ ### Commit message with no body
81
+
82
+ ```
83
+ docs: correct spelling of CHANGELOG
84
+
85
+ ```
86
+
87
+ ### Commit message with scope
88
+
89
+ ```
90
+ feat(lang): add Polish language
91
+
92
+ ```
93
+
94
+ ### Commit message with multi-paragraph body and multiple footers
95
+
96
+ ```
97
+ fix: prevent racing of requests
98
+
99
+ Introduce a request id and a reference to latest request. Dismiss
100
+ incoming responses other than from latest request.
101
+
102
+ Remove timeouts which were used to mitigate the racing issue but are
103
+ obsolete now.
104
+
105
+ Reviewed-by: Z
106
+ Refs: #123
107
+
108
+ ```
109
+
110
+ ## Specification
111
+
112
+ The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119.
113
+
114
+ 1. Commits MUST be prefixed with a type, which consists of a noun, `feat`, `fix`, etc., followed by the OPTIONAL scope, OPTIONAL `!`, and REQUIRED terminal colon and space.
115
+ 2. The type `feat` MUST be used when a commit adds a new feature to your application or library.
116
+ 3. The type `fix` MUST be used when a commit represents a bug fix for your application.
117
+ 4. A scope MAY be provided after a type. A scope MUST consist of a noun describing a section of the codebase surrounded by parenthesis, e.g., `fix(parser):`
118
+ 5. A description MUST immediately follow the colon and space after the type/scope prefix. The description is a short summary of the code changes, e.g., _fix: array parsing issue when multiple spaces were contained in string_.
119
+ 6. A longer commit body MAY be provided after the short description, providing additional contextual information about the code changes. The body MUST begin one blank line after the description.
120
+ 7. A commit body is free-form and MAY consist of any number of newline separated paragraphs.
121
+ 8. One or more footers MAY be provided one blank line after the body. Each footer MUST consist of a word token, followed by either a `:<space>` or `<space>#` separator, followed by a string value (this is inspired by the git trailer convention).
122
+ 9. A footer’s token MUST use `-` in place of whitespace characters, e.g., `Acked-by` (this helps differentiate the footer section from a multi-paragraph body). An exception is made for `BREAKING CHANGE`, which MAY also be used as a token.
123
+ 10. A footer’s value MAY contain spaces and newlines, and parsing MUST terminate when the next valid footer token/separator pair is observed.
124
+ 11. Breaking changes MUST be indicated in the type/scope prefix of a commit, or as an entry in the footer.
125
+ 12. If included as a footer, a breaking change MUST consist of the uppercase text BREAKING CHANGE, followed by a colon, space, and description, e.g.,_BREAKING CHANGE: environment variables now take precedence over config files_.
126
+ 13. If included in the type/scope prefix, breaking changes MUST be indicated by a`!` immediately before the `:`. If `!` is used, `BREAKING CHANGE:` MAY be omitted from the footer section, and the commit description SHALL be used to describe the breaking change.
127
+ 14. Types other than `feat` and `fix` MAY be used in your commit messages, e.g., _docs: update ref docs._
128
+ 15. The units of information that make up Conventional Commits MUST NOT be treated as case sensitive by implementors, with the exception of BREAKING CHANGE which MUST be uppercase.
129
+ 16. BREAKING-CHANGE MUST be synonymous with BREAKING CHANGE, when used as a token in a footer.
130
+
131
+ ## Why Use Conventional Commits
132
+
133
+ * Automatically generating CHANGELOGs.
134
+ * Automatically determining a semantic version bump (based on the types of commits landed).
135
+ * Communicating the nature of changes to teammates, the public, and other stakeholders.
136
+ * Triggering build and publish processes.
137
+ * Making it easier for people to contribute to your projects, by allowing them to explore a more structured commit history.
138
+
139
+ ## FAQ
140
+
141
+ ### How should I deal with commit messages in the initial development phase?
142
+
143
+ We recommend that you proceed as if you’ve already released the product. Typically _somebody_, even if it’s your fellow software developers, is using your software. They’ll want to know what’s fixed, what breaks etc.
144
+
145
+ ### Are the types in the commit title uppercase or lowercase?
146
+
147
+ Any casing may be used, but it’s best to be consistent.
148
+
149
+ ### What do I do if the commit conforms to more than one of the commit types?
150
+
151
+ Go back and make multiple commits whenever possible. Part of the benefit of Conventional Commits is its ability to drive us to make more organized commits and PRs.
152
+
153
+ ### Doesn’t this discourage rapid development and fast iteration?
154
+
155
+ It discourages moving fast in a disorganized way. It helps you be able to move fast long term across multiple projects with varied contributors.
156
+
157
+ ### Might Conventional Commits lead developers to limit the type of commits they make because they’ll be thinking in the types provided?
158
+
159
+ Conventional Commits encourages us to make more of certain types of commits such as fixes. Other than that, the flexibility of Conventional Commits allows your team to come up with their own types and change those types over time.
160
+
161
+ ### How does this relate to SemVer?
162
+
163
+ `fix` type commits should be translated to `PATCH` releases. `feat` type commits should be translated to `MINOR` releases. Commits with `BREAKING CHANGE` in the commits, regardless of type, should be translated to `MAJOR` releases.
164
+
165
+ ### How should I version my extensions to the Conventional Commits Specification, e.g. `@jameswomack/conventional-commit-spec`?
166
+
167
+ We recommend using SemVer to release your own extensions to this specification (and encourage you to make these extensions!)
168
+
169
+ ### What do I do if I accidentally use the wrong commit type?
170
+
171
+ #### When you used a type that’s of the spec but not the correct type, e.g. `fix` instead of `feat`
172
+
173
+ Prior to merging or releasing the mistake, we recommend using `git rebase -i` to edit the commit history. After release, the cleanup will be different according to what tools and processes you use.
174
+
175
+ #### When you used a type _not_ of the spec, e.g. `feet` instead of `feat`
176
+
177
+ In a worst case scenario, it’s not the end of the world if a commit lands that does not meet the Conventional Commits specification. It simply means that commit will be missed by tools that are based on the spec.
178
+
179
+ ### Do all my contributors need to use the Conventional Commits specification?
180
+
181
+ No! If you use a squash based workflow on Git lead maintainers can clean up the commit messages as they’re merged—adding no workload to casual committers. A common workflow for this is to have your git system automatically squash commits from a pull request and present a form for the lead maintainer to enter the proper git commit message for the merge.
182
+
183
+ ### How does Conventional Commits handle revert commits?
184
+
185
+ Reverting code can be complicated: are you reverting multiple commits? if you revert a feature, should the next release instead be a patch?
186
+
187
+ Conventional Commits does not make an explicit effort to define revert behavior. Instead we leave it to tooling authors to use the flexibility of _types_ and _footers_ to develop their logic for handling reverts.
188
+
189
+ One recommendation is to use the `revert` type, and a footer that references the commit SHAs that are being reverted:
190
+
191
+ ```
192
+ revert: let us never again speak of the noodle incident
193
+
194
+ Refs: 676104e, a215868
195
+
196
+ ```
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Dewayne VanHoozer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,260 @@
1
+ # Asgard
2
+
3
+ A [just](https://just.systems)-like task runner for Ruby. Define project recipes in a `.loki` file and run them with the `asgard` command. Built on [Thor](https://github.com/rails/thor) for argument handling and [SimpleFlow](https://github.com/madbomber/simple_flow) for dependency ordering.
4
+
5
+ The name comes from Norse mythology: **Thor** is the CLI framework, **Asgard** is the realm where tasks live, and the task file is named **loki** — because Loki holds all the tricks.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ gem install asgard
11
+ ```
12
+
13
+ Or add to your Gemfile:
14
+
15
+ ```bash
16
+ bundle add asgard
17
+ ```
18
+
19
+ ## Quick Start
20
+
21
+ Create a `.loki` file at your project root. `sh` runs any shell command — a single line or a multiline heredoc:
22
+
23
+ ```ruby
24
+ # filename: .loki
25
+
26
+ class Tasks < Asgard::Base
27
+ desc "deps", "Install project dependencies"
28
+ def deps
29
+ sh <<~SHELL
30
+ brew install redis
31
+ npm install
32
+ bundle install
33
+ SHELL
34
+ end
35
+
36
+ depends_on :deps
37
+ desc "test", "Run the test suite"
38
+ def test
39
+ sh "bundle exec rake test"
40
+ end
41
+
42
+ depends_on :test
43
+ desc "release", "Tag and publish the gem"
44
+ def release
45
+ sh <<~SHELL
46
+ git tag v$(ruby -r./lib/my_gem/version -e 'puts MyGem::VERSION')
47
+ git push --tags
48
+ bundle exec rake release
49
+ SHELL
50
+ end
51
+ end
52
+ ```
53
+
54
+ Then run tasks from any directory in the project tree:
55
+
56
+ ```bash
57
+ asgard test # runs deps, then test
58
+ asgard release # runs deps, then test, then release
59
+ asgard help # list all available tasks
60
+ ```
61
+
62
+ ## Task Files
63
+
64
+ Asgard searches the current directory and its ancestors for task files, in this order:
65
+
66
+ 1. **`.loki`** — the hidden default. Found alone, takes priority over everything.
67
+ 2. **`*.loki`** — all matching files loaded alphabetically when no `.loki` exists.
68
+
69
+ This means you can split a large task set across multiple files:
70
+
71
+ ```
72
+ deploy.loki
73
+ test.loki
74
+ build.loki # loaded as: build.loki, deploy.loki, test.loki
75
+ ```
76
+
77
+ Or use a single hidden default:
78
+
79
+ ```
80
+ .loki # takes priority, *.loki files are ignored
81
+ ```
82
+
83
+ ## Features
84
+
85
+ ### Task dependencies
86
+
87
+ ```ruby
88
+ depends_on :build
89
+ desc "test", "Run tests"
90
+ def test
91
+ sh "bundle exec rake test"
92
+ end
93
+ ```
94
+
95
+ Dependencies run before the recipe, at most once per invocation regardless of how many recipes declare them. Circular dependencies are caught at startup via `SimpleFlow::DependencyGraph`.
96
+
97
+ ### Variables
98
+
99
+ ```ruby
100
+ var :app, "myapp"
101
+ var :version, -> { `git describe --tags`.strip } # lazy, evaluated on first use
102
+
103
+ desc "tag", "Create a git tag"
104
+ def tag
105
+ sh "git tag #{version}"
106
+ end
107
+ ```
108
+
109
+ ### Multi-line shell scripts
110
+
111
+ ```ruby
112
+ desc "setup", "Bootstrap the dev environment"
113
+ def setup
114
+ sh <<~SHELL
115
+ brew install redis postgresql
116
+ brew services start redis
117
+ bundle install
118
+ rails db:setup
119
+ SHELL
120
+ end
121
+ ```
122
+
123
+ ### Embedded scripts in other languages
124
+
125
+ ```ruby
126
+ desc "analyze", "Run data analysis"
127
+ def analyze
128
+ shebang :python3, <<~PYTHON
129
+ import json
130
+ data = json.load(open("results.json"))
131
+ print(f"Total: {sum(data.values())}")
132
+ PYTHON
133
+ end
134
+
135
+ desc "bundle", "Build frontend assets"
136
+ def bundle_assets
137
+ shebang :node, <<~JS
138
+ const esbuild = require("esbuild")
139
+ esbuild.buildSync({ entryPoints: ["src/app.js"], bundle: true, outfile: "dist/app.js" })
140
+ JS
141
+ end
142
+ ```
143
+
144
+ Supported interpreters: `:python3`, `:python`, `:node`, `:ruby`, `:perl`, `:bash`, `:sh`. Any other symbol is passed directly to `system` with a `.tmp` extension.
145
+
146
+ ### Importing task modules
147
+
148
+ Split tasks into reusable modules and include them flat (all tasks in the same namespace):
149
+
150
+ ```ruby
151
+ # shared/deploy_tasks.rb
152
+ module DeployTasks
153
+ def self.included(base)
154
+ base.desc "deploy", "Deploy to production"
155
+ base.define_method(:deploy) { sh "cap production deploy" }
156
+ end
157
+ end
158
+
159
+ # .loki
160
+ require_relative "shared/deploy_tasks"
161
+
162
+ class Tasks < Asgard::Base
163
+ import DeployTasks
164
+ end
165
+ ```
166
+
167
+ For namespaced subcommands, use Thor's `register`:
168
+
169
+ ```ruby
170
+ register DeployTasks, "deploy", "deploy COMMAND", "Deployment tasks"
171
+ # invoked as: asgard deploy production
172
+ ```
173
+
174
+ ### Dotenv
175
+
176
+ ```ruby
177
+ class Tasks < Asgard::Base
178
+ dotenv # loads .env from CWD
179
+ dotenv ".env.local"
180
+
181
+ desc "check", "Print the app name"
182
+ def check
183
+ sh "echo $APP_NAME"
184
+ end
185
+ end
186
+ ```
187
+
188
+ ### Echo suppression
189
+
190
+ Pass `silent: true` to suppress the command echo (equivalent to `just`'s `@` prefix):
191
+
192
+ ```ruby
193
+ def build
194
+ sh "bundle exec rake build", silent: true # runs quietly, output still shown
195
+ end
196
+ ```
197
+
198
+ ## Shell helpers
199
+
200
+ | Method | Description |
201
+ |---|---|
202
+ | `sh(script, silent: false)` | Run a shell command or multiline script |
203
+ | `shebang(interpreter, script, silent: false)` | Write script to a tempfile and execute it |
204
+
205
+ Both exit with the command's status code on failure.
206
+
207
+ ## Full example `.loki`
208
+
209
+ ```ruby
210
+ require "asgard"
211
+
212
+ class Tasks < Asgard::Base
213
+ dotenv
214
+
215
+ var :app, "myapp"
216
+ var :version, -> { File.read("VERSION").strip }
217
+
218
+ desc "test", "Run the test suite"
219
+ def test
220
+ sh "bundle exec rake test"
221
+ end
222
+
223
+ depends_on :test
224
+ desc "quality", "Run tests then check complexity"
225
+ def quality
226
+ sh "flog lib/"
227
+ end
228
+
229
+ desc "build", "Build the gem"
230
+ def build
231
+ sh "bundle exec rake build"
232
+ end
233
+
234
+ depends_on :quality, :build
235
+ desc "release", "Release #{version} to RubyGems"
236
+ def release
237
+ sh "bundle exec rake release"
238
+ end
239
+ end
240
+ ```
241
+
242
+ ## Development
243
+
244
+ ```bash
245
+ git clone git@github.com:MadBomber/asgard.git
246
+ cd asgard
247
+ bundle install
248
+ bundle exec rake test # run tests with coverage
249
+ bundle exec bin/asgard help # try the CLI against this gem's own .loki file
250
+ ```
251
+
252
+ Coverage threshold is enforced at 95% via SimpleCov.
253
+
254
+ ## Contributing
255
+
256
+ Bug reports and pull requests are welcome at https://github.com/MadBomber/asgard.
257
+
258
+ ## License
259
+
260
+ MIT. See [LICENSE.txt](LICENSE.txt).
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ SIMPLECOV_PRELUDE = <<~RUBY.freeze
7
+ require "simplecov"
8
+ SimpleCov.start do
9
+ add_filter "/test/"
10
+ minimum_coverage 95
11
+ end
12
+ RUBY
13
+
14
+ Minitest::TestTask.create do |t|
15
+ t.test_prelude = SIMPLECOV_PRELUDE
16
+ end
17
+
18
+ task quality: :test do
19
+ sh "flog lib/"
20
+ end
21
+
22
+ task default: :test
data/bin/asgard ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "asgard"
5
+
6
+ task_files = Asgard.find_task_files
7
+
8
+ unless task_files
9
+ warn "asgard: no .loki or *.loki task file found in #{Dir.pwd} or any parent directory"
10
+ exit 1
11
+ end
12
+
13
+ task_files.each { |f| load f }
14
+
15
+ klass = Asgard::Base.subclasses.last
16
+
17
+ unless klass
18
+ warn "asgard: no class inheriting Asgard::Base found in #{task_files.join(', ')}"
19
+ exit 1
20
+ end
21
+
22
+ klass.validate_deps!
23
+ klass._reset_ran!
24
+ klass.start(ARGV)
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "asgard"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ require "irb"
11
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,156 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+ require "set"
5
+ require "simple_flow"
6
+
7
+ module Asgard
8
+ class Base < Thor
9
+ include Asgard::Shell
10
+
11
+ class << self
12
+ def subclasses
13
+ @subclasses ||= []
14
+ end
15
+
16
+ def inherited(subclass)
17
+ super
18
+ Asgard::Base.subclasses << subclass
19
+ subclass.instance_variable_set(:@_deps, {})
20
+ subclass.instance_variable_set(:@_vars, {})
21
+ subclass.instance_variable_set(:@_pending_deps, [])
22
+ subclass.instance_variable_set(:@_ran_tasks, Set.new)
23
+ subclass.instance_variable_set(:@_ran_mutex, Mutex.new)
24
+ end
25
+
26
+ def _deps
27
+ @_deps ||= {}
28
+ end
29
+
30
+ def _vars
31
+ @_vars ||= {}
32
+ end
33
+
34
+ def _ran_tasks
35
+ @_ran_tasks ||= Set.new
36
+ end
37
+
38
+ def _ran_mutex
39
+ @_ran_mutex ||= Mutex.new
40
+ end
41
+
42
+ # Reset execution tracking for a fresh asgard invocation.
43
+ def _reset_ran!
44
+ _ran_mutex.synchronize { @_ran_tasks = Set.new }
45
+ end
46
+
47
+ # Translate stages into a DependencyGraph-compatible hash.
48
+ #
49
+ # stages: [[:one], [:two, :three], [:four]]
50
+ # → { one: [], two: [:one], three: [:one], four: [:two, :three] }
51
+ def _build_dep_graph(stages)
52
+ graph = {}
53
+ stages.each_with_index do |stage, i|
54
+ prev_stage = i > 0 ? stages[i - 1] : []
55
+ stage.each { |task| graph[task] = prev_stage.dup }
56
+ end
57
+ graph
58
+ end
59
+
60
+ # Declare dependencies for the next recipe.
61
+ # Bare symbols run sequentially; arrays within the splat run in parallel.
62
+ #
63
+ # depends_on :build # sequential
64
+ # depends_on :build, :lint # both sequential
65
+ # depends_on [:build, :lint] # build and lint in parallel
66
+ # depends_on :setup, [:build, :lint], :test # setup, then build+lint, then test
67
+ def depends_on(*recipes)
68
+ @_pending_deps = recipes
69
+ end
70
+
71
+ def var(name, value = nil, &block)
72
+ value = block if block_given?
73
+ _vars[name.to_sym] = value
74
+ no_commands do
75
+ define_method(name) do
76
+ v = self.class._vars[name.to_sym]
77
+ v.respond_to?(:call) ? v.call : v
78
+ end
79
+ end
80
+ end
81
+
82
+ def import(mod)
83
+ include mod
84
+ end
85
+
86
+ def dotenv(path = ".env")
87
+ require "dotenv"
88
+ Dotenv.load(path) if File.exist?(path)
89
+ end
90
+
91
+ # Validate the full dep graph for cycles using SimpleFlow::DependencyGraph.
92
+ def validate_deps!
93
+ return if _deps.empty?
94
+
95
+ all_tasks = all_commands.keys.map(&:to_sym)
96
+ full_graph = all_tasks.each_with_object({}) do |task, hash|
97
+ hash[task] = _deps.fetch(task, []).flatten
98
+ end
99
+
100
+ SimpleFlow::DependencyGraph.new(full_graph).order
101
+ rescue TSort::Cyclic => e
102
+ raise Asgard::CircularDependencyError, e.message
103
+ end
104
+
105
+ def method_added(method_name)
106
+ pending = Array(@_pending_deps).dup
107
+ @_pending_deps = []
108
+
109
+ return super if pending.empty?
110
+ return super if method_name.to_s.start_with?("_")
111
+
112
+ # Each element is a Symbol (sequential) or Array (parallel group).
113
+ _deps[method_name.to_sym] = pending.map { |d| Array(d).map(&:to_sym) }
114
+ super
115
+ end
116
+ end
117
+
118
+ no_commands do
119
+ # Dispatch hook: resolves and runs all deps (in parallel where declared)
120
+ # before executing the target command. Thread-safe deduplication via
121
+ # the class-level _ran_tasks set ensures each recipe runs at most once.
122
+ def invoke_command(command, *args)
123
+ target = command.name.to_sym
124
+
125
+ should_run = self.class._ran_mutex.synchronize do
126
+ next false if self.class._ran_tasks.include?(target)
127
+ self.class._ran_tasks.add(target)
128
+ true
129
+ end
130
+ return unless should_run
131
+
132
+ stages = self.class._deps[target]
133
+ if stages&.any?
134
+ graph = self.class._build_dep_graph(stages)
135
+ groups = SimpleFlow::DependencyGraph.new(graph).parallel_order
136
+
137
+ groups.each do |group|
138
+ if group.size > 1
139
+ threads = group.map { |task| Thread.new { _run_dep(task) } }
140
+ threads.each(&:join)
141
+ else
142
+ _run_dep(group.first)
143
+ end
144
+ end
145
+ end
146
+
147
+ command.run(self, *args)
148
+ end
149
+
150
+ def _run_dep(task)
151
+ command = self.class.all_commands[task.to_s]
152
+ invoke_command(command) if command
153
+ end
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tempfile"
4
+
5
+ module Asgard
6
+ module Shell
7
+ # Run a shell script. Multiline strings are passed to bash -c; single-line
8
+ # strings are passed to system directly. Exits with the command's status
9
+ # code on failure.
10
+ def sh(script, silent: false)
11
+ script = script.strip
12
+ $stdout.puts script unless silent
13
+
14
+ success = if script.include?("\n")
15
+ system("bash", "-c", script)
16
+ else
17
+ system(script)
18
+ end
19
+
20
+ exit($?.exitstatus) unless success
21
+ end
22
+
23
+ # Write +script+ to a tempfile and execute it with +interpreter+.
24
+ # Useful for embedding Python, Node, Ruby, or any shebang-style body.
25
+ def shebang(interpreter, script, silent: false)
26
+ extensions = {
27
+ python3: ".py", python: ".py",
28
+ node: ".js",
29
+ ruby: ".rb",
30
+ perl: ".pl",
31
+ bash: ".sh", sh: ".sh"
32
+ }
33
+ ext = extensions.fetch(interpreter.to_sym, ".tmp")
34
+
35
+ Tempfile.create(["asgard_", ext]) do |f|
36
+ f.write(script)
37
+ f.flush
38
+ system(interpreter.to_s, f.path)
39
+ exit($?.exitstatus) unless $?.success?
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Asgard
4
+ VERSION = "0.1.0"
5
+ end
data/lib/asgard.rb ADDED
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "asgard/version"
4
+ require_relative "asgard/shell"
5
+ require_relative "asgard/base"
6
+
7
+ module Asgard
8
+ class Error < StandardError; end
9
+ class CircularDependencyError < Error; end
10
+
11
+ # Search the current directory and its ancestors for task files.
12
+ # Returns an array of paths, or nil if nothing is found.
13
+ #
14
+ # Priority:
15
+ # 1. A single .loki file in the directory (default/hidden task file)
16
+ # 2. All *.loki files in the directory, sorted alphabetically
17
+ def self.find_task_files
18
+ dir = Dir.pwd
19
+ loop do
20
+ dot_loki = File.join(dir, ".loki")
21
+ return [dot_loki] if File.exist?(dot_loki)
22
+
23
+ matches = Dir.glob(File.join(dir, "*.loki")).sort
24
+ return matches unless matches.empty?
25
+
26
+ parent = File.dirname(dir)
27
+ break if parent == dir
28
+ dir = parent
29
+ end
30
+ nil
31
+ end
32
+ end
data/sig/asgard.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Asgard
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asgard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dewayne VanHoozer
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: logger
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: thor
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: simple_flow
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.4'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.4'
54
+ - !ruby/object:Gem::Dependency
55
+ name: dotenv
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.0'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ description: 'Asgard brings just-style recipes to Ruby: Thor-powered CLI, dep ordering
69
+ via SimpleFlow::DependencyGraph, var declarations, dotenv, sh/shebang helpers, and
70
+ importable task modules.'
71
+ email:
72
+ - dewayne@vanhoozer.me
73
+ executables:
74
+ - asgard
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".envrc"
79
+ - ".loki"
80
+ - CHANGELOG.md
81
+ - COMMITS.md
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/asgard
86
+ - bin/console
87
+ - bin/setup
88
+ - lib/asgard.rb
89
+ - lib/asgard/base.rb
90
+ - lib/asgard/shell.rb
91
+ - lib/asgard/version.rb
92
+ - sig/asgard.rbs
93
+ homepage: https://github.com/madbomber/asgard
94
+ licenses:
95
+ - MIT
96
+ metadata:
97
+ homepage_uri: https://github.com/madbomber/asgard
98
+ source_code_uri: https://github.com/madbomber/asgard
99
+ changelog_uri: https://github.com/madbomber/asgard/blob/master/CHANGELOG.md
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: 3.2.0
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubygems_version: 4.0.12
115
+ specification_version: 4
116
+ summary: A just-like task runner built on Thor, with recipe dependencies via SimpleFlow.
117
+ test_files: []