Skip to content

Instantly share code, notes, and snippets.

@atty303
Created May 5, 2025 13:14
Show Gist options
  • Save atty303/1cff62ca4dd5e0128c08a16bf0eb0932 to your computer and use it in GitHub Desktop.
Save atty303/1cff62ca4dd5e0128c08a16bf0eb0932 to your computer and use it in GitHub Desktop.
GitHub Actions: deno-actions
name: name
description: description
inputs:
deno_run:
description: Path to the deno script to run
default: ./.github/actions/example/main.ts
runs:
using: node20
main: ./.github/actions/example.index.js
import o from"node:process";import n,{spawnSync as r}from"node:child_process";import t from"node:os";import e from"node:path";import i from"node:fs/promises";import{createWriteStream as a}from"node:fs";import{pipeline as s}from"node:stream/promises";import{ok as c}from"node:assert";import{fileURLToPath as l}from"node:url";async function d(){const n=o.env.RUNNER_TOOL_CACHE;c(n,"RUNNER_TOOL_CACHE is not set");const l="win32"===t.platform()?"deno.exe":"deno",d=function(){const o=t.platform(),n=t.arch();if("linux"===o&&"x64"===n)return"linux-x64-glibc";if("linux"===o&&"arm64"===n)return"linux-arm64-glibc";if("darwin"===o&&"x64"===n)return"darwin-x64";if("darwin"===o&&"arm64"===n)return"darwin-aarch64";if("win32"===o&&"x64"===n)return"win32-x64";if("win32"===o&&"arm64"===n)return"win32-arm64";throw new Error(`Unsupported platform/arch: ${o}/${n}`)}(),m=e.resolve(n,"deno-actions",d),f=e.join(m,l);try{await i.access(f),console.log(`Using cached Deno at ${f}`)}catch{const o=await async function(o){const n=`@deno/${o}`,r=`https://registry.npmjs.org/${encodeURIComponent(n)}/latest`,t=await fetch(r);if(!t.ok)throw new Error(`Failed to fetch ${n}: ${t.status}`);return t.json()}(d);await async function(o,n){const t=o.dist.tarball;console.log(`Downloading Deno tarball: ${t}`);const c=await fetch(t);if(!c.ok)throw new Error(`Tarball download failed: ${c.status}`);await i.mkdir(n,{recursive:!0});const l=e.join(n,"deno.tar.gz");await s(c.body,a(l)),console.log(`Extracting to ${n} …`);const d=r("tar",["-xzf",l,"-C",n,"--strip-components","1"],{stdio:"inherit"});if(0!==d.status)throw new Error(`tar exited with code ${d.status}`);await i.unlink(l),console.log("Extraction complete.")}(o,m)}return console.log(`Deno binary is ready: ${f}`),f}async function m(){const r=o.env.INPUT_DENO_RUN;r||(console.log(":error::No deno arguments provided"),o.exit(1));const t=["run","--unstable-temporal","-A",r],e=await d();console.log(`Running ${e} ${t.join(" ")}`);const i=n.spawnSync(e,t,{stdio:"inherit",env:{...o.env}});if(i.error)throw i.error;console.log(`Deno exited with ${i}`),o.exitCode=i.status}l(import.meta.url)===o.argv[1]&&await m();export{m as run};
@atty303
Copy link
Author

atty303 commented May 5, 2025

Usage

Copy index.js (2.1 KB) into your repository (anywhere you like) and set its path in the runs.main field of your action.yml. Then, in your Deno-based custom Action, put the path to your Deno script in inputs.deno_run.default. With that in place, your Deno script can be executed directly from the GitHub Action.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment