Skip to content

Commit

Permalink
Add daily schedule test action
Browse files Browse the repository at this point in the history
Trigger test action if wikitextprocessor is updated after the last
test.
  • Loading branch information
xxyzz committed Jan 3, 2024
1 parent 8599343 commit 9758236
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ on:
pull_request:
paths-ignore:
- '**.md'
workflow_run:
workflows: [Test schedule]
types:
- completed
branches:
- master

permissions:
contents: read
Expand All @@ -18,6 +24,7 @@ permissions:
jobs:
test:
runs-on: ubuntu-latest
if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }}
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/test_schedule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Test schedule

on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:

permissions:
contents: read

jobs:
test_schedule:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.12
- run: python -m pip install requests
- run: python tools/test_schedule.py
33 changes: 33 additions & 0 deletions tools/test_schedule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import sys
from datetime import datetime

import requests


def main() -> int:
"""
This code runs daily to trigger test action then update container image if
wikitextprocessor's code is newer than the version used in the latest test.
https://docs.github.com/en/rest/actions/workflow-runs?apiVersion=2022-11-28#list-workflow-runs-for-a-workflow
"""

r = requests.get(
"https://api.github.com/repos/tatuylonen/wiktextract/actions/workflows/59463306/runs?branch=master&per_page=1"
)
latest_test = datetime.fromisoformat(
r.json()["workflow_runs"][0]["created_at"]
)
r = requests.get(
"https://api.github.com/repos/tatuylonen/wikitextprocessor/commits/main"
)
latest_wikitextprocessor_commit = datetime.fromisoformat(
r.json()["commit"]["committer"]["date"]
)
if latest_test < latest_wikitextprocessor_commit:
return 0
return 1


if __name__ == "__main__":
sys.exit(main())

0 comments on commit 9758236

Please sign in to comment.