3333
3434 - name : Get result
3535 run : echo "${{steps.script.outputs.result}}"
36-
3736 io-is-visible-in-logs :
3837 runs-on : ubuntu-latest
3938 steps :
4544
4645 - name : Get result
4746 run : echo "${{steps.script.outputs.result}}"
48-
4947 event-context-is-available :
5048 runs-on : ubuntu-latest
5149 steps :
5856
5957 - name : Get result
6058 run : echo "${{steps.script.outputs.result}}"
61-
6259 the-entire-context-can-be-inspected :
6360 runs-on : ubuntu-latest
6461 steps :
7067
7168 - name : Get result
7269 run : echo "${{steps.script.outputs.result}}"
73-
7470 multiline-scripts-are-possible :
7571 runs-on : ubuntu-latest
7672 steps :
8379
8480 - name : Get result
8581 run : echo "${{steps.script.outputs.result}}"
86-
8782 oh-hi-mark-greeter :
8883 runs-on : ubuntu-latest
8984 steps :
9893
9994 - name : Get result
10095 run : echo "${{steps.script.outputs.result}}"
101-
10296 can-use-the-github-api-via-tentacat :
10397 runs-on : ubuntu-latest
10498 steps :
@@ -111,7 +105,6 @@ jobs:
111105
112106 - name : Get result
113107 run : echo "${{steps.script.outputs.result}}"
114-
115108 can-grab-information-via-the-github-api :
116109 runs-on : ubuntu-latest
117110 steps :
@@ -124,7 +117,6 @@ jobs:
124117
125118 - name : Get result
126119 run : echo "${{steps.script.outputs.result}}"
127-
128120 can-interact-with-repositories-via-github-api :
129121 runs-on : ubuntu-latest
130122 steps :
@@ -137,3 +129,138 @@ jobs:
137129
138130 - name : Get result
139131 run : echo "${{steps.script.outputs.result}}"
132+ file-scripts-can-define-and-use-modules :
133+ runs-on : ubuntu-latest
134+ steps :
135+ - name : Create script files
136+ run : |
137+ mkdir -p ./.github/scripts
138+ cat > ./.github/scripts/pr_analyzer.exs << 'EOFMARKER'
139+ defmodule PRAnalyzer do
140+ def analyze(context) do
141+ %{
142+ event: context.event_name,
143+ workflow: context.workflow,
144+ job: context.job,
145+ ref: context.ref
146+ }
147+ end
148+
149+ def format_message(analysis) do
150+ "PR Analysis: event=#{analysis.event}"
151+ end
152+ end
153+
154+ # Use the module to analyze and format
155+ analysis = PRAnalyzer.analyze(context)
156+ PRAnalyzer.format_message(analysis)
157+ EOFMARKER
158+
159+ - uses : gaggle/elixir_script@v0
160+ id : script
161+ with :
162+ script : ./.github/scripts/pr_analyzer.exs
163+
164+ - name : Get result
165+ run : echo "${{steps.script.outputs.result}}"
166+ file-scripts-can-use-relative-require-for-helper-modules :
167+ runs-on : ubuntu-latest
168+ steps :
169+ - name : Create script files
170+ run : |
171+ mkdir -p ./scripts
172+ cat > ./scripts/helpers.exs << 'EOFMARKER'
173+ defmodule Helpers do
174+ def format_workflow(_context) do
175+ "Script loaded from: ./scripts/main.exs"
176+ end
177+ end
178+ EOFMARKER
179+ mkdir -p ./scripts
180+ cat > ./scripts/main.exs << 'EOFMARKER'
181+ Code.require_file("helpers.exs", __DIR__)
182+ Helpers.format_workflow(context)
183+ EOFMARKER
184+
185+ - uses : gaggle/elixir_script@v0
186+ id : script
187+ with :
188+ script : ./scripts/main.exs
189+
190+ - name : Get result
191+ run : echo "${{steps.script.outputs.result}}"
192+ bootstrap-pattern-delegates-to-testable-module :
193+ runs-on : ubuntu-latest
194+ steps :
195+ - name : Create script files
196+ run : |
197+ mkdir -p .
198+ cat > main.ex << 'EOFMARKER'
199+ defmodule Main do
200+ def run(_context) do
201+ "Bootstrap test passed!"
202+ end
203+ end
204+ EOFMARKER
205+
206+ - uses : gaggle/elixir_script@v0
207+ id : script
208+ with :
209+ script : |
210+ # Bootstrap: load and run the main module
211+ Code.require_file("main.ex", ".")
212+ Main.run(context)
213+
214+ - name : Get result
215+ run : echo "${{steps.script.outputs.result}}"
216+ bootstrap-with-complex-module-structure :
217+ runs-on : ubuntu-latest
218+ steps :
219+ - name : Create script files
220+ run : |
221+ mkdir -p lib
222+ cat > lib/analyzer.ex << 'EOFMARKER'
223+ defmodule Analyzer do
224+ def analyze_event(context) do
225+ %{
226+ type: context.event_name,
227+ branch: extract_branch(context.ref)
228+ }
229+ end
230+
231+ defp extract_branch(ref) do
232+ ref |> String.split("/") |> List.last()
233+ end
234+ end
235+ EOFMARKER
236+ mkdir -p lib
237+ cat > lib/app.ex << 'EOFMARKER'
238+ defmodule App do
239+ def start(context, _client) do
240+ context
241+ |> Analyzer.analyze_event()
242+ |> Formatter.format_analysis()
243+ end
244+ end
245+ EOFMARKER
246+ mkdir -p lib
247+ cat > lib/formatter.ex << 'EOFMARKER'
248+ defmodule Formatter do
249+ def format_analysis(analysis) do
250+ "Event type: #{String.capitalize(analysis.type)}"
251+ end
252+ end
253+ EOFMARKER
254+
255+ - uses : gaggle/elixir_script@v0
256+ id : script
257+ with :
258+ script : |
259+ # Minimal bootstrap that loads and runs the application
260+ Code.require_file("lib/analyzer.ex", ".")
261+ Code.require_file("lib/formatter.ex", ".")
262+ Code.require_file("lib/app.ex", ".")
263+ App.start(context, client)
264+
265+ - name : Get result
266+ run : echo "${{steps.script.outputs.result}}"
0 commit comments