1+ #! /bin/bash
2+
3+ # Dummy inputs simulating GitHub Actions
4+ TARGET_LABEL=" deploy"
5+ BRANCH_PREFIX=" "
6+ CURRENT_BRANCH=" release/1/dev"
7+
8+ # This is the dummy value for ${{ inputs.labels }}
9+ # In GitHub Actions, this comes from the workflow inputs
10+ # Here we're simulating it with a variable
11+ INPUT_LABELS=' [
12+ {
13+ "color": "d73a4a",
14+ "default": true,
15+ "description": "Something isn' \' ' t working",
16+ "id": 9778996043,
17+ "name": "bug",
18+ "node_id": "LA_kwDOQje8Gc8AAAACRt-jSw",
19+ "url": "https://api.github.com/repos/wislertt/zerv-flow-demo-test/labels/bug"
20+ },
21+ {
22+ "color": "0075ca",
23+ "default": true,
24+ "description": "Improvements or additions to documentation",
25+ "id": 9778996045,
26+ "name": "documentation",
27+ "node_id": "LA_kwDOQje8Gc8AAAACRt-jTQ",
28+ "url": "https://api.github.com/repos/wislertt/zerv-flow-demo-test/labels/documentation"
29+ },
30+ {
31+ "color": "c5def5",
32+ "default": false,
33+ "description": "",
34+ "id": 9801717827,
35+ "name": "deploy-d",
36+ "node_id": "LA_kwDOQje8Gc8AAAACSDpYQw",
37+ "url": "https://api.github.com/repos/wislertt/zerv-flow-demo-test/labels/deploy-d"
38+ },
39+ {
40+ "color": "c5def5",
41+ "default": false,
42+ "description": "",
43+ "id": 9801718458,
44+ "name": "deploy-n",
45+ "node_id": "LA_kwDOQje8Gc8AAAACSDpaug",
46+ "url": "https://api.github.com/repos/wislertt/zerv-flow-demo-test/labels/deploy-n"
47+ },
48+ {
49+ "color": "c5def5",
50+ "default": false,
51+ "description": "",
52+ "id": 9804113951,
53+ "name": "deploy",
54+ "node_id": "LA_kwDOQje8Gc8AAAACSF7oHw",
55+ "url": "https://api.github.com/repos/wislertt/zerv-flow-demo-test/labels/deploy"
56+ }
57+ ]'
58+
59+ echo " Checking for label: $TARGET_LABEL "
60+ echo " Required branch prefix: $BRANCH_PREFIX "
61+ echo " Current branch: $CURRENT_BRANCH "
62+ echo " Input labels: $INPUT_LABELS "
63+
64+ # Check if branch has the required prefix
65+ if [ -n " $BRANCH_PREFIX " ]; then
66+ if [[ " $CURRENT_BRANCH " == " $BRANCH_PREFIX " * ]]; then
67+ echo " ✅ Branch prefix matches"
68+ HAS_BRANCH_PREFIX=true
69+ else
70+ echo " ❌ Branch prefix does not match"
71+ HAS_BRANCH_PREFIX=false
72+ fi
73+ else
74+ echo " ℹ️ No branch prefix requirement"
75+ HAS_BRANCH_PREFIX=true
76+ fi
77+
78+ # Simple approach: pass JSON to jq via stdin to avoid shell parsing
79+ # This is the key fix for handling JSON with special characters
80+ # Using printf with the INPUT_LABELS variable (simulating ${{ inputs.labels }})
81+ if printf ' %s\n' " $INPUT_LABELS " | \
82+ jq -e --arg target " $TARGET_LABEL " \
83+ ' .[] | select(.name == $target)' > /dev/null 2>&1 ; then
84+ HAS_LABEL=true
85+ else
86+ HAS_LABEL=false
87+ fi
88+
89+ echo " Has label: $HAS_LABEL "
90+
91+ # Create a dummy GITHUB_OUTPUT file for demonstration
92+ GITHUB_OUTPUT=" /tmp/github_output.txt"
93+
94+ # Output individual condition results
95+ echo " has_label=$HAS_LABEL " >> " $GITHUB_OUTPUT "
96+ echo " is_valid_branch=$HAS_BRANCH_PREFIX " >> " $GITHUB_OUTPUT "
97+
98+ # Both conditions must be true
99+ if [ " $HAS_LABEL " = " true" ] && [ " $HAS_BRANCH_PREFIX " = " true" ]; then
100+ echo " is_valid=true" >> " $GITHUB_OUTPUT "
101+ echo " ✅ Both label '$TARGET_LABEL ' and branch prefix '$BRANCH_PREFIX ' found"
102+ else
103+ echo " is_valid=false" >> " $GITHUB_OUTPUT "
104+ if [ " $HAS_LABEL " != " true" ]; then
105+ echo " ❌ Label '$TARGET_LABEL ' not found"
106+ else
107+ echo " ✅ Label '$TARGET_LABEL ' found"
108+ fi
109+ if [ " $HAS_BRANCH_PREFIX " != " true" ]; then
110+ echo " ❌ Branch prefix '$BRANCH_PREFIX ' not found"
111+ else
112+ echo " ✅ Branch prefix '$BRANCH_PREFIX ' found"
113+ fi
114+ fi
115+
116+ # No cleanup needed since we're using a variable now
117+
118+ # Display the outputs (simulating GitHub Actions outputs)
119+ echo " "
120+ echo " === GitHub Outputs ==="
121+ cat " $GITHUB_OUTPUT "
122+ rm -f " $GITHUB_OUTPUT "
0 commit comments