27 lines
832 B
YAML
27 lines
832 B
YAML
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" |