TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Any program can be a GitHub Actions shell

282 pointsby woodruffwabout 2 months ago

20 comments

jstriebabout 2 months ago
I&#x27;ve used this in the past to force bash to print every command it runs (using the -x flag) in the Actions workflow. This can be very helpful for debugging.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;jstrieb&#x2F;just.sh&#x2F;blob&#x2F;2da1e2a3bfb51d583be0b14969bd81fea696d039&#x2F;.github&#x2F;workflows&#x2F;test.yml#L20">https:&#x2F;&#x2F;github.com&#x2F;jstrieb&#x2F;just.sh&#x2F;blob&#x2F;2da1e2a3bfb51d583be0...</a>
评论 #43623035 未加载
digianarchistabout 2 months ago
One cool undocumented GitHub Actions trick I spotted at work was the ability to use wildcards to match repository_dispatch event names:<p><pre><code> on: repository_dispatch: - security_scan - security_scan::* </code></pre> Why would you want to do this?<p>We centralize our release pipelines as it&#x27;s the only way to force repositories through a defined reusable workflow (we don&#x27;t want our product teams to have to maintain them).<p>This allows us to dispatch an event like so:<p><pre><code> { &quot;event_type&quot;: &quot;security_scan::$product_name::$version&quot;, &quot;client_payload&quot;: { &quot;field&quot;: &quot;value&quot; } } </code></pre> Then it is far easier to identify which product and version a workflow is running when looking in the Actions tab of our central release repository.
评论 #43621239 未加载
评论 #43620285 未加载
greener_grassabout 2 months ago
My experience is that the less done in GitHub actions the better.<p>I tend to prefer either:<p>- Using a build-system (e.g. Make) to encode logic and just invoke that from GitHub Actions; or<p>- Writing a small CLI program and then invoke that from GitHub Actions<p>It&#x27;s so much easier to debug this stuff locally than in CI.<p>So an interesting trick, but I don&#x27;t see where it would be useful.
评论 #43621938 未加载
评论 #43619850 未加载
评论 #43620041 未加载
cturnerabout 2 months ago
Our generation shuddered in terror when we were asked to translate a spreadsheet to code while the spreadsheet continued to evolve.<p>This generation will shudder when they are asked to bring discipline to deployments built from github actions.
评论 #43620212 未加载
评论 #43618970 未加载
ZiiSabout 2 months ago
You can also trick the default shell &#x27;bash&#x27; into running any program.
throw10920about 2 months ago
As long as other readers of the action are aware of what&#x27;s happening, this seems pretty useful. There&#x27;s been many adventures where my shell script, starting out as a few lines basically mirroring what I typed in by hand, has grown to a hundred-line-plus monster where I wish that I had real arrays and types and the included batteries in the Python stdlib.<p>I&#x27;m definitely not going to use this to implement my company&#x27;s build actions in elisp.
aljarryabout 2 months ago
Github Actions Runner code is pretty easy to read, here&#x27;s a specific place that define default arguments for popular shells &#x2F; binaries: <a href="https:&#x2F;&#x2F;github.com&#x2F;actions&#x2F;runner&#x2F;blob&#x2F;main&#x2F;src&#x2F;Runner.Worker&#x2F;Handlers&#x2F;ScriptHandlerHelpers.cs#L18">https:&#x2F;&#x2F;github.com&#x2F;actions&#x2F;runner&#x2F;blob&#x2F;main&#x2F;src&#x2F;Runner.Worke...</a>, it is exported through a method ScriptHandlerHelpers.GetScriptArgumentsFormat.<p>In ScriptHandler.cs there&#x27;s all the code for preparing process environment, arguments, etc. but specifically here&#x27;s actual code to start the process:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;actions&#x2F;runner&#x2F;blob&#x2F;main&#x2F;src&#x2F;Runner.Worker&#x2F;Handlers&#x2F;ScriptHandler.cs#L331">https:&#x2F;&#x2F;github.com&#x2F;actions&#x2F;runner&#x2F;blob&#x2F;main&#x2F;src&#x2F;Runner.Worke...</a><p>Overall I was positively surprised at simplicity of this code. It&#x27;s very procedural, it handles a ton of edge cases, but it seems to be easy to understand and debug.
markus_zhangabout 2 months ago
Wait I can finally write C for our CI&#x2F;CD in production and call it a low level system job.<p>Probably can write assembly too.
评论 #43618933 未加载
评论 #43618230 未加载
dolmenabout 2 months ago
This gives me hope to ease running Go code for CI jobs directly from GitHub workflow YAML files using goeval [1].<p>However goeval doesn&#x27;t yet have direct support for file input (only stdin), so shell tricks are needed.<p>So far the way is:<p><pre><code> run: | go run github.com&#x2F;dolmen-go&#x2F;goeval@v1 - &lt;&lt;&#x27;EOF&#x27; fmt.Println(&quot;Hello&quot;) EOF </code></pre> but this requires a bit of boilerplate.<p>Disclaimer: I&#x27;m the author of goeval.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;dolmen-go&#x2F;goeval">https:&#x2F;&#x2F;github.com&#x2F;dolmen-go&#x2F;goeval</a>
评论 #43621030 未加载
评论 #43621787 未加载
z3t4about 2 months ago
What are the advantages with Github CI yaml over just a bash script, eg run: pipeline.sh ?
评论 #43619328 未加载
评论 #43619274 未加载
评论 #43619478 未加载
_defabout 2 months ago
Ah I didn&#x27;t know of the shell directive. Basically an equivalent to #! in shell scripts I guess: <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Shebang_%28Unix%29" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Shebang_%28Unix%29</a>
评论 #43619913 未加载
nonethewiserabout 2 months ago
Who would the potential bad actor be here? Someone whose committing to your repo right? I guess the risk is that they add something malicious in the commit and you dont see it. Which is maybe obfuscated to some extent by this little known fact. But all the malicious code would be there in the open just like any other commit.<p>I mean, it seems like it would either take not noticing the malicious code which is always a threat vector. Or seeing it and mistakenly thinking &quot;aha, but you arent actually running it!&quot; and then letting it through based on that (which is of course ridiculous).<p>Or there is some other way to exploit this that I&#x27;m unaware of.<p>Edit: OK, maybe this is a little better. Re-write some malicious bash look alike somewhere outside the repo, install it from github actions (make it look like you are updating bash or something) and then its doing the bad thing.
评论 #43621963 未加载
pseufauxabout 2 months ago
uv --script
hulituabout 2 months ago
&gt; Any program can be a GitHub Actions shell<p>systemd, echo &quot;1&quot; &gt; &#x2F;proc&#x2F;sys&#x2F;kernel&#x2F;panic, echo &gt; &#x2F;bin&#x2F;bash, etc.
评论 #43618629 未加载
cdataabout 2 months ago
I wonder if you could pair this with nix e.g.,:<p><pre><code> - shell: nix develop --command {0} run: ...</code></pre>
评论 #43618779 未加载
评论 #43623866 未加载
ViperCodeabout 2 months ago
how many workflows could be simplified this way without sacrificing debuggability or security.&quot;
nickysielickiabout 2 months ago
Would be cool to use this with nix shell shebangs
mkoubaaabout 2 months ago
The next DOOM port
评论 #43622080 未加载
donatjabout 2 months ago
I mean it&#x27;s just a shell script jammed into YAML for reasons. The shell is just the shebang of said script
emilfihlmanabout 2 months ago
I mean, exec already exists, so you can become anything anyways.
评论 #43619386 未加载