Skip to content

Commit

Permalink
use glint 1.0.0-rc2
Browse files Browse the repository at this point in the history
  • Loading branch information
TanklesXL committed May 16, 2024
1 parent e179a92 commit bbe05b7
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 178 deletions.
34 changes: 0 additions & 34 deletions .github/actions/test/action.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions .github/workflows/main.yml

This file was deleted.

26 changes: 0 additions & 26 deletions .github/workflows/release.yaml

This file was deleted.

55 changes: 55 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Release

on:
push:
tags:
- v*.*.*
jobs:
test:
uses: ./.github/workflows/test.yml

version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- run: cargo install tomlq
- run: |
if [ "v$(tomlq version -f gleam.toml)" == "${{ github.ref_name }}" ]; then
exit 0
fi
echo "tag does not match version in gleam.toml, refusing to publish"
exit 1
release-gh:
runs-on: ubuntu-latest
needs:
- test
- version
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Release
uses: softprops/action-gh-release@v1

release-hex:
runs-on: ubuntu-latest
environment: publish
needs:
- test
- version
steps:
- uses: actions/checkout@v4
- uses: TanklesXL/gleam_actions/.github/actions/deps_restore@main
- uses: erlef/setup-beam@v1
with:
otp-version: 26
rebar3-version: 3
gleam-version: 1
- run: gleam publish -y
env:
HEXPM_USER: ${{ secrets.HEXPM_USER }}
HEXPM_PASS: ${{ secrets.HEXPM_PASS }}
shell: bash
16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Test

on:
push:
branches:
- main
pull_request:
workflow_call:

jobs:
test:
uses: TanklesXL/gleam_actions/.github/workflows/test.yaml@main
with:
gleam_version: 1.1.0
node_enabled: true
erlang_enabled: true
2 changes: 2 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tools]
gleam = "latest"
3 changes: 2 additions & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal_modules = ["gladvent/internal/*"]
gleam = "~> 1.0"

[dependencies]
glint = "1.0.0-rc1"
glint = "1.0.0-rc2"
simplifile = "~> 1.0"
argv = "~> 1.0"
shellout = "~> 1.6"
Expand All @@ -18,6 +18,7 @@ gleam_stdlib = "~> 0.36 or ~> 1.0"
gleam_otp = "~> 0.4"
gleam_erlang = "~> 0.7"
snag = "~> 0.2"
parallel_map = ">= 2.0.0 and < 3.0.0"

[dev-dependencies]
gleeunit = "~> 1.0"
17 changes: 10 additions & 7 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@

packages = [
{ name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" },
{ name = "filepath", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "EFB6FF65C98B2A16378ABC3EE2B14124168C0CE5201553DE652E2644DCFDB594" },
{ name = "gleam_community_ansi", version = "1.4.0", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_stdlib"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "FE79E08BF97009729259B6357EC058315B6FBB916FAD1C2FF9355115FEB0D3A4" },
{ name = "gleam_community_colour", version = "1.4.0", build_tools = ["gleam"], requirements = ["gleam_json", "gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "795964217EBEDB3DA656F5EB8F67D7AD22872EB95182042D3E7AFEF32D3FD2FE" },
{ name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" },
{ name = "gleam_json", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "8B197DD5D578EA6AC2C0D4BDC634C71A5BCA8E7DB5F47091C263ECB411A60DF3" },
{ name = "gleam_json", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "9063D14D25406326C0255BDA0021541E797D8A7A12573D849462CAFED459F6EB" },
{ name = "gleam_otp", version = "0.10.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "0B04FE915ACECE539B317F9652CAADBBC0F000184D586AAAF2D94C100945D72B" },
{ name = "gleam_package_interface", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_json", "gleam_stdlib"], otp_app = "gleam_package_interface", source = "hex", outer_checksum = "52A721BCA972C8099BB881195D821AAA64B9F2655BECC102165D5A1097731F01" },
{ name = "gleam_stdlib", version = "0.36.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "C0D14D807FEC6F8A08A7C9EF8DFDE6AE5C10E40E21325B2B29365965D82EB3D4" },
{ name = "gleam_stdlib", version = "0.37.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "5398BD6C2ABA17338F676F42F404B9B7BABE1C8DC7380031ACB05BBE1BCF3742" },
{ name = "glearray", version = "0.2.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glearray", source = "hex", outer_checksum = "908154F695D330E06A37FAB2C04119E8F315D643206F8F32B6A6C14A8709FFF4" },
{ name = "gleeunit", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D364C87AFEB26BDB4FB8A5ABDE67D635DC9FA52D6AB68416044C35B096C6882D" },
{ name = "glint", version = "1.0.0-rc1", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "gleam_community_colour", "gleam_stdlib", "snag"], otp_app = "glint", source = "hex", outer_checksum = "91EC8EFA3E8FBCB842C219AA02E8072204CEE02597B4C36C2ED78AD86DD1B2EC" },
{ name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" },
{ name = "glint", version = "1.0.0-rc2", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "gleam_community_colour", "gleam_stdlib", "snag"], otp_app = "glint", source = "hex", outer_checksum = "FD5C47CE237CA67121F3946ADE7C630750BB67F5E8A4717D2DF5B5EE758CCFDB" },
{ name = "parallel_map", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_otp", "gleam_stdlib"], otp_app = "parallel_map", source = "hex", outer_checksum = "653714A9FD63EACD1A9D0A6582A972B0EC109AE275CDDD2E99CFC3DFAFAB9225" },
{ name = "repeatedly", version = "2.1.1", build_tools = ["gleam"], requirements = [], otp_app = "repeatedly", source = "hex", outer_checksum = "38808C3EC382B0CD981336D5879C24ECB37FCB9C1D1BD128F7A80B0F74404D79" },
{ name = "shellout", version = "1.6.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "shellout", source = "hex", outer_checksum = "E2FCD18957F0E9F67E1F497FC9FF57393392F8A9BAEAEA4779541DE7A68DD7E0" },
{ name = "simplifile", version = "1.5.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "C44DB387524F90DC42142699C78C850003289D32C7C99C7D32873792A299CDF7" },
{ name = "simplifile", version = "1.7.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "1D5DFA3A2F9319EC85825F6ED88B8E449F381B0D55A62F5E61424E748E7DDEB0" },
{ name = "snag", version = "0.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "snag", source = "hex", outer_checksum = "54D32E16E33655346AA3E66CBA7E191DE0A8793D2C05284E3EFB90AD2CE92BCC" },
{ name = "spinner", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "gleam_erlang", "gleam_stdlib", "glearray", "repeatedly"], otp_app = "spinner", source = "hex", outer_checksum = "200BA3D4A04D468898E63C0D316E23F526E02514BC46454091975CB5BAE41E8F" },
{ name = "thoas", version = "0.4.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "4918D50026C073C4AB1388437132C77A6F6F7C8AC43C60C13758CC0ADCE2134E" },
{ name = "thoas", version = "1.2.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "E38697EDFFD6E91BD12CEA41B155115282630075C2A727E7A6B2947F5408B86A" },
]

[requirements]
Expand All @@ -29,7 +31,8 @@ gleam_otp = { version = "~> 0.4" }
gleam_package_interface = { version = "~> 1.0" }
gleam_stdlib = { version = "~> 0.36 or ~> 1.0" }
gleeunit = { version = "~> 1.0" }
glint = { version = "1.0.0-rc1" }
glint = { version = "1.0.0-rc2" }
parallel_map = { version = ">= 2.0.0 and < 3.0.0" }
shellout = { version = "~> 1.6" }
simplifile = { version = "~> 1.0" }
snag = { version = "~> 0.2" }
Expand Down
28 changes: 15 additions & 13 deletions src/gladvent.gleam
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import gleam/string
import gleam/io
import gladvent/internal/cmd/run
import gladvent/internal/cmd/new
import argv
import gladvent/internal/cmd
import gladvent/internal/cmd/new
import gladvent/internal/cmd/run
import gleam/io
import gleam/string
import glint
import snag
import argv

/// Find all runners in the project src/days/ directory and
/// run either the 'run' or 'new' command as specified
///
pub fn main() {
let commands =
glint.new()
|> glint.name("gladvent")
|> glint.path_help(
[],
"gladvent is an advent of code runner and generator for gleam.
Please use either the 'run' or 'new' commands.",
)
|> glint.with_name("gladvent")
|> glint.as_module
|> glint.group_flag(at: [], for: cmd.year, of: cmd.year_flag())
|> glint.group_flag(at: [], of: cmd.year_flag())
|> glint.pretty_help(glint.default_pretty_help())
|> glint.add(at: ["new"], do: new.new_command())
|> glint.group_flag(at: ["run"], for: run.timeout, of: run.timeout_flag())
|> glint.group_flag(
at: ["run"],
for: run.allow_crash,
of: run.allow_crash_flag(),
)
|> glint.group_flag(at: ["run"], of: run.timeout_flag())
|> glint.group_flag(at: ["run"], of: run.allow_crash_flag())
|> glint.add(at: ["run"], do: run.run_command())
|> glint.add(at: ["run", "all"], do: run.run_all_command())

Expand Down
77 changes: 28 additions & 49 deletions src/gladvent/internal/cmd.gleam
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import gleam/result
import gladvent/internal/parse.{type Day}
import gleam/otp/task.{type Task}
import gleam/erlang
import gleam/pair
import gleam/list
import gleam/int
import gleam/string
import snag
import gleam/list
import gleam/otp/task
import gleam/pair
import gleam/result
import glint
import parallel_map
import snag

pub fn input_dir(year) {
input_root <> int.to_string(year) <> "/"
Expand Down Expand Up @@ -38,47 +37,29 @@ pub fn exec(
do: fn(Day) -> a,
collect: fn(#(Day, Result(a, String))) -> c,
) -> List(c) {
days
|> task_map(do)
|> try_await_many(timing)
|> list.map(collect)
}

fn now_ms() {
erlang.system_time(erlang.Millisecond)
}

fn task_map(over l: List(a), with f: fn(a) -> b) -> List(#(a, Task(b))) {
use x <- list.map(l)
#(x, task.async(fn() { f(x) }))
}

fn try_await_many(
tasks: List(#(x, Task(a))),
timing: Timing,
) -> List(#(x, Result(a, String))) {
case timing {
Endless -> {
use tup <- list.map(tasks)
use t <- pair.map_second(tup)
Ok(task.await_forever(t))
}

Ending(timeout) -> {
let end = now_ms() + timeout
use tup <- list.map(tasks)
use t <- pair.map_second(tup)
let res =
{ end - now_ms() }
|> int.clamp(min: 0, max: timeout)
|> task.try_await(t, _)
use err <- result.map_error(res)
case err {
task.Timeout -> "task timed out"
task.Exit(s) -> "task exited for some reason: " <> string.inspect(s)
Endless ->
days
// spawn all tasks
|> list.map(fn(day) { #(day, task.async(fn() { do(day) })) })
// start collecting tasks
|> fn(tasks) {
use tup <- list.map(tasks)
use t <- pair.map_second(tup)
Ok(task.await_forever(t))
}
Ending(timeout) -> {
parallel_map.list_pmap(
days,
do,
parallel_map.MatchSchedulersOnline,
timeout,
)
|> list.map(result.replace_error(_, "failed to execute task"))
|> list.zip(days, _)
}
}
|> list.map(collect)
}

@external(erlang, "erlang", "localtime")
Expand All @@ -88,12 +69,10 @@ fn current_year() -> Int {
{ date().0 }.0
}

pub const year = "year"

pub fn year_flag() {
use year <- glint.constraint(
glint.int()
|> glint.default(current_year()),
use year <- glint.flag_constraint(
glint.int_flag("year")
|> glint.flag_default(current_year()),
)
case year < 2015 {
True ->
Expand Down
21 changes: 10 additions & 11 deletions src/gladvent/internal/cmd/new.gleam
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import gladvent/internal/cmd
import gladvent/internal/file
import gladvent/internal/parse.{type Day}
import gleam/int
import gleam/result
import gleam/list
import gleam/pair
import gleam/result
import gleam/string
import gladvent/internal/file
import simplifile as efile
import gladvent/internal/cmd
import glint
import gladvent/internal/parse.{type Day}
import gleam/pair
import simplifile as efile

type Context {
Context(year: Int, day: Day, add_parse: Bool)
Expand Down Expand Up @@ -179,14 +179,13 @@ pub fn new_command() {
use <- glint.command_help("Create .gleam and input files")
use <- glint.unnamed_args(glint.MinArgs(1))
use parse <- glint.flag(
"parse",
glint.bool()
|> glint.default(False)
|> glint.flag_help("Generate day runners with a parse function"),
glint.bool_flag("parse")
|> glint.flag_default(False)
|> glint.flag_help("Generate day runners with a parse function"),
)
use _, args, flags <- glint.command()
use days <- result.map(parse.days(args))
let assert Ok(year) = glint.get_int(flags, cmd.year)
let assert Ok(year) = glint.get_flag(flags, cmd.year_flag())
let assert Ok(parse) = parse(flags)
cmd.exec(
days,
Expand Down

0 comments on commit bbe05b7

Please sign in to comment.