-
Notifications
You must be signed in to change notification settings - Fork 61
134 lines (106 loc) · 4.52 KB
/
remove_deleted_tutorials.yml
File metadata and controls
134 lines (106 loc) · 4.52 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
name: Remove Deleted Tutorials
on:
push:
branches: [ master ]
paths:
- '**.mlx'
permissions:
contents: write
jobs:
remove-deleted-files:
runs-on: self-hosted
steps:
- name: Checkout Source Repo
uses: actions/checkout@v4
with:
repository: '${{ github.repository_owner }}/COBRA.tutorials'
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Clone the destination repository
shell: bash
run: |
rm -rf cobratoolbox
echo "Cloning the destination repository: git@github.com:opencobra/cobratoolbox.git"
git clone --depth 1 --branch gh-pages "https://x-access-token:${{ secrets.DEST_REPO_TOKEN }}@github.com/opencobra/cobratoolbox.git"
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install Python dependencies
shell: bash
run: |
python -m pip install --upgrade pip
pip install beautifulsoup4
- name: Detect Deleted mlx Files
id: getDeletedFiles
shell: bash
run: |
echo "Looking for last sync commit..."
last_sync_commit=$(git log --grep="removed .pdf, .html and .m files" -n 1 --pretty=format:%H)
if [[ -z "$last_sync_commit" ]]; then
echo "No previous deletion sync commit found. Checking all history for deletions."
# Look back further for any sync commit
last_sync_commit=$(git log --grep="created .pdf, .mlx and .m files" -n 1 --pretty=format:%H)
fi
if [[ -z "$last_sync_commit" ]]; then
echo "No sync commit found. Cannot determine deletions. Exiting."
exit 0
fi
echo "Last sync commit: $last_sync_commit"
changed_status=$(git diff --name-status "$last_sync_commit"..HEAD -- '*.mlx' || true)
echo "Detected .mlx status rows (D/R only relevant for deletion):"
echo "$changed_status" | grep -E '^(D|R[0-9]+)\s' || echo "None"
deleted_files=$(echo "$changed_status" | awk -F '\t' '
$1 == "D" { print $2 }
$1 ~ /^R[0-9]+$/ { print $2 }
' | sort -u)
if [[ -z "$deleted_files" ]]; then
echo "No .mlx files deleted or renamed since last sync. Exiting."
exit 0
fi
deleted_files=$(echo "$deleted_files" | tr '\n' ' ')
echo "Found deleted files: $deleted_files"
echo "deleted_files=$deleted_files" >> "$GITHUB_ENV"
- name: Remove Deleted Files from Website
shell: bash
run: |
if [[ -z "${deleted_files:-}" ]]; then
echo "No files to delete. Skipping."
exit 0
fi
cd cobratoolbox
for file in $deleted_files; do
if [[ $file != "" ]]; then
echo "Processing deletion: $file"
# Remove only HTML file from website
HTML_FILE_NAME=$(basename "$file" .mlx).html
HTML_FILE_PATH="stable/tutorials/$(dirname "$file")/$HTML_FILE_NAME"
if [[ -f "$HTML_FILE_PATH" ]]; then
echo "Removing $HTML_FILE_PATH from website"
git rm "$HTML_FILE_PATH" || rm -f "$HTML_FILE_PATH"
else
echo "HTML file not found: $HTML_FILE_PATH"
fi
# Update index to remove entry and remove tutorial wrapper file
echo "Updating cobratoolbox index to remove deleted tutorial..."
python stable/remove_from_index.py "stable/tutorials/$(dirname "$file")/$HTML_FILE_NAME" || echo "Index update failed or script not found"
fi
done
cd ..
- name: Pushing the changes to website
shell: bash
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
cd cobratoolbox
# Add any remaining untracked deletions
git add -A
if git diff --cached --quiet && git diff --quiet; then
echo "No changes to commit in cobratoolbox"
else
git commit -m "Remove deleted tutorials from source repo" || echo "Commit failed"
git push "https://x-access-token:${{ secrets.DEST_REPO_TOKEN }}@github.com/opencobra/cobratoolbox.git" gh-pages
fi
cd ..
rm -rf cobratoolbox
echo "Deletion workflow completed."