-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-github-workflow.sh
More file actions
executable file
·143 lines (120 loc) · 4.18 KB
/
Copy pathtest-github-workflow.sh
File metadata and controls
executable file
·143 lines (120 loc) · 4.18 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash
# Script to test the GitHub Actions workflow
# This script will actually trigger the workflow and monitor its execution
echo "=== GitHub Actions Workflow Tester ==="
echo "This script will test the actual CI/CD workflow"
echo ""
# Check if GitHub CLI is available
if ! command -v gh &> /dev/null; then
echo "❌ GitHub CLI (gh) is not installed"
echo "Please install it: https://github.com/cli/cli#installation"
exit 1
fi
# Check if we're authenticated
if ! gh auth status &> /dev/null; then
echo "❌ Not authenticated with GitHub CLI"
echo "Please run: gh auth login"
exit 1
fi
echo "✅ GitHub CLI is available and authenticated"
echo ""
# Get repository information
REPO=$(gh repo view --json nameWithOwner -q .nameWithOwner)
echo "Repository: $REPO"
echo ""
echo "=== Testing Options ==="
echo "1. Test workflow validation (safe - no deployment)"
echo "2. Test main CI/CD workflow (will actually deploy!)"
echo "3. Check workflow status"
echo "4. View recent workflow runs"
echo ""
read -p "Choose an option (1-4): " choice
case $choice in
1)
echo ""
echo "=== Running Workflow Validation Test ==="
echo "This will run the validation workflow that tests configuration without deploying"
echo ""
# Trigger the test workflow
echo "Triggering test workflow..."
run_id=$(gh workflow run test-workflow.yml --json id -q .id 2>/dev/null)
if [ $? -eq 0 ]; then
echo "✅ Test workflow triggered successfully"
echo "Run ID: $run_id"
echo ""
echo "Waiting for workflow to start..."
sleep 5
echo "Monitoring workflow execution..."
gh run watch $run_id
else
echo "❌ Failed to trigger test workflow"
echo "Make sure the test-workflow.yml file exists and is valid"
fi
;;
2)
echo ""
echo "⚠️ WARNING: This will trigger the actual CI/CD workflow!"
echo "This will build, package, and deploy your application to Kubernetes"
echo ""
read -p "Are you sure you want to proceed? (y/N): " confirm
if [[ $confirm =~ ^[Yy]$ ]]; then
echo ""
echo "=== Running Main CI/CD Workflow ==="
echo "Triggering CI/CD pipeline..."
# Trigger the main workflow
run_id=$(gh workflow run ci-cd.yml --json id -q .id 2>/dev/null)
if [ $? -eq 0 ]; then
echo "✅ CI/CD workflow triggered successfully"
echo "Run ID: $run_id"
echo ""
echo "Monitoring workflow execution..."
gh run watch $run_id
else
echo "❌ Failed to trigger CI/CD workflow"
echo "Check the workflow configuration and try again"
fi
else
echo "Cancelled."
fi
;;
3)
echo ""
echo "=== Workflow Status ==="
echo "Checking current workflow runs..."
echo ""
gh run list --limit 5 --json status,conclusion,workflowName,createdAt,url \
--template '{{range .}}{{.workflowName}} - {{.status}} {{if .conclusion}}({{.conclusion}}){{end}} - {{timeago .createdAt}} - {{.url}}
{{end}}'
;;
4)
echo ""
echo "=== Recent Workflow Runs ==="
echo "Last 10 workflow runs:"
echo ""
gh run list --limit 10
echo ""
read -p "Enter a run ID to view details (or press Enter to skip): " run_id
if [[ -n "$run_id" ]]; then
echo ""
echo "=== Workflow Run Details ==="
gh run view $run_id
fi
;;
*)
echo "Invalid option. Exiting."
exit 1
;;
esac
echo ""
echo "=== Additional Commands ==="
echo "To manually trigger workflows:"
echo " gh workflow run ci-cd.yml"
echo " gh workflow run test-workflow.yml"
echo ""
echo "To watch a specific run:"
echo " gh run watch <run-id>"
echo ""
echo "To view workflow logs:"
echo " gh run view <run-id> --log"
echo ""
echo "=== End of Test Script ==="