Current section

Files

Jump to
caffeine_lang src caffeine_lang@codegen@relay_workflow.erl
Raw

src/caffeine_lang@codegen@relay_workflow.erl

-module(caffeine_lang@codegen@relay_workflow).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/caffeine_lang/codegen/relay_workflow.gleam").
-export([generate/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-file("src/caffeine_lang/codegen/relay_workflow.gleam", 23).
?DOC(
" Codegen for the GitHub Actions workflow that runs the bundled relay.\n"
"\n"
" The output is a static YAML file the compiler dumps verbatim at\n"
" `.github/workflows/caffeine-relay.yml` whenever any expectation uses\n"
" external-signal indicators. The workflow:\n"
"\n"
" - fires every 5 minutes (cron) and on `workflow_dispatch`\n"
" - uses a single-slot concurrency group so a slow run doesn't overlap\n"
" itself\n"
" - installs Erlang + Gleam via `erlef/setup-beam`\n"
" - restores the cursor file from GHA cache, then saves it back on exit\n"
" so each run picks up where the last one stopped\n"
" - invokes the bundled relay project via `gleam run`\n"
" - pulls Langfuse and Datadog credentials from repo secrets\n"
"\n"
" Paths assume the layout from `codegen/relay` (Task #5) and the bundled\n"
" relay project from Task #7: `build/relay/signals.json` for the routing\n"
" table and `build/relay/relay/` for the Gleam project itself.\n"
" Returns `None` when no relay is needed (the compiler decides based on\n"
" whether any IR uses external-signal indicators). The wrapped string is\n"
" the literal YAML the compiler writes to disk.\n"
).
-spec generate() -> binary().
generate() ->
<<"name: caffeine-relay
on:
schedule:
- cron: \"*/5 * * * *\"
workflow_dispatch: {}
concurrency:
group: caffeine-relay
cancel-in-progress: false
jobs:
relay:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
with:
otp-version: \"27\"
gleam-version: \"1.x\"
- uses: actions/cache/restore@v4
with:
path: .caffeine/cursor.json
key: caffeine-cursor-${{ github.run_id }}
restore-keys: caffeine-cursor-
- run: gleam run -- --config ../signals.json --cursor ../../.caffeine/cursor.json
working-directory: build/relay/relay
env:
LANGFUSE_PUBLIC_KEY: ${{ secrets.LANGFUSE_PUBLIC_KEY }}
LANGFUSE_SECRET_KEY: ${{ secrets.LANGFUSE_SECRET_KEY }}
# Override for self-hosted / EU cloud; leave the repo var unset
# to default to https://cloud.langfuse.com.
LANGFUSE_BASE_URL: ${{ vars.LANGFUSE_BASE_URL }}
DD_API_KEY: ${{ secrets.DD_API_KEY }}
- if: always()
uses: actions/cache/save@v4
with:
path: .caffeine/cursor.json
key: caffeine-cursor-${{ github.run_id }}
"/utf8>>.