Consolidated actions and variables

This commit is contained in:
2026-04-11 20:58:04 -05:00
parent f9e8eeab45
commit 8da0525491
4 changed files with 98 additions and 40 deletions

View File

@@ -8,25 +8,12 @@ inputs:
slug:
required: true
description: Branch slug to clean up
pangolin-api-url:
required: true
description: Base URL for the Pangolin API (https://api.pangolin.local)
pangolin-api-key:
required: true
description: Pangolin API key
pangolin-org-id:
required: true
description: Pangolin organization ID
runs:
using: composite
steps:
- name: Remove Pangolin resource
shell: bash
env:
PANGOLIN_API_URL: ${{ inputs.pangolin-api-url }}
PANGOLIN_API_KEY: ${{ inputs.pangolin-api-key }}
PANGOLIN_ORG_ID: ${{ inputs.pangolin-org-id }}
run: |
bash ${{ github.action_path }}/../scripts/pangolin-delete.sh \
--resource-name "${{ inputs.app-name }}-${{ inputs.slug }}"
@@ -37,4 +24,4 @@ runs:
CONTAINER="${{ inputs.app-name }}-${{ inputs.slug }}"
docker stop "$CONTAINER" 2>/dev/null || true
docker rm "$CONTAINER" 2>/dev/null || true
docker rmi "${{ inputs.app-name }}:${{ inputs.slug }}" 2>/dev/null || true
docker rmi "${{ inputs.app-name }}:${{ inputs.slug }}" 2>/dev/null || true

View File

@@ -17,32 +17,14 @@ inputs:
description: Port the app listens on inside the container
environment:
required: true
description: Node environment name ("production" or "preview")
description: Environment name ("production" or "preview")
subdomain:
required: true
description: Subdomain for Pangolin resource
target-ip:
required: true
description: Target IP for Pangolin
build-args:
required: false
default: ""
description: Extra docker build args (space-separated KEY=VALUE pairs)
pangolin-api-url:
required: true
description: Base URL for the Pangolin API (https://api.pangolin.local)
pangolin-api-key:
required: true
description: Pangolin API key
pangolin-org-id:
required: true
description: Pangolin organization ID
pangolin-domain-id:
required: true
description: Pangolin domain ID
pangolin-site-id:
required: true
description: Pangolin site ID
runs:
using: composite
@@ -71,15 +53,9 @@ runs:
- name: Register Pangolin resource
shell: bash
env:
PANGOLIN_API_URL: ${{ inputs.pangolin-api-url }}
PANGOLIN_API_KEY: ${{ inputs.pangolin-api-key }}
PANGOLIN_ORG_ID: ${{ inputs.pangolin-org-id }}
PANGOLIN_DOMAIN_ID: ${{ inputs.pangolin-domain-id }}
PANGOLIN_SITE_ID: ${{ inputs.pangolin-site-id }}
run: |
bash ${{ github.action_path }}/../scripts/pangolin-upsert.sh \
--subdomain "${{ inputs.subdomain }}" \
--port "${{ inputs.port }}" \
--resource-name "${{ inputs.app-name }}-${{ inputs.tag }}" \
--target-ip "${{ inputs.target-ip }}"
--target-ip "$PANGOLIN_TARGET_IP"

68
example-deploy.yml Normal file
View File

@@ -0,0 +1,68 @@
name: Deploy
on:
push:
branches: ["main", "**"]
delete:
env:
PANGOLIN_API_URL: ${{ secrets.PANGOLIN_API_URL }}
PANGOLIN_API_KEY: ${{ secrets.PANGOLIN_API_KEY }}
PANGOLIN_ORG_ID: ${{ secrets.PANGOLIN_ORG_ID }}
PANGOLIN_DOMAIN_ID: ${{ secrets.PANGOLIN_DOMAIN_ID }}
PANGOLIN_SITE_ID: ${{ secrets.PANGOLIN_SITE_ID }}
PANGOLIN_TARGET_IP: ${{ secrets.PANGOLIN_TARGET_IP }}
jobs:
deploy-production:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: zyrrus/node-deploy-action/deploy@v1
with:
app-name: ${{ vars.APP_NAME }}
tag: production
port: ${{ vars.PROD_PORT }}
environment: production
subdomain: ${{ vars.PROD_SUBDOMAIN }}
deploy-preview:
if: github.event_name == 'push' && github.ref != 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Compute preview slug
id: slug
uses: zyrrus/node-deploy-action/slug@v1
with:
branch: ${{ github.ref_name }}
- uses: zyrrus/node-deploy-action/deploy@v1
with:
app-name: ${{ vars.APP_NAME }}
tag: ${{ steps.slug.outputs.slug }}
port: ${{ steps.slug.outputs.port }}
environment: preview
subdomain: ${{ steps.slug.outputs.slug }}.${{ vars.APP_NAME }}
cleanup-preview:
if: github.event_name == 'delete' && github.event.ref_type == 'branch'
runs-on: ubuntu-latest
steps:
- name: Compute preview slug
id: slug
uses: zyrrus/node-deploy-action/slug@v1
with:
branch: ${{ github.event.ref }}
- uses: actions/checkout@v4
with:
ref: main
- uses: zyrrus/node-deploy-action/cleanup@v1
with:
app-name: ${{ vars.APP_NAME }}
slug: ${{ steps.slug.outputs.slug }}

27
slug/action.yml Normal file
View File

@@ -0,0 +1,27 @@
name: Compute Preview Slug
description: Derive a URL-safe slug and deterministic port from a branch name
inputs:
branch:
required: true
description: Branch name to slugify
outputs:
slug:
description: URL-safe branch slug
value: ${{ steps.compute.outputs.slug }}
port:
description: Deterministic port derived from the slug
value: ${{ steps.compute.outputs.port }}
runs:
using: composite
steps:
- name: Compute slug and port
id: compute
shell: bash
run: |
SLUG=$(echo "${{ inputs.branch }}" | tr '/' '-' | tr '_' '-' | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9-]//g' | cut -c1-40)
echo "slug=$SLUG" >> "$GITHUB_OUTPUT"
PORT=$(( 20000 + ( $(echo -n "$SLUG" | cksum | awk '{print $1}') % 10000 ) ))
echo "port=$PORT" >> "$GITHUB_OUTPUT"