Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run bids-validator #5

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions bids-hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,13 @@ type job struct {
// web link to the results page for this job
// see also j.resultPath()
func (j job) resultUrl() string {
return giteaRootUrl.JoinPath("assets", fmt.Sprintf("%s.html", j.uuid)).String()
return giteaRootUrl.JoinPath("assets", "bids-validator", j.uuid[:2], j.uuid[2:4], fmt.Sprintf("%s.html", j.uuid)).String()
}

// file path to the results page for this job
// see also j.resultUrl()
func (j job) resultPath() string {
return filepath.Join(giteaCustom, "public", fmt.Sprintf("%s.html", j.uuid))
return filepath.Join(giteaCustom, "public", "bids-validator", j.uuid[:2], j.uuid[2:4], fmt.Sprintf("%s.html", j.uuid))
}

// file path to the log file for this job
Expand Down Expand Up @@ -360,7 +360,12 @@ func (j job) run() (state string, _ error) {
)

// redirect stdout to the result file
stdout, err := os.OpenFile(j.resultPath(), os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
resultPath := j.resultPath()
err := os.MkdirAll(filepath.Dir(resultPath), 0750)
if err != nil {
return stateError, err
}
stdout, err := os.OpenFile(resultPath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0640)
if err != nil {
return stateError, err
}
Expand Down Expand Up @@ -464,7 +469,7 @@ func readConfig() {
if err != nil {
log.Fatalf("invalid GITEA_CUSTOM: %v", err)
}
err = os.MkdirAll(filepath.Join(giteaCustom, "public"), 0750)
err = os.MkdirAll(filepath.Join(giteaCustom, "public", "bids-validator"), 0750)
if err != nil {
log.Fatalf("error creating output folder: %v", err)
}
Expand Down
54 changes: 51 additions & 3 deletions worker
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash
set -o nounset -o pipefail
trap 'exit 3' ERR
mguaypaq marked this conversation as resolved.
Show resolved Hide resolved

(exec 1>&2
date
Expand All @@ -12,13 +11,62 @@ BH_UUID=${BH_UUID}
EOF
)

GITEA_REPO="$GITEA_REPOSITORY_ROOT"/"${BH_USER}"/"${BH_REPO}".git
#echo $GITEA_REPO #DEBUG

sleep 5

cat <<"EOF"
<!DOCTYPE html>
<html lang=en>
<title>a title</title>
<p>a paragraph
<p>a paragraph</p>
<pre>
EOF

(
WORKDIR="$(mktemp -d --tmpdir bids-hook."$BH_UUID".XXXXXXXXXXX)"
cd "$WORKDIR"

#git clone "$GITEA_REPO" dataset && cd dataset # this is standard but clones a full copy of the repo which might be expensive
#git clone -b "${BH_COMMIT}" --depth 1 "$GITEA_REPO" dataset && cd dataset # this doesn't work unless BH_COMMIT is a branch name
# this is more complicated but it allows to us to --depth 1 with branches OR commit IDs:
(mkdir dataset && cd dataset && git init && git remote add origin "$GITEA_REPO" && git fetch --depth 1 origin "${BH_COMMIT}")
#trap 'echo -n "cleaning "; pwd; chmod -R +w "$WORKDIR" && rm -rf "$WORKDIR"' EXIT
(
cd dataset
git checkout "$BH_COMMIT"
set -e

if git ls-remote --exit-code "$GITEA_REPO" "refs/heads/git-annex" >/dev/null; then
ANNEXED=1
else
ANNEXED=""
fi

if [ -n "$ANNEXED" ]; then
set -x
# this reduces copies; always overrides annex.hardlink even if that is set system-wide
git config annex.thin true
# make sure we don't corrupt origin accidentally
git config remote.origin.annex-readonly true
git config annex.private true # XXX this doesn't do anything until git-annex 10
git annex init
git annex dead here # this is like annex.private, but has to be run
git annex sync --only-annex --no-content # grab the git-annex branch (since we did a shallow clone above)
git annex copy --from origin # NB: using copy --from origin and not git annex get to ensure we're validating the contents of origin and not any special remotes
else
set -x
fi

bids-validator --verbose .
)
) 2>&1
R=$?

cat <<"EOF"
</pre>
</html>
EOF

exit 0
exit $R