Move Deprecated Notebooks #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Move Deprecated Notebooks | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 3 * * *' # Runs daily at 3 AM UTC | |
jobs: | |
check_and_move: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
ref: gh-storage # Start from the gh-storage branch | |
- name: Set up date variables | |
id: date_setup | |
run: | | |
CURRENT_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") | |
echo "current_date=$CURRENT_DATE" >> $GITHUB_ENV | |
- name: Find all deprecated notebooks | |
id: find_deprecated | |
run: | | |
# Find all notebooks with the deprecation flag set | |
DEPRECATED_NOTEBOOKS=$(find ./notebooks -name "*.ipynb" -exec jq -r 'select(.metadata.deprecated.status == true) | input_filename' {} \;) | |
if [ -z "$DEPRECATED_NOTEBOOKS" ]; then | |
echo "No deprecated notebooks found." | |
exit 0 | |
fi | |
echo "deprecated_notebooks=$DEPRECATED_NOTEBOOKS" >> $GITHUB_ENV | |
- name: Process deprecated notebooks | |
run: | | |
current_date="${{ env.current_date }}" | |
deprecated_notebooks="${{ env.deprecated_notebooks }}" | |
for notebook_path in $deprecated_notebooks; do | |
# Extract the removal date from the notebook metadata | |
removal_date=$(jq -r '.metadata.deprecated.removal_date' "$notebook_path") | |
# Check if the current date is past the removal date | |
if [[ "$current_date" > "$removal_date" ]]; then | |
echo "Notebook $notebook_path is past the deprecation date ($removal_date). Moving to 'deprecated' branch." | |
# Determine the notebook's directory | |
notebook_dir=$(dirname "$notebook_path") | |
else | |
echo "Notebook $notebook_path is not past the deprecation date ($removal_date)." | |
fi | |
done | |
# Checkout deprecated branch | |
git fetch origin deprecated | |
git checkout deprecated || git checkout -b deprecated | |
# Move the entire folder to the deprecated branch | |
git mv "$notebook_dir" . | |
# Commit changes on deprecated branch | |
git add . | |
git commit -m "Moved deprecated notebook $notebook_path to deprecated branch" | |
# Push changes to the deprecated branch | |
git push origin deprecated | |
# Checkout main branch | |
git checkout main | |
# Remove the folder from main | |
git rm -r "$notebook_dir" | |
# Commit changes on main branch | |
git add . | |
git commit -m "Removed deprecated notebook $notebook_path from main branch" | |
# Push changes to the main branch | |
git push origin main | |
# Return to gh-storage branch | |
git checkout gh-storage | |
else | |
echo "Notebook $notebook_path is not past the deprecation date ($removal_date)." | |
fi | |
done |