Signed-off-by: Sam Therapy <sam@samtherapy.net>
This commit is contained in:
parent
10d17ae2f6
commit
c8aa478c88
9 changed files with 122 additions and 95 deletions
40
.drone.yml
40
.drone.yml
|
@ -1,40 +0,0 @@
|
|||
kind: pipeline
|
||||
name: PR
|
||||
type: docker
|
||||
|
||||
steps:
|
||||
- name: Build
|
||||
image: plugins/docker
|
||||
depends_on:
|
||||
- "clone"
|
||||
settings:
|
||||
repo: git.froth.zone/sam/drone-deno-deploy
|
||||
dry_run: true
|
||||
when:
|
||||
event:
|
||||
- pull_request
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
name: Push
|
||||
type: docker
|
||||
|
||||
steps:
|
||||
- name: Build & Publish
|
||||
depends_on:
|
||||
- "clone"
|
||||
image: plugins/docker
|
||||
settings:
|
||||
registry: git.froth.zone
|
||||
username: sam
|
||||
password:
|
||||
from_secret: password
|
||||
repo: git.froth.zone/sam/drone-deno-deploy
|
||||
tags: latest
|
||||
when:
|
||||
branch:
|
||||
- master
|
||||
event:
|
||||
- push
|
||||
depends_on:
|
||||
- "clone"
|
4
README.md → .github/README.md
vendored
4
README.md → .github/README.md
vendored
|
@ -1,6 +1,6 @@
|
|||
# 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
|
||||
|
@ -8,7 +8,7 @@ to deploy a JavaScript/TypeScript application to
|
|||
|
||||
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)
|
37
.github/workflows/build.yaml
vendored
Normal file
37
.github/workflows/build.yaml
vendored
Normal file
|
@ -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
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -1,3 +0,0 @@
|
|||
[submodule "example"]
|
||||
path = example
|
||||
url = ../drone-deploy-example
|
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"deno.enable": true,
|
||||
"deno.unstable": true,
|
||||
"deno.lint": true
|
||||
}
|
33
action.yaml
Normal file
33
action.yaml
Normal file
|
@ -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
deno.json
Normal file
5
deno.json
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"imports": {
|
||||
"std/": "https://deno.land/std@0.220.1/"
|
||||
}
|
||||
}
|
1
example
1
example
|
@ -1 +0,0 @@
|
|||
Subproject commit c1d62aac006148041dac7187d7f08a93aa2e6e25
|
89
run.ts
89
run.ts
|
@ -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(
|
||||
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 "";
|
||||
}
|
||||
|
||||
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.",
|
||||
);
|
||||
Deno.exit(1);
|
||||
),
|
||||
);
|
||||
|
||||
let temp: string = getEnv("Project", true, "An entrypoint is required");
|
||||
const flags = [`-p=${temp}`];
|
||||
|
||||
temp = getEnv("EXCLUDE");
|
||||
if (temp) {
|
||||
flags.push(`--exclude=${temp}`);
|
||||
}
|
||||
|
||||
if (!env["PLUGIN_ENTRYPOINT"]) {
|
||||
console.error("An entrypoint is required");
|
||||
Deno.exit(1);
|
||||
temp = getEnv("INCLUDE");
|
||||
if (temp) {
|
||||
flags.push(`--include=${temp}`);
|
||||
}
|
||||
|
||||
if (!env["PLUGIN_PROJECT"]) {
|
||||
console.error("An project is required");
|
||||
Deno.exit(1);
|
||||
temp = getEnv("IMPORT_MAP");
|
||||
if (temp) {
|
||||
flags.push(`--import-map=${temp}`);
|
||||
}
|
||||
|
||||
const flags = [`-p=${env["PLUGIN_PROJECT"]}`];
|
||||
|
||||
if (env["PLUGIN_DENO_DEPLOY_TOKEN"]) {
|
||||
flags.push(`--token=${env["PLUGIN_DENO_DEPLOY_TOKEN"]}`);
|
||||
}
|
||||
|
||||
if (env["PLUGIN_EXCLUDE"]) {
|
||||
flags.push(`--exclude=${env["PLUGIN_EXCLUDE"]}`);
|
||||
}
|
||||
|
||||
if (env["PLUGIN_INCLUDE"]) {
|
||||
flags.push(`--include=${env["PLUGIN_INCLUDE"]}`);
|
||||
}
|
||||
|
||||
if (env["PLUGIN_IMPORT_MAP"]) {
|
||||
flags.push(`--import-map=${env["PLUGIN_IMPORT_MAP"]}`);
|
||||
}
|
||||
|
||||
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 { success } = await process.status;
|
||||
|
||||
const status = await prog.status()
|
||||
|
||||
prog.close();
|
||||
|
||||
if (!status.success) {
|
||||
if (!success) {
|
||||
console.error("Deno Deploy failed!");
|
||||
Deno.exit(1);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue