-
Notifications
You must be signed in to change notification settings - Fork 1.6k
72 lines (59 loc) · 1.65 KB
/
slugify.yaml
File metadata and controls
72 lines (59 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
name: Generate Branch Slug
on:
workflow_call:
inputs:
value:
description: 'Value to slugify'
required: true
type: string
outputs:
slug:
description: 'Slugified value'
value: ${{ jobs.generate-slug.outputs.slug }}
jobs:
generate-slug:
runs-on: ubuntu-latest
outputs:
slug: ${{ steps.slugify.outputs.slug }}
steps:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Generate slug
id: slugify
run: |
# Create working directory
mkdir -p $HOME/slugify
cd $HOME/slugify
# Create Go script
cat > main.go << 'EOF'
package main
import (
"fmt"
"os"
"github.com/gosimple/slug"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("Usage: slugify <text>")
os.Exit(1)
}
text := os.Args[1]
slugged := slug.Make(text)
fmt.Println(slugged)
}
EOF
# Initialize module and install dependency
go mod init slugify
go mod tidy
go get github.com/gosimple/slug
# Build
go build -o slugify main.go
# Generate slug
VALUE="${{ inputs.value }}"
echo "Input value: $VALUE"
SLUG=$(./slugify "$VALUE")
echo "Generated slug: $SLUG"
# Export
echo "slug=$SLUG" >> $GITHUB_OUTPUT