-
Notifications
You must be signed in to change notification settings - Fork 85
66 lines (57 loc) · 2.74 KB
/
ci_deprecate.yml
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
name: Deprecate Notebook
on:
workflow_dispatch:
inputs:
notebook_name:
description: 'The name of the notebook to deprecate (e.g., example.ipynb)'
required: true
default: 'example.ipynb'
jobs:
deprecate:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Find notebook path
id: find_path
run: |
NOTEBOOK_NAME="${{ github.event.inputs.notebook_name }}"
NOTEBOOK_PATH=$(find ./notebooks -name "$NOTEBOOK_NAME" -type f)
if [ -z "$NOTEBOOK_PATH" ]; then
echo "::error::Notebook '${NOTEBOOK_NAME}' not found in the notebooks directory."
exit 1
fi
echo "notebook_path=$NOTEBOOK_PATH" >> $GITHUB_ENV
# - name: Check for deprecated tag
# id: check_deprecated
# run: |
# notebook_path="${{ env.notebook_path }}"
# if jq '.metadata.deprecated == true' "$notebook_path"; then
# echo "::error::Notebook '${{ env.notebook_path }}' is already flagged as deprecated."
# exit 0
# fi
- name: Add deprecated tag with timestamp and removal date
run: |
notebook_path="${{ env.notebook_path }}"
timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
removal_date=$(date -u -d "$timestamp + 30 days" +"%Y-%m-%dT%H:%M:%SZ")
jq --arg ts "$timestamp" --arg rd "$removal_date" \
'.metadata.deprecated = { "status": true, "timestamp": $ts, "removal_date": $rd }' \
"$notebook_path" > temp.ipynb && mv temp.ipynb "$notebook_path"
- name: Add deprecation banner with timestamp and removal date
run: |
notebook_path="${{ env.notebook_path }}"
timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
removal_date=$(date -u -d "$timestamp + 30 days" +"%Y-%m-%d")
BANNER_CELL=$(jq -n \
--arg text "<div style='border: 3px solid red; padding: 10px; text-align: center; font-weight: bold; color: red;'>⚠️ This notebook is scheduled for deprecation as of $timestamp and is planned for removal by $removal_date. Future use is discouraged.</div>" \
'{"cell_type": "markdown", "metadata": {"deprecation": true}, "source": [$text]}')
jq ".cells |= [$BANNER_CELL] + ." "$notebook_path" > temp.ipynb && mv temp.ipynb "$notebook_path"
- name: Commit and push to gh-storage branch
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
git checkout -B gh-storage
git add "${{ env.notebook_path }}"
git commit -m "Deprecate notebook ${{ env.notebook_path }}"
git push origin gh-storage --force