Adds test option to repo.

This commit is contained in:
Llewellyn van der Merwe 2021-05-02 23:45:27 +02:00
parent e0f9f7bd8d
commit 6fbeffd21e
Signed by: Llewellyn
GPG Key ID: EFC0C720A240551C
3 changed files with 94 additions and 20 deletions

27
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,27 @@
name: "Test Today's Scripture!"
on:
# so we can manually run a test also
workflow_dispatch:
jobs:
build:
runs-on: [ubuntu-20.04]
steps:
- name: Setup gitHub User Details
env:
GIT_USER: ${{ secrets.GIT_USER }}
GIT_EMAIL: ${{ secrets.GIT_EMAIL }}
GPG_USER: ${{ secrets.GPG_USER }}
GPG_KEY: ${{ secrets.GPG_KEY }}
SSH_KEY: ${{ secrets.SSH_KEY }}
SSH_PUB: ${{ secrets.SSH_PUB }}
run: |
/bin/bash <(/bin/curl -s https://raw.githubusercontent.com/vdm-io/github-user/master/src/setup.sh) --gpg-key "$GPG_KEY" --gpg-user "$GPG_USER" --ssh-key "$SSH_KEY" --ssh-pub "$SSH_PUB" --git-user "$GIT_USER" --git-email "$GIT_EMAIL"
- name: Clone Master Repositry
run: |
/bin/git clone git@github.com:trueChristian/daily-scripture.git daily_scripture
- name: Build the Daily Scripture
run: |
cd daily_scripture
/bin/bash ./src/today.sh --dry

View File

@ -5,6 +5,9 @@ on:
schedule:
- cron: '7 22 * * *'
# so we can manually run a test also
workflow_dispatch:
jobs:
build:
runs-on: [ubuntu-20.04]

View File

@ -1,7 +1,33 @@
#!/bin/bash
# Do some prep work
command -v git >/dev/null 2>&1 || {
echo >&2 "We require git for this script to run, but it's not installed. Aborting."
exit 1
}
command -v curl >/dev/null 2>&1 || {
echo >&2 "We require curl for this script to run, but it's not installed. Aborting."
exit 1
}
# global config options
DRYRUN=0
# check if we have options
while :; do
case $1 in
--dry)
DRYRUN=1
;;
*) # Default case: No more options, so break out of the loop.
break ;;
esac
shift
done
#██████████████████████████████████████████████████████████████ DATE TODAY ███
TODAY=$(date '+%A %d-%B, %Y')
# must set the time to Namibian :)
TODAY=$(TZ="Africa/Windhoek" date '+%A %d-%B, %Y')
#█████████████████████████████████████████████████████████████ SCRIPT PATH ███
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@ -16,26 +42,37 @@ TMP="$DIR/.TMP"
sort -R -k1 -b "${SORTED}" >"${TMP}"
# get the first line
VERSE=$(head -n 1 "${TMP}")
# remove the verse
sed -i -e '1,1d' "${TMP}"
# add to used verses
[ -f "${USED}" ] && echo "$VERSE" >>"${USED}" || echo "$VERSE" >"${USED}"
# test behaviour
if (("$DRYRUN" == 1)); then
echo "selected: $VERSE"
else
# remove the verse
sed -i -e '1,1d' "${TMP}"
# add to used verses
[ -f "${USED}" ] && echo "$VERSE" >>"${USED}" || echo "$VERSE" >"${USED}"
fi
#█████████████████████████████████████████████████████ SIX MONTH RETENTION ███
# count the number of verse in used file
LINES_NR=$(wc -l <"${USED}")
if [ "$LINES_NR" -gt 182 ]; then
# get the first line
VERSE_BACK=$(head -n 1 "${USED}")
# remove the verse
sed -i -e '1,1d' "${USED}"
# add add back to the pile
echo "$VERSE_BACK" >>"${TMP}"
# check test behaviour
if (("$DRYRUN" == 0)); then
# count the number of verse in used file
LINES_NR=$(wc -l <"${USED}")
if [ "$LINES_NR" -gt 182 ]; then
# get the first line
VERSE_BACK=$(head -n 1 "${USED}")
# remove the verse
sed -i -e '1,1d' "${USED}"
# add add back to the pile
echo "$VERSE_BACK" >>"${TMP}"
fi
fi
#███████████████████████████████████████████████████████████████ SORT BACK ███
# store back for next time
sort -h -b -k1 "${TMP}" >"${SORTED}"
# check test behaviour
if (("$DRYRUN" == 0)); then
# store back for next time
sort -h -b -k1 "${TMP}" >"${SORTED}"
fi
# remove the temp file
rm -f "${TMP}"
@ -61,10 +98,17 @@ ${VERSES//$'\n'/ }
#███████████████████████████████████████████████████████████████ SET FILES ███
echo "${HTML}" >README.html
echo "${MARKDOWN}" >README.md
# check test behaviour
if (("$DRYRUN" == 1)); then
echo "${HTML}"
echo "----------------------------------------------------"
echo "${MARKDOWN}"
else
echo "${HTML}" >README.html
echo "${MARKDOWN}" >README.md
git commit -am"${TODAY}"
git push
git commit -am"${TODAY}"
git push
fi
exit 0