Skip to content

Commit

Permalink
Add self-hosted noscience pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
fjammes committed Sep 16, 2024
1 parent 3af6451 commit 00d938f
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 26 deletions.
File renamed without changes.
31 changes: 6 additions & 25 deletions doc/self_hosted.md → doc/self_hosted_ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,8 @@ sudo su - fink-ci
echo "your_github_token" > /home/fink-ci/.token
chmod 600 /home/fink-ci/.token

cat <<EOF > /home/fink-ci/fink-ci.sh
#!/bin/bash
set -euxo pipefail
# Load GitHub token
export TOKEN=$(cat /home/fink-ci/.token)
export USER="fink-ci"
repo_url="https://github.com/astrolabsoftware/fink-broker.git"
tmpdir=\$(mktemp -d --suffix -fink-broker-ci)
repo=\$tmpdir/fink-broker
branchname="877-automated-e2e-tests"
# Set go path according to go install method
PATH=\$HOME/go/bin:/usr/local/go/bin:/usr/local/bin:\$PATH
# Clone the repository
git clone --single-branch \$repo_url \$repo --branch \$branchname
# Run fink ci in science mode
\$repo/e2e/run.sh -s -c
EOF
# Retrieve the fink-ci script
curl https://raw.githubusercontent.com/astrolabsoftware/fink-broker/master/e2e/fink-ci.sh

# Make the script executable
chmod +x /home/fink-ci/fink-ci.sh
Expand All @@ -63,13 +43,14 @@ To ensure the CI script runs nightly, set up a cron job.
crontab -e
```

2. Add the following line to schedule the script to run at midnight every day:
2. Add the following line to schedule the `noscience` and `science` scripts to run every night:

```bash
0 0 * * * /home/fink-ci/fink-ci.sh >> /home/fink-ci/cronjob-$(date +\%Y-\%m-\%d).log 2>&1
0 0 * * * /home/fink-ci/fink-ci.sh -c >> /home/fink-ci/cronjob-noscience-$(date +\%Y-\%m-\%d).log 2>&1
0 1 * * * /home/fink-ci/fink-ci.sh -c -s >> /home/fink-ci/cronjob-science-$(date +\%Y-\%m-\%d).log 2>&1
```

This will log the output to `/home/fink-ci/cronjob-YYY-MM-DD.log`.
This will log the output to `/home/fink-ci/cronjob-<science>-YYY-MM-DD.log`.


By following this procedure, the `fink-ci` user will be set up to automatically run fink e2e tests every night and report it to Github Actions.
52 changes: 52 additions & 0 deletions e2e/fink-ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

# Clone Fink-broker source code in a tempory directory and run e2e test
# designed to be run as a cron job.

set -euxo pipefail

export TOKEN=$(cat /home/fink-ci/.token)
export USER="fink-ci"
repo_url="https://github.com/astrolabsoftware/fink-broker.git"
tmpdir=$(mktemp -d --suffix -fink-broker-ci)
repo=$tmpdir/fink-broker
science_opt=""
cleanup_opt=""

# Set go path according to go install method
PATH=$HOME/go/bin:/usr/local/go/bin:/usr/local/bin:$PATH

branchname="master"

usage() {
cat << EOD
Usage: $(basename "$0") [options]
Available options:
-h This message
-c Cleanup the cluster if the tests are successful
-s Use the science algorithms during the tests
-b <branch> Branch name to clone (default: master)
Clone Fink-broker source code in a tempory directory and run e2e test
designed to be run as a cron job.
EOD
}

# Get the options
while getopts hsb: c ; do
case $c in
h) usage ; exit 0 ;;
b) branchname=$OPTARG ;;
c) cleanup_opt="-c" ;;
s) science_opt="-s" ;;
\?) usage ; exit 2 ;;
esac
done
shift "$((OPTIND-1))"

# Clone the repository
git clone --single-branch $repo_url $repo --branch $branchname

# Run fink ci in science mode
$repo/e2e/run.sh "$cleanup_opt" $science_opt
11 changes: 10 additions & 1 deletion e2e/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ export SUFFIX

function dispatch()
{

if [ $SUFFIX = "" ]; then
echo "Running e2e tests with science algorithms"
event_type="e2e-science"
else
echo "Running e2e tests without science algorithms"
event_type="e2e-noscience"
fi

url="https://api.github.com/repos/astrolabsoftware/fink-broker/dispatches"

payload="{\"build\": $build,\"e2e\": $e2e,\"push\": $push, \"cluster\": \"$cluster\", \"image\": \"$CIUX_IMAGE_URL\"}"
Expand All @@ -67,7 +76,7 @@ function dispatch()
-H "Authorization: Bearer $token" \
-H "X-GitHub-Api-Version: 2022-11-28" \
$url \
-d "{\"event_type\":\"e2e-science\",\"client_payload\":$payload}" || echo "ERROR Failed to dispatch event" >&2
-d "{\"event_type\":\"$event_type\",\"client_payload\":$payload}" || echo "ERROR Failed to dispatch event" >&2
fi

if [ $cleanup = true -a $e2e = true ]; then
Expand Down

0 comments on commit 00d938f

Please sign in to comment.