forked from ROCm/transformers
-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (95 loc) · 3.87 KB
/
dynamic-scheduled-fork-maintenance.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
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
name: Dynamic Schedule Workflow
on:
workflow_dispatch:
schedule:
- cron: '0 * * * *' # Runs every hour
jobs:
schedule_job:
runs-on: ubuntu-latest
env:
SCHEDULE_CONFIG: ${{ secrets.SCHEDULE_CONFIG }} # Secret storing the schedule JSON
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Read schedule configuration
id: read_config
run: |
echo "${{ env.SCHEDULE_CONFIG }}" > schedule.json
- name: Parse and use schedule data
id: parse_schedule
run: |
cat <<EOF > schedule.json
{
"events": [
{
"name": "weekly_backup",
"upstream_main_branch": "main",
"upstream_release_branch": "v4.43-release",
"downstream_testing_branch": "rocm6.3_testing_rel4.43_testing",
"downstream_develop_branch": "develop",
"commits": [
"731f0308bb0a2796e28b68664f4ed050eab6dbfd",
"0c1b311bff616a4faf214461584a758fbab14a6f",
"5b2d4fec5abb8ffe755fe66ce0856fc066c561a6"
],
"branching_date": "2024-08-07T00:00:00Z",
"last_run": "2024-08-09T00:00:00Z"
},
{
"name": "monthly_update",
"upstream_main_branch": "main",
"upstream_release_branch": "v4.44-release",
"downstream_testing_branch": "rocm6.3_testing_rel4.44_testing",
"downstream_develop_branch": "develop",
"commits": [
"731f0308bb0a2796e28b68664f4ed050eab6dbfd",
"0c1b311bff616a4faf214461584a758fbab14a6f",
"5b2d4fec5abb8ffe755fe66ce0856fc066c561a6"
],
"branching_date": "2024-08-15T00:00:00Z",
"last_run": "2024-07-15T00:00:00Z"
}
]
}
EOF
SCHEDULE_FILE="schedule.json"
SCHEDULE=$(cat $SCHEDULE_FILE)
echo "Schedule: $SCHEDULE"
# Loop through each event in the schedule
for row in $(jq -c '.events[]' $SCHEDULE_FILE); do
NAME=$(echo $row | jq -r '.name')
LAST_RUN=$(echo $row | jq -r '.last_run')
BRANCHING_DATE=$(echo $row | jq -r '.branching_date')
# Get the current date
CURRENT_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
if [[ "$CURRENT_DATE" > "$BRANCHING_DATE" && "$LAST_RUN" < "$BRANCHING_DATE" ]]; then
echo "Event $NAME needs to run. Last run: $LAST_RUN, Branching date: $BRANCHING_DATE, Current date: $CURRENT_DATE"
echo "::set-output name=event::$NAME"
SCHEDULE_JSON=$(echo $row | jq -c '{upstream_main_branch, upstream_release_branch, downstream_testing_branch, downstream_develop_branch, commits}')
echo "::set-output name=schedule_json::$SCHEDULE_JSON"
break
fi
done
- name: Fork Maintenance System
if: steps.parse_schedule.outputs.event != ''
uses: Cemberk/Fork-Maintenance-System@main
with:
github_token: ${{ secrets.CRED_TOKEN }}
upstream_repo: "https://github.com/huggingface/transformers"
schedule_json: ${{ steps.parse_schedule.outputs.schedule_json }}
pr_branch_prefix: "scheduled-merge"
unit_test_command: "your-unit-test-command"
performance_test_command: "your-performance-test-command"
- name: Remove completed event from schedule
if: success() && steps.parse_schedule.outputs.event != ''
run: |
SCHEDULE_FILE=schedule.json
EVENT_NAME=${{ steps.parse_schedule.outputs.event }}
jq 'del(.events[] | select(.name == "'$EVENT_NAME'"))' $SCHEDULE_FILE > tmp.$$.json && mv tmp.$$.json $SCHEDULE_FILE
- name: Update secret with new schedule configuration
if: success() && steps.parse_schedule.outputs.event != ''
run: |
SCHEDULE_JSON=$(cat schedule.json)
gh secret set SCHEDULE_CONFIG --body "$SCHEDULE_JSON"
env:
GITHUB_TOKEN: ${{ secrets.CRED_TOKEN }}