D
Deno

help

Creating custom GitHub Action using Deno

MMqx1/30/2024
Hey, I am currently trying to develop my first own custom GitHub Action. I have some trouble setting up my environment. I really don't want to use Node and try to stick to Deno, but this is easier said than done. Can someone help me setting a basic action up? Thanks! This is my current repo where I try to set everything up: https://github.com/Datapack-Registry/minecraft-manifest I have already look into this official template, but this is for Node only... https://github.com/actions/typescript-action/tree/main
DAHDeno AI Helper1/30/2024
Hello there! 🦕 It's great to hear that you're looking to create a custom GitHub Action using Deno. Setting up a GitHub Action with Deno is quite straightforward, and I can guide you through the basic setup. Here's a simple workflow that you can use as a starting point for your GitHub Action:
name: Deno Custom Action
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Deno
uses: denoland/setup-deno@main
with:
deno-version: 1.x

- name: Run custom Deno script
run: deno run --allow-all your-script.ts
name: Deno Custom Action
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Deno
uses: denoland/setup-deno@main
with:
deno-version: 1.x

- name: Run custom Deno script
run: deno run --allow-all your-script.ts
In this workflow: - The action is triggered on push and pull request events to the main branch. - It sets up a job called build that runs on the latest Ubuntu runner. - The actions/checkout@v2 step checks out your repository code. - The denoland/setup-deno@main step sets up Deno on the runner. You can specify the Deno version you want to use with the deno-version input. - Finally, the Run custom Deno script step executes your Deno script using deno run. Replace your-script.ts with the path to your Deno script in the repository. Make sure to adjust the permissions and flags according to your script's requirements. For example, if your script doesn't need access to all permissions, you should remove --allow-all and specify only the permissions your script needs. You can place this workflow in a .github/workflows directory in your repository. For example, you could name the file deno-action.yml. Remember to also check the documentation for any specific configurations you might need, especially if you're planning to use Deno Deploy or other Deno-specific features. The
DAHDeno AI Helper1/30/2024
documentation provides detailed guidance on setting up GitHub Actions with Deno, including how to use the deployctl GitHub action if you're deploying to Deno Deploy. I hope this helps you get started with your custom GitHub Action using Deno! If you have any more questions or need further assistance, feel free to ask. Good luck with your project! 🦕
MMqx1/31/2024
That’s not what I want to achieve. I don’t want to build a workflow where I use Deno, I want to build my own custom action using Deno as runtime.
DAHDeno AI Helper1/31/2024
Apologies for the confusion. To create a custom GitHub Action using Deno as the runtime, you'll need to create a Docker container action that uses Deno. Here's a basic setup for a custom GitHub Action using Deno: 1. Create a Dockerfile in your GitHub repository that sets up Deno. Here's an example Dockerfile:
# Use the official Deno image as a parent image
FROM denoland/deno:alpine-1.24.3

# Set the working directory
WORKDIR /action

# Copy the entrypoint script to the container
COPY entrypoint.sh /entrypoint.sh

# Give execute permission to the entrypoint script
RUN chmod +x /entrypoint.sh

# Set the entrypoint script to be executed when the container starts
ENTRYPOINT ["/entrypoint.sh"]
# Use the official Deno image as a parent image
FROM denoland/deno:alpine-1.24.3

# Set the working directory
WORKDIR /action

# Copy the entrypoint script to the container
COPY entrypoint.sh /entrypoint.sh

# Give execute permission to the entrypoint script
RUN chmod +x /entrypoint.sh

# Set the entrypoint script to be executed when the container starts
ENTRYPOINT ["/entrypoint.sh"]
2. Create an entrypoint.sh script that will run your Deno code. Here's an example entrypoint.sh:
#!/bin/sh -l

# Run your Deno script
deno run --allow-all your-script.ts "$@"
#!/bin/sh -l

# Run your Deno script
deno run --allow-all your-script.ts "$@"
Make sure to replace your-script.ts with the path to your Deno script and adjust the permissions as needed. 3. Create your Deno script (e.g., your-script.ts) that contains the logic for your GitHub Action. 4. Create an action.yml file in the root of your repository that defines your action's inputs, outputs, and runs the Docker container. Here's an example action.yml:
name: 'My Custom Deno Action'
description: 'A custom GitHub Action built with Deno'
inputs:
my-input:
description: 'Input for my action'
required: true
outputs:
my-output:
description: 'Output from my action'
runs:
using: 'docker'
image: 'Dockerfile'
args:
- "${{ inputs.my-input }}"
name: 'My Custom Deno Action'
description: 'A custom GitHub Action built with Deno'
inputs:
my-input:
description: 'Input for my action'
required: true
outputs:
my-output:
description: 'Output from my action'
runs:
using: 'docker'
image: 'Dockerfile'
args:
- "${{ inputs.my-input }}"
5. Push these changes to your repository. This setup defines a custom GitHub Action that runs a Deno script inside a Docker container. When you use this action in a workflow,
DAHDeno AI Helper1/31/2024
GitHub will build the Docker container using the Dockerfile and then run the container with the entrypoint.sh script as the entry point. Please note that the advice provided here is not directly from the Deno documentation, and you should double-check the accuracy of the advice given. If you encounter any issues or have further questions, feel free to ask for assistance. Good luck with your Deno-based GitHub Action!

Looking for more? Join the community!

Recommended Posts
how to avoid deprecation warnings in compiled binaries```sh $ pkgx --version warning: Use of deprecated "Deno.stderr.rid" API. This API will be removed inDeno compile with "--no-terminal" don't workI'm trying to compile a very simple file named main.ts ```ts await Deno.writeTextFile('test.txt', 'Hdeno task start not runnning in Powershell.This is the link of the tutorial I am following https://github.com/googleanalytics/ga4-tutorials?tabDeployment ID not available after API deploymentHi - i'm calling the /deployments endpoint after creating a new project: ${API}/projects/${project.`Request` body reading functions: possible error types[This](https://docs.deno.com/runtime/manual/runtime/http_server_apis#inspecting-the-incoming-requestHow to call a JS function from Rust?Hi, I'd like to call a JS function from Rust but I can't seem to find an example that does so. I goView code in Subhosting projectHi there - i'm using the API to create a new project and deployment with Subhosting. Just wondering Stop deno deploy instanceHi everyone, I just deployed my first test deno project on deno deploy. Now I'm wondering how to stoHow can I flush a stream to a response?I'm trying to stream a response but it appears that data is only sent after either a newline is writHoping for a clean way to get an array of filenames in directoryTrying to do something like this: ```typescript const files = Deno.readDirSync(Deno.cwd()).map(x => Support for auto-accessorsI'm playing around with Decorators, it seems like with `"experimentalDecorators": false`, there's a Rust sdk register_actity_typeHey, I am using the core_sdk in rust. I registered an activity, which should be able to consume follIs there a feature allowing custom "Allow?" CLI inputs?For example, if you `deno run` some program that reads from the file system, you're prompted `Deno r"deno compile --no-terminal" is not workingI'm trying to compile a very simple file named main.ts ```ts await Deno.writeTextFile('test.txt', 'H