Skip to content

Commit

Permalink
Create dynamic-scheduled-fork-maintenance.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Cemberk authored Aug 6, 2024
1 parent e58394e commit 144d022
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/dynamic-scheduled-fork-maintenance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Dynamic Schedule Workflow

on:
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: |
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 }}

0 comments on commit 144d022

Please sign in to comment.