pocmatos
2020-10-7 16:53:25

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)


pocmatos
2020-10-7 16:53:50

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.


pocmatos
2020-10-7 16:54:21

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.


pocmatos
2020-10-7 16:54:33

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)


pocmatos
2020-10-7 16:54:42

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


pocmatos
2020-10-7 16:54:52

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


pocmatos
2020-10-7 16:55:04

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


pocmatos
2020-10-7 16:55:12

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


pocmatos
2020-10-7 16:55:58

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.


pocmatos
2020-10-7 16:56:54

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:


pocmatos
2020-10-7 16:57:18

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


sorawee
2020-10-7 18:49:16

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.


mflatt
2020-10-7 19:02:01

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.


pocmatos
2020-10-8 04:46:03

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.