Skip to content

Cron tests scheduler #1120

Cron tests scheduler

Cron tests scheduler #1120

name: 'Cron tests scheduler'
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
jobs:
cron-test-scheduler:
runs-on: ubuntu-latest
steps:
- name: 'Ensure git is installed'
run: sudo apt-get install -y git
- name: 'Ensure jq is installed'
run: sudo apt-get install -y jq
- name: 'Checkout all branches'
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: 'Scan all open branches'
run: |
for source in $(git for-each-ref --format='%(refname:lstrip=3)' refs/remotes/origin/); do
echo "+ Evaluating branch: $source"
if [ "$source" = "HEAD" ] || [ "$source" = "master" ] || [ "$source" = "gh-pages" ]; then
echo "+- Skipping branch $source"
continue
fi
echo "+- Acquiring last commit information"
curl --silent --show-error -L https://api.github.com/repos/$GITHUB_REPOSITORY/commits/$source > commit-raw.json
head -n2 commit-raw.json | tail -n1
echo "+- Extracting last commit date"
date="$(jq -r '.commit.author.date' commit-raw.json)"
echo "+-- $date"
echo "+- Converting to timestamp"
timestamp=$(date -u -d "$date" +%s)
echo "+-- $timestamp"
echo "+- Evaluating elapsed days"
days=$(( ( $(date -u +%s) - $timestamp ) / 86400 ))
echo "+-- Last commit was $days days ago"
if [ $days -lt 1 ]; then
echo "+- Launching cron tests on $source"
curl --silent --show-error -X POST -H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/$GITHUB_REPOSITORY/actions/workflows/cron-runner.yml/dispatches \
-d "{ \"ref\" : \"$source\", \"inputs\" : { \"source\" : \"$source\" }}" \
-u ${{ secrets.LISA_PAT }}
else
echo "+- Skipping cron tests on $source"
fi
done