diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index a0104d6..0000000 --- a/.drone.yml +++ /dev/null @@ -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" \ No newline at end of file diff --git a/README.md b/.github/README.md similarity index 79% rename from README.md rename to .github/README.md index aac90be..cd8d6bf 100644 --- a/README.md +++ b/.github/README.md @@ -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) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..cd13906 --- /dev/null +++ b/.github/workflows/build.yaml @@ -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 \ No newline at end of file diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index ca3b8db..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "example"] - path = example - url = ../drone-deploy-example diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 6efa375..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "deno.enable": true, - "deno.unstable": true, - "deno.lint": true -} diff --git a/action.yaml b/action.yaml new file mode 100644 index 0000000..c928060 --- /dev/null +++ b/action.yaml @@ -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 + + \ No newline at end of file diff --git a/deno.json b/deno.json new file mode 100644 index 0000000..8c064a2 --- /dev/null +++ b/deno.json @@ -0,0 +1,5 @@ +{ + "imports": { + "std/": "https://deno.land/std@0.220.1/" + } +} diff --git a/example b/example deleted file mode 160000 index c1d62aa..0000000 --- a/example +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c1d62aac006148041dac7187d7f08a93aa2e6e25 diff --git a/run.ts b/run.ts index d3c3aa8..ffc52f1 100755 --- a/run.ts +++ b/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); }