-
-
Notifications
You must be signed in to change notification settings - Fork 109
122 lines (106 loc) · 4.41 KB
/
sync-examples.yml
File metadata and controls
122 lines (106 loc) · 4.41 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
name: Sync Examples to SootUp-Examples
on:
push:
branches: [main, master]
paths: ['sootup.examples/**']
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
has_new: ${{ steps.detect.outputs.has_new }}
examples_list: ${{ steps.detect.outputs.examples_list }}
steps:
- name: Checkout SootUp
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Detect new example folders
id: detect
run: |
echo "=== Detecting new example folders ==="
# Get current example folders
if [ -d "sootup.examples" ]; then
find sootup.examples -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | sort > current_examples.txt
echo "Current examples:"
cat current_examples.txt
else
echo "No sootup.examples directory found"
touch current_examples.txt
fi
# Get previous example folders (from previous commit)
git show HEAD~1:sootup.examples --name-only 2>/dev/null | grep "/" | cut -d'/' -f1 | sort -u > previous_examples.txt || touch previous_examples.txt
echo "Previous examples:"
cat previous_examples.txt || echo "No previous examples found"
# Find new folders
comm -23 current_examples.txt previous_examples.txt > new_examples.txt
if [ -s new_examples.txt ]; then
echo "has_new=true" >> $GITHUB_OUTPUT
examples_json=$(cat new_examples.txt | jq -R -s -c 'split("\n")[:-1]')
echo "examples_list=$examples_json" >> $GITHUB_OUTPUT
echo "New examples found:"
cat new_examples.txt
else
echo "has_new=false" >> $GITHUB_OUTPUT
echo "No new examples found"
fi
sync-examples:
needs: detect-changes
if: needs.detect-changes.outputs.has_new == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout SootUp
uses: actions/checkout@v4
- name: Check if target repository exists
id: check-repo
run: |
if curl -s -f -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository_owner }}/SootUp-Examples" > /dev/null; then
echo "repo_exists=true" >> $GITHUB_OUTPUT
echo "Target repository exists"
else
echo "repo_exists=false" >> $GITHUB_OUTPUT
echo "Target repository does not exist or is not accessible"
fi
- name: Checkout SootUp-Examples Repository
uses: actions/checkout@v4
with:
repository: ${{ github.repository_owner }}/SootUp-Examples
token: ${{ secrets.GITHUB_TOKEN }}
path: examples-repo
ref: main
- name: Sync new examples
run: |
echo "=== Syncing new examples ==="
examples='${{ needs.detect-changes.outputs.examples_list }}'
echo "Examples to sync: $examples"
# Parse JSON array and sync each example
echo "$examples" | jq -r '.[]' | while read example; do
if [ -d "sootup.examples/$example" ]; then
echo "Copying example: $example"
cp -r "sootup.examples/$example" "examples-repo/$example"
echo "Successfully copied $example"
else
echo "Warning: Example folder $example not found"
fi
done
- name: Commit and push changes
run: |
cd examples-repo
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
# Check if there are changes to commit
if [ -n "$(git status --porcelain)" ]; then
git add .
# Create commit message
echo "Auto-sync new examples from SootUp" > commit_msg.txt
echo "" >> commit_msg.txt
echo "New examples added:" >> commit_msg.txt
echo '${{ needs.detect-changes.outputs.examples_list }}' | jq -r '.[]' | sed 's/^/- /' >> commit_msg.txt
echo "" >> commit_msg.txt
echo "Synced on: $(date)" >> commit_msg.txt
git commit -F commit_msg.txt
git push origin main
echo "Changes committed and pushed successfully"
else
echo "No changes to commit"
fi