-
Notifications
You must be signed in to change notification settings - Fork 0
159 lines (126 loc) · 5.39 KB
/
Copy pathmaintain-test-workflows.yml
File metadata and controls
159 lines (126 loc) · 5.39 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
156
157
158
159
name: Maintain Test Workflows
on:
schedule:
- cron: '0 0 * * 1' # Every Monday at 00:00 UTC (09:00 KST)
workflow_dispatch:
push:
paths:
- '.github/templates/test-ccs-template.yml'
permissions:
contents: write
jobs:
sync-workflows:
name: Sync Workflow Files
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
token: ${{ secrets.PAT_TOKEN }}
fetch-depth: 0
- name: Discover Versions from GitHub Releases
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "=== Fetching releases from uoohyo/action-ccstudio-ide ==="
gh api repos/uoohyo/action-ccstudio-ide/releases \
--paginate \
--jq '.[].tag_name' \
| grep -E '^v[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' \
| sed 's/^v//' \
| sort -V > /tmp/all_versions.txt
TOTAL_COUNT=$(wc -l < /tmp/all_versions.txt)
echo "Total versions found: $TOTAL_COUNT"
- name: Find Existing Workflows
run: |
echo "=== Scanning existing workflow files ==="
if ls .github/workflows/test-ccs-v*.yml 1> /dev/null 2>&1; then
ls .github/workflows/test-ccs-v*.yml \
| sed 's|.github/workflows/test-ccs-v||; s|.yml||' \
| sort -V > /tmp/existing_versions.txt
else
touch /tmp/existing_versions.txt
fi
EXISTING_COUNT=$(wc -l < /tmp/existing_versions.txt)
echo "Existing workflow files: $EXISTING_COUNT"
- name: Calculate Differences
run: |
echo "=== Calculating differences ==="
# Ensure consistent sorting for comm
export LC_ALL=C
sort /tmp/all_versions.txt -o /tmp/all_versions_sorted.txt
sort /tmp/existing_versions.txt -o /tmp/existing_versions_sorted.txt
# New versions (in releases but not in workflows)
comm -23 /tmp/all_versions_sorted.txt /tmp/existing_versions_sorted.txt > /tmp/new_versions.txt
# Removed versions (in workflows but not in releases)
comm -13 /tmp/all_versions_sorted.txt /tmp/existing_versions_sorted.txt > /tmp/removed_versions.txt
NEW_COUNT=$(wc -l < /tmp/new_versions.txt)
REMOVED_COUNT=$(wc -l < /tmp/removed_versions.txt)
echo "New versions to add: $NEW_COUNT"
if [ "$NEW_COUNT" -gt 0 ]; then
echo "New versions:"
cat /tmp/new_versions.txt
fi
echo "Versions to remove: $REMOVED_COUNT"
if [ "$REMOVED_COUNT" -gt 0 ]; then
echo "Versions to remove:"
cat /tmp/removed_versions.txt
fi
- name: Generate Workflows for New Versions
run: |
echo "=== Generating workflow files for new versions ==="
NEW_COUNT=$(wc -l < /tmp/new_versions.txt)
if [ "$NEW_COUNT" -eq 0 ]; then
echo "No new versions to add"
exit 0
fi
while IFS= read -r version; do
[ -z "$version" ] && continue
echo "Creating workflow for v${version}..."
sed "s/{{VERSION}}/${version}/g" \
.github/templates/test-ccs-template.yml \
> .github/workflows/test-ccs-v${version}.yml
echo "✅ Created: .github/workflows/test-ccs-v${version}.yml"
done < /tmp/new_versions.txt
- name: Update Existing Workflows from Template
run: |
echo "=== Updating all existing workflows from template ==="
while IFS= read -r version; do
[ -z "$version" ] && continue
echo "Updating workflow for v${version}..."
sed "s/{{VERSION}}/${version}/g" \
.github/templates/test-ccs-template.yml \
> .github/workflows/test-ccs-v${version}.yml
echo "✅ Updated: .github/workflows/test-ccs-v${version}.yml"
done < /tmp/all_versions.txt
- name: Remove Workflows for Deleted Versions
run: |
echo "=== Removing workflow files for deleted versions ==="
REMOVED_COUNT=$(wc -l < /tmp/removed_versions.txt)
if [ "$REMOVED_COUNT" -eq 0 ]; then
echo "No versions to remove"
exit 0
fi
while IFS= read -r version; do
[ -z "$version" ] && continue
echo "Removing workflow for v${version}..."
rm -f .github/workflows/test-ccs-v${version}.yml
echo "✅ Removed: .github/workflows/test-ccs-v${version}.yml"
done < /tmp/removed_versions.txt
- name: Commit and Push Changes
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .github/workflows/test-ccs-v*.yml
if git diff --staged --quiet; then
echo "No changes to commit"
else
NEW_COUNT=$(wc -l < /tmp/new_versions.txt)
REMOVED_COUNT=$(wc -l < /tmp/removed_versions.txt)
COMMIT_MSG="🤖 sync: update test workflows"
[ "$NEW_COUNT" -gt 0 ] && COMMIT_MSG="$COMMIT_MSG (+${NEW_COUNT})"
[ "$REMOVED_COUNT" -gt 0 ] && COMMIT_MSG="$COMMIT_MSG (-${REMOVED_COUNT})"
git commit -m "$COMMIT_MSG"
git push
echo "✅ Successfully synced $NEW_COUNT new and removed $REMOVED_COUNT old workflow files"
fi