Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Finally use crystal for the json nize tool. Not nodejs, ruby, python,…
Browse files Browse the repository at this point in the history
… golang, jq...
  • Loading branch information
kachick committed Oct 20, 2022
1 parent 89362f5 commit 939e594
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 87 deletions.
29 changes: 0 additions & 29 deletions .eslintrc.yml

This file was deleted.

22 changes: 22 additions & 0 deletions .github/workflows/crystal.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI - Crystal
on:
push:
branches: [main]
paths:
- '.github/crystal.yml'
- '**/*.cr'
pull_request:
paths:
- '.github/crystal.yml'
- '**/*.cr'
workflow_dispatch:

jobs:
crystal:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
- uses: crystal-lang/install-crystal@v1
- run: crystal tool format --check
- run: crystal spec
2 changes: 2 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
branches: [main]
paths-ignore:
- '.github/dependabot.yml'
- '.github/workflows/crystal.yml'
- '.github/workflows/dprint.yml'
- '.github/workflows/dependency-review.yml'
- '.github/workflows/auto-merge-dependabot-prs.yml'
Expand All @@ -14,6 +15,7 @@ on:
pull_request:
paths-ignore:
- '.github/dependabot.yml'
- '.github/workflows/crystal.yml'
- '.github/workflows/dprint.yml'
- '.github/workflows/dependency-review.yml'
- '.github/workflows/auto-merge-dependabot-prs.yml'
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shellcheck 0.8.0 0.7.2
nodejs 18.11.0 16.17.1 # This entry exists for test
shfmt 3.5.1
bun 0.2.1
crystal 1.6.0
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"recommendations": [
"redhat.vscode-yaml",
"editorconfig.editorconfig",
"dprint.dprint"
"dprint.dprint",
"crystal-lang-tools.crystal-lang"
]
}
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"cSpell.words": [
"antongolub",
"dprint",
"jsonize",
"jsonizer",
"shfmt"
],
Expand Down
13 changes: 11 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@ runs:
- uses: asdf-vm/actions/setup@v1
- run: |
(source "$ASDF_DIR/lib/utils.bash"; strip_tool_version_comments .tool-versions) |
ruby -r json -e 'print(STDIN.each_line.to_h {|line| line.split.slice(0, 2) }.to_json)' |
grep -P '^crystal' | awk '{print "crystal=" $2}' |
tee --append $GITHUB_OUTPUT
shell: bash
id: prepare-runner
- uses: crystal-lang/install-crystal@v1
with:
crystal: ${{ steps.prepare-runner.outputs.crystal }}
- run: |
(source "$ASDF_DIR/lib/utils.bash"; strip_tool_version_comments .tool-versions) |
crystal run src/main.cr -- jsonize |
echo "json=$(</dev/stdin)" | tee --append $GITHUB_OUTPUT
shell: bash
id: parser
outputs:
tool-versions:
description: 'Stringified JSON that includes parsed .tool-versions'
description: 'Stringified JSON for parsed .tool-versions'
value: '${{ steps.parser.outputs.json }}'
Binary file removed bun.lockb
Binary file not shown.
26 changes: 0 additions & 26 deletions jsonizer.ts

This file was deleted.

15 changes: 0 additions & 15 deletions package.json

This file was deleted.

23 changes: 23 additions & 0 deletions spec/jsonizer_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require "./spec_helper"

require "../src/jsonizer"

require "json"

describe Jsonizer do
describe ".run" do
it "outputs usage" do
io = IO::Memory.new(
<<-TEXT
shellcheck 0.8.0 0.7.2
nodejs 18.11.0 16.17.1
shfmt 3.5.1
crystal 1.6.0
TEXT
)
Jsonizer::ParsedJson.from_json(Jsonizer.run(io)).should eq(
{"shellcheck" => "0.8.0", "nodejs" => "18.11.0", "shfmt" => "3.5.1", "crystal" => "1.6.0"}
)
end
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "spec"
11 changes: 11 additions & 0 deletions src/jsonizer.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require "json"

module Jsonizer
alias PluginName = String
alias PluginVersion = String
alias ParsedJson = Hash(PluginName, PluginVersion)

def self.run(io : IO) : String
io.each_line.to_h { |line| Tuple(String, String).from(line.split[0, 2]) }.to_json
end
end
5 changes: 5 additions & 0 deletions src/main.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require "./jsonizer"

if ARGV.first == "jsonize"
print Jsonizer.run(STDIN)
end
13 changes: 0 additions & 13 deletions tsconfig.json

This file was deleted.

0 comments on commit 939e594

Please sign in to comment.