
Hi everyone! CI channel has been quiet which is good because things have been working smoothly modulo flaky failures with github network or flaky tests (portlib mainly)

Anyway, I want to write more workflows but it really annoys me to do so these days cause I am copy/pasting stuff all over the place.

So I quickly went back to an idea we discussed a couple of months ago and just put this together in the last 20 mins to see if there were any major issues.

So this: #lang scribble/text
@(define test-list
'(tests/racket/test
tests/racket/contract/all))
@(define (indent-block n str)
(define lines (string-split str "\n"))
(define indent (make-string n #\space))
(apply string-append
(for/list ([line (in-list lines)])
(string-append indent line "\n"))))
@(define (generate-test-steps tests indent)
(indent-block indent
(apply string-append
(for/list ([t (in-list tests)])
(format
#<<EOF
- name: Run ~a
run: rack test -l ~a
EOF
t t)))))
name: Test CI
on: [push]
jobs:
test:
steps:
@(generate-test-steps test-list 6)

generates this: name: Test CI
on: [push]
jobs:
test:
steps:
- name: Run tests/racket/test
run: rack test -l tests/racket/test
- name: Run tests/racket/contract/all
run: rack test -l tests/racket/contract/all

There’s a reason I don’t like this very much…

It’s the hardcoded 6 in @(generate-test-steps test-list 6)

There a few more issues but that’s the most annoying one.

I would appreciate suggestions to this approach and if anybody knows how to get the current column in scribble/text so that I can somehow pass it into generate-test-steps
it would be great.

Also, I will need to revisit all the string to list transformations and back but this is just a MVP - so the final thing would be done properly(TM) :wink:

I had a quite long day so I will break for now but keen to know if anyone has some suggestions.

The problem is that you print jobs: test: steps:
separately. It’s not in the control of the “printer”.
I think a proper way to do this is to create an S-exp like:
(jobs (test (steps
(step [name "Run ..."] [run "..."])
(step [name "Run ..."] [run "..."]))))
With this, the procedure that converts S-exp to string knows how far it’s already been, since it has a control of the whole thing.

A full S-expression-ization could certainly work.
Another possibility is to rely on source location information; put six spaces before @(generate-test-steps …)
, and have generate-test-steps
be a macro that infers 6
from the source location of its use. Relying on source locations can sometimes cause problems, but it mostly works out for things like racketblock
in Scribble.

I think using scribble/text
is a cool idea. My initial idea was closer to what @sorawee mentioned which went through generating an sexpr and using the yaml
module to convert that to valid yaml. I think s-exprs are easier to work with and manipulate but the scribble/text
feels like it would be easier to read for those who hadn’t looked at it before, and certainly another cool application of Racket’s multi language paradigm. I will go down the rabbit hole and see what a scribble/text
approach looks like for something like for the ci-push_linux
workflow and then come back and see how the sexpr solution compares.