CI: adding age check ci
All checks were successful
ci/woodpecker/push/age-check Pipeline was successful

This commit is contained in:
Louis 2025-04-29 16:11:44 +02:00
parent 8eb6cf42aa
commit b132659a7a
2 changed files with 52 additions and 0 deletions

19
.woodpecker/age-check.yml Normal file
View file

@ -0,0 +1,19 @@
steps:
- name: age-check
image: alpine:latest
commands:
- /bin/sh -c 'update-age.sh' && echo "Age check succeeded" || echo "Age check failed"
when:
- event: [cron, manual]
- name: push commit
image: appleboy/drone-git-push
settings:
commit: true
commit_message: "Update age"
remote_name: origin
author_name: "Woodpecker CI"
author_email: "git@polarolouis.fr"
when:
path:
include: ["infos_persos.tex"]

33
update-age.sh Executable file
View file

@ -0,0 +1,33 @@
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: $0 <file>";
echo "Example: $0 /path/to/file.txt";
echo "Please provide a file as an argument.";
exit 1;
fi
if [ ! -f $1 ]; then
echo "File $1 not found";
echo "Usage: $0 <file>";
echo "Example: $0 /path/to/file.txt";
exit 1;
fi
AGE_W=$(grep -oP "([0-9]{2}) ans" $1 | grep -oP "([0-9]{2})")
if [ -z "$AGE_W" ]; then
echo "Age not found in $1";
exit 1;
fi
echo "Age found: $AGE_W"
AGE_R=$(($(date +%Y)-2000))
echo "Current age: $AGE_R"
if [ "$AGE_W" -eq "$AGE_R" ]; then
echo "Age in $1 ($AGE_W) matches current year ($AGE_R)";
exit 0;
else
echo "Age in $1 ($AGE_W) does not match current year ($AGE_R)";
echo "Updating age in $1";
sed -i -e "s/$AGE_W ans/$AGE_R ans/" $1;
echo "Age updated to $AGE_R in $1";
cat $1
fi