Mqx
Mqx•10mo ago

Creating custom GitHub Action using Deno

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
6 Replies
Mqx
MqxOP•10mo ago
I have already look into this official template, but this is for Node only... https://github.com/actions/typescript-action/tree/main
Deno AI Helper
Deno AI Helper•10mo ago
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
Deno AI Helper
Deno AI Helper•10mo ago
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! 🦕
Mqx
MqxOP•10mo ago
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.
Deno AI Helper
Deno AI Helper•10mo ago
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,
Deno AI Helper
Deno AI Helper•10mo ago
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!