From 8da05254913963e98c5eb21a7651158cc22fc9ed Mon Sep 17 00:00:00 2001 From: Zeke Abshire Date: Sat, 11 Apr 2026 20:58:04 -0500 Subject: [PATCH] Consolidated actions and variables --- cleanup/action.yml | 15 +--------- deploy/action.yml | 28 ++----------------- example-deploy.yml | 68 ++++++++++++++++++++++++++++++++++++++++++++++ slug/action.yml | 27 ++++++++++++++++++ 4 files changed, 98 insertions(+), 40 deletions(-) create mode 100644 example-deploy.yml create mode 100644 slug/action.yml diff --git a/cleanup/action.yml b/cleanup/action.yml index 3677dad..e4fefeb 100644 --- a/cleanup/action.yml +++ b/cleanup/action.yml @@ -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 \ No newline at end of file + docker rmi "${{ inputs.app-name }}:${{ inputs.slug }}" 2>/dev/null || true diff --git a/deploy/action.yml b/deploy/action.yml index f14b055..c3a95f2 100644 --- a/deploy/action.yml +++ b/deploy/action.yml @@ -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 }}" \ No newline at end of file + --target-ip "$PANGOLIN_TARGET_IP" diff --git a/example-deploy.yml b/example-deploy.yml new file mode 100644 index 0000000..d2576b5 --- /dev/null +++ b/example-deploy.yml @@ -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 }} diff --git a/slug/action.yml b/slug/action.yml new file mode 100644 index 0000000..c130cd5 --- /dev/null +++ b/slug/action.yml @@ -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" \ No newline at end of file