CI cronjobs, daily #493
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Runs every day to check if Freenet's fred repository has changed. | |
# If yes it runs the CI tests to see if the changes at fred broke anything at Freetalk. | |
# If no it does nothing. | |
# NOTICE: This only runs on xor-freenet's repository currently, see the comments below. | |
name: CI cronjobs, daily | |
# TODO: Code quality: Currently Freetalk only has branch "master" so the cronjobs only run there. | |
# Once there's also a development branch run the cronjobs on both branches. | |
on: | |
schedule: | |
- cron: 07 19 * * * # At 19:07 every day | |
jobs: | |
get-fred-commits: | |
name: Determine if fred branch next has changed | |
# TODO: Once the tests are reasonably stable remove the "github.repository == ..." line so the | |
# cronjob also runs on Freenet's GitHub repo and fred developers thus get an email if their | |
# changes break Freetalk. | |
# NOTICE: I think GHA currently disables cronjobs if a repo did not have changes for 60 days, | |
# check if that is true. Then it may be necessary to move the cronjob to the fred repo because | |
# the Freetalk repo on Freenet's GitHub is not that frequently updated. | |
if: github.repository == 'xor-freenet/plugin-Freetalk' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Load and print current fred branch next HEAD commit | |
id: get-new-HEAD | |
shell: bash | |
run: | | |
set -o errexit | |
set -o pipefail | |
echo 'Current HEAD commit of fred branch next:' | |
git ls-remote 'https://github.com/freenet/fred.git' 'refs/heads/next' | cut -f 1 \ | |
| tee current_fred_commit | |
echo "::set-output name=current_fred_commit::$(<current_fred_commit)" | |
- name: Retrieve/cache fred branch next HEAD commit of previous run | |
uses: actions/cache@v3 | |
with: | |
path: previous_fred_commit | |
# The key must include the hash of the file to ensure the cache is invalidated whenever the | |
# file contents change. | |
key: previous_fred_commit_${{hashFiles('current_fred_commit')}} | |
- name: Load and print previous fred branch next HEAD commit | |
id: get-old-HEAD | |
shell: bash | |
run: | | |
set -o errexit | |
set -o pipefail | |
echo 'Previous HEAD commit of fred branch next:' | |
if [ -f previous_fred_commit ] ; then | |
cat previous_fred_commit | |
else | |
# The cache did not serve us the file so the cache key and thus hash was different. | |
echo 'Different_from_current_HEAD' | tee previous_fred_commit | |
fi | |
echo "::set-output name=previous_fred_commit::$(<previous_fred_commit)" | |
cp --force current_fred_commit previous_fred_commit | |
outputs: | |
previous_fred_commit: ${{steps.get-old-HEAD.outputs.previous_fred_commit}} | |
current_fred_commit: ${{steps.get-new-HEAD.outputs.current_fred_commit}} | |
run-ci-tests-if-fred-changed: | |
name: Daily CI tests if fred changed, on xor-freenet's Freetalk repo only | |
needs: get-fred-commits | |
if: | | |
needs.get-fred-commits.outputs.current_fred_commit != | |
needs.get-fred-commits.outputs.previous_fred_commit | |
# "./" is the syntax for reusing workflows in the same repository. | |
# For reusing a workflow from a different repository see: | |
# https://docs.github.com/en/actions/using-workflows/reusing-workflows#calling-a-reusable-workflow | |
uses: ./.github/workflows/ci-tests.yml |