Skip to content

Commit

Permalink
Attempt to create a GitHub Action
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Therapy <sam@samtherapy.net>
  • Loading branch information
SamTherapy committed Mar 27, 2024
1 parent 10d17ae commit c8aa478
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 92 deletions.
40 changes: 0 additions & 40 deletions .drone.yml

This file was deleted.

4 changes: 2 additions & 2 deletions README.md → .github/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Drone Plugin to Deploy to Deno Deploy

[![Build Status](https://ci.git.froth.zone/api/badges/sam/drone-deno-deploy/status.svg)](https://ci.git.froth.zone/sam/drone-deno-deploy)
[![Built with the Deno Standard Library](https://raw.githubusercontent.com/denoland/deno_std/main/badge.svg)](https://deno.land/std)

A [Drone](https://drone.io) and [Woodpecker](https://woodpecker-ci.org/) plugin
to deploy a JavaScript/TypeScript application to
[Deno Deploy](https://deno.com/deploy).

This is built on top of [deployctl](https://deno.com/deploy/docs/deployctl).

## Example Usage
## Example Usage (Drone)

```yaml
- name: Deploy to Deno Deploy (prod)
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: ci

on:
push:
branches:
- master

env:
REGISTRY: ${{ gitea.actor != '' && 'git.froth.zone' || 'ghcr.io' }}
IMAGE_NAME: ${{ github.repository }}

jobs:
docker:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

5 changes: 0 additions & 5 deletions .vscode/settings.json

This file was deleted.

33 changes: 33 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: 'Deno Deploy Action'
description: 'Github/Gitea/Forgejo Action for deploying applications via Deno Deploy'
author: 'SamTherapy'
runs:
using: 'docker'
image: 'Dockerfile'
inputs:
deno_deploy_token:
description: 'Deno Deploy Token'
required: true
project:
description: 'The project name used to deploy'
required: true
entrypoint:
description: 'The entrypoint file for the deployment'
required: true
exclude:
description: 'Files to exclude from the deployment'
required: false
default: ''
include:
description: 'Files to include in the deployment'
required: false
default: ''
import_map:
description: 'Path to the import map for the deployment'
required: false
default: ''
production:
description: 'Whether to deploy in production mode'
required: false


5 changes: 5 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"imports": {
"std/": "https://deno.land/std@0.220.1/"
}
}
1 change: 0 additions & 1 deletion example
Submodule example deleted from c1d62a
83 changes: 42 additions & 41 deletions run.ts
Original file line number Diff line number Diff line change
@@ -1,78 +1,79 @@
#!/usr/bin/env -S deno run --allow-read --allow-write --allow-run --allow-env --allow-sys --no-lock

import { copy } from "https://deno.land/std@0.104.0/io/util.ts";

const env = Deno.env.toObject();

if (!env["PLUGIN_DENO_DEPLOY_TOKEN"] && !env["DENO_DEPLOY_TOKEN"]) {
console.error(
"A Deno Deploy token is required.\n\nGo to https://dash.deno.com/account#access-tokens to get one and set DENO_DEPLOY_TOKEN.",
);
Deno.exit(1);
function getEnv(key: string, required = false, errorMsg?: string) {
key = key.toUpperCase();
if (env[key]) return env[key];
// Drone/Woodpecker
else if (env[`PLUGIN_${key}`]) return env[`PLUGIN_${key}`];
// Github Actions
else if (env[`INPUT_${key}`]) return env[`INPUT_${key}`];
else if (required) {
console.error(errorMsg ?? `${key} is required`);
Deno.exit(1);
}
return "";
}

if (!env["PLUGIN_ENTRYPOINT"]) {
console.error("An entrypoint is required");
Deno.exit(1);
}

if (!env["PLUGIN_PROJECT"]) {
console.error("An project is required");
Deno.exit(1);
}

const flags = [`-p=${env["PLUGIN_PROJECT"]}`];
Deno.env.set(
"DENO_DEPLOY_TOKEN",
getEnv(
"DENO_DEPLOY_TOKEN",
true,
"A Deno Deploy token is required.\n\nGo to https://dash.deno.com/account#access-tokens to get one and set DENO_DEPLOY_TOKEN.",
),
);

if (env["PLUGIN_DENO_DEPLOY_TOKEN"]) {
flags.push(`--token=${env["PLUGIN_DENO_DEPLOY_TOKEN"]}`);
}
let temp: string = getEnv("Project", true, "An entrypoint is required");
const flags = [`-p=${temp}`];

if (env["PLUGIN_EXCLUDE"]) {
flags.push(`--exclude=${env["PLUGIN_EXCLUDE"]}`);
temp = getEnv("EXCLUDE");
if (temp) {
flags.push(`--exclude=${temp}`);
}

if (env["PLUGIN_INCLUDE"]) {
flags.push(`--include=${env["PLUGIN_INCLUDE"]}`);
temp = getEnv("INCLUDE");
if (temp) {
flags.push(`--include=${temp}`);
}

if (env["PLUGIN_IMPORT_MAP"]) {
flags.push(`--import-map=${env["PLUGIN_IMPORT_MAP"]}`);
temp = getEnv("IMPORT_MAP");
if (temp) {
flags.push(`--import-map=${temp}`);
}

if (env["PLUGIN_NO_STATIC"]) {
if (getEnv("NO_STATIC")) {
flags.push(`--no-static`);
}

if (env["PLUGIN_PROD"] || env["PLUGIN_PRODUCTION"]) {
if (getEnv("PRODUCTION") || getEnv("PROD")) {
flags.push(`--prod`);
}

if (env["PLUGIN_DRY_RUN"]) {
if (getEnv("DRY_RUN")) {
flags.push(`--dry-run`);
}

console.log("Deploying to Deno Deploy......");

const prog = Deno.run({
cmd: [
"deployctl",
const command = new Deno.Command("deployctl", {
args: [
"deploy",
...flags,
env["PLUGIN_ENTRYPOINT"],
getEnv("ENTRYPOINT", true, "An entrypoint is required"),
],
stdout: "piped",
stderr: "piped",
});

const process = command.spawn();
process.stdout.pipeTo(Deno.stdout.writable);
process.stderr.pipeTo(Deno.stderr.writable);

copy(prog.stdout, Deno.stdout);
copy(prog.stderr, Deno.stderr);

const status = await prog.status()

prog.close();
const { success } = await process.status;

if (!status.success) {
if (!success) {
console.error("Deno Deploy failed!");
Deno.exit(1);
}

0 comments on commit c8aa478

Please sign in to comment.