add ci
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/deployment/woodpecker Pipeline was successful

This commit is contained in:
Simon Vieille 2023-07-26 18:25:22 +02:00
commit 67cbc8267a
Signed by: deblan
GPG key ID: 579388D585F70417
2 changed files with 133 additions and 0 deletions

8
.woodpecker.yml Normal file
View file

@ -0,0 +1,8 @@
steps:
rss:
image: alpine
commands:
- apk add curl
- ./bin/rss -f https://www.deblan.io/RSS
when:
event: [deployment, cron]

125
bin/rss Executable file
View file

@ -0,0 +1,125 @@
#!/bin/sh
set -eu
usage() {
printf "Usage: %s [-l DEBUG_LEVEL] [-f URL] [-h]\n" "$0"
}
help() {
cat << EOH
SYNOPSIS
$0 [-l DEBUG_LEVEL] [-f FEED_URL] [-h]
DESCRIPTION
$0 generates a list of my personal blog posts.
OPTIONS
-h Show this help
-l debug|info|notice|warning|error
Debug level
-f URL
URL of the RSS Feed
EOH
}
on_interrupt() {
log -l notice ""
log -l notice "Process aborted!"
exit 130
}
main() {
while getopts "f:l:h" option; do
case "${option}" in
h) help; exit 0;;
l) LOG_VERBOSE="$OPTARG";;
f) RSS_URL="$OPTARG";;
?) log -l error "$(usage)"; exit 1;;
esac
done
# log [-t] [-l debug|info|notice|warning|error] message
key=0
is_first=1
title=
link=
curl --silent "$RSS_URL" \
| grep -E "<(title|link)" \
| grep -v "<link>" \
| grep -v "gemini:" \
| while read line; do
if [ $((key%2)) -eq 1 ]; then
title="$(printf "$line" | sed 's/<title><!\[CDATA\[//g' | sed 's/\]\]><\/title>//g')"
else
link="$(printf "$line" | cut -d'"' -f2)"
if [ $is_first -eq 1 ]; then
is_first=0
else
printf "* [%s](%s)\n" "$title" "$link"
fi
fi
key=$((key+1))
done
exit 0
}
log() {
LOG_VERBOSE="${LOG_VERBOSE:-info}"
LEVEL=info
TIME=
while getopts "tl:" option; do
case "${option}" in
l) LEVEL="$OPTARG"; shift $((OPTIND-1));;
t) TIME="$(printf "[%s] " "$(date +'%Y-%m-%dT%H:%M:%S.%s')")"; shift $((OPTIND-1));;
*) exit 1;;
esac
done
if [ -t 2 ] && [ -z "${NO_COLOR-}" ]; then
case "${LEVEL}" in
debug) COLOR="$(tput setaf 3)";;
notice) COLOR="$(tput setaf 4)";;
warning) COLOR="$(tput setaf 5)";;
error) COLOR="$(tput setaf 1)";;
*) COLOR="$(tput sgr0)";;
esac
fi
case "${LEVEL}" in
debug) LEVEL=100;;
notice) LEVEL=250;;
warning) LEVEL=300;;
error) LEVEL=400;;
*) LEVEL=200;;
esac
case "${LOG_VERBOSE}" in
debug) LOG_VERBOSE_VALUE=100;;
notice) LOG_VERBOSE_VALUE=250;;
warning) LOG_VERBOSE_VALUE=300;;
error) LOG_VERBOSE_VALUE=400;;
*) LOG_VERBOSE_VALUE=200;;
esac
if [ $LEVEL -ge $LOG_VERBOSE_VALUE ]; then
printf "%s\n" "$*" | while IFS='' read -r LINE; do
printf "%s%s%s\n" "${COLOR:-}" "${TIME:-}" "$LINE" >&2
done
fi
}
trap on_interrupt INT
main "$@"