Repository navigation
Expand file tree
/
Copy pathverify-automation.sh
More file actions
executable file
Β·155 lines (138 loc) Β· 5.04 KB
/
Copy pathverify-automation.sh
File metadata and controls
executable file
Β·155 lines (138 loc) Β· 5.04 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
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
# GitHub Actions Automation Verification Script
# This script tests the core automation functionality without making any changes
echo "π GitHub Actions Automation Verification"
echo "========================================"
echo ""
# Check if we're in the right repository
if [ ! -f ".github/workflows/update-content.yml" ]; then
echo "β Error: Not in the correct repository or workflow file missing"
echo " Expected: .github/workflows/update-content.yml"
exit 1
fi
echo "β
Repository structure verified"
# Test 1: Check workflow file syntax
echo ""
echo "π Test 1: Workflow file validation"
echo "-----------------------------------"
if command -v python3 &> /dev/null; then
python3 -c "
import yaml
import sys
try:
with open('.github/workflows/update-content.yml', 'r') as f:
yaml.safe_load(f)
print('β
Workflow YAML syntax is valid')
except Exception as e:
print(f'β Workflow YAML syntax error: {e}')
sys.exit(1)
"
else
echo "β οΈ Python not available for YAML validation, skipping syntax check"
fi
# Test 2: Source repository accessibility (both courses)
echo ""
echo "π Test 2: Source repository accessibility"
echo "-----------------------------------------"
ANALYTICAL_SRC="https://raw.githubusercontent.com/DrBenjamin/Analytical-Skills-for-Business/main/Analytical_Skills_for_Business.html"
DATA_SCI_SRC="https://raw.githubusercontent.com/DrBenjamin/Data-Science-and-Data-Analytics/main/Data_Science_and_Data_Analytics.html"
for SRC in "$ANALYTICAL_SRC" "$DATA_SCI_SRC"; do
NAME=$(basename "$SRC")
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$SRC")
if [ "$HTTP_STATUS" = "200" ]; then
echo "β
$NAME accessible (HTTP $HTTP_STATUS)"
else
echo "β οΈ $NAME not accessible (HTTP $HTTP_STATUS) β if this file is optional it will simply be skipped by the workflow"
fi
done
# Test 3: Content download functionality (size + hash)
echo ""
echo "π Test 3: Content download functionality"
echo "----------------------------------------"
tmpdir=$(mktemp -d)
for SRC in "$ANALYTICAL_SRC" "$DATA_SCI_SRC"; do
NAME=$(basename "$SRC")
DEST="$tmpdir/$NAME"
curl -s "$SRC" -o "$DEST"
if [ -f "$DEST" ]; then
SIZE=$(wc -c < "$DEST")
if [ "$SIZE" -gt 800 ]; then
if command -v shasum &> /dev/null; then
HASH=$(shasum -a 256 "$DEST" | cut -d' ' -f1)
echo "β
$NAME downloaded ($SIZE bytes) sha256=$HASH"
else
echo "β
$NAME downloaded ($SIZE bytes)"
fi
else
echo "β οΈ $NAME downloaded but size seems small ($SIZE bytes)"
fi
else
echo "β οΈ Failed to download $NAME"
fi
done
rm -rf "$tmpdir"
# Test 4: Change detection logic (per course file)
echo ""
echo "π Test 4: Change detection simulation"
echo "-------------------------------------"
for PAIR in \
"${ANALYTICAL_SRC}::analytical-skills.html" \
"${DATA_SCI_SRC}::data-science-analytics.html"; do
SRC_URL="${PAIR%%::*}"
LOCAL_FILE="${PAIR##*::}"
BASENAME=$(basename "$SRC_URL")
echo ""
echo "βΆ Checking $LOCAL_FILE vs source $BASENAME"
curl -s "$SRC_URL" -o fresh.tmp || true
if [ ! -f fresh.tmp ]; then
echo "β οΈ Skipping $LOCAL_FILE (source fetch failed)"
continue
fi
if [ -f "$LOCAL_FILE" ]; then
if cmp -s fresh.tmp "$LOCAL_FILE"; then
echo "β
No change ($LOCAL_FILE)"
else
echo "π Would update ($LOCAL_FILE differs)"
if command -v diff &>/dev/null; then
echo "--- size comparison"
echo -n "current: "; wc -c < "$LOCAL_FILE"
echo -n "fresh: "; wc -c < fresh.tmp
fi
fi
else
echo "π $LOCAL_FILE missing locally (would be created)"
fi
rm -f fresh.tmp
done
# Test 5: GitHub Actions workflow permissions
echo ""
echo "π Test 5: Workflow permissions check"
echo "-------------------------------------"
if grep -q "contents: write" .github/workflows/update-content.yml; then
echo "β
Content write permissions configured"
else
echo "β οΈ Content write permissions may not be configured"
fi
if grep -q "pages: write" .github/workflows/update-content.yml; then
echo "β
Pages write permissions configured"
else
echo "β οΈ Pages write permissions may not be configured"
fi
# Summary
echo ""
echo "π Verification Summary"
echo "======================"
echo ""
echo "The automation should work automatically with:"
echo "β’ Daily scheduled updates (6 AM UTC)"
echo "β’ Manual triggering from GitHub Actions tab (multi-repo sync)"
echo "β’ Per-file change detection for two course HTML files"
echo "β’ Static landing page preserved (not auto-overwritten)"
echo ""
echo "No manual setup required for basic functionality!"
echo ""
echo "To manually trigger an update:"
echo "1. Go to: https://github.com/$(git remote get-url origin | sed 's/.*github.com[:/]//' | sed 's/.git$//')/actions"
echo "2. Click 'Update course contents and Deploy to GitHub Pages'"
echo "3. Click 'Run workflow' β 'Run workflow'"
echo ""