forked from d2l-ai/d2l-zh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd2l_job.sh
68 lines (56 loc) · 1.8 KB
/
d2l_job.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
date
echo "Args: $@"
env
echo "jobId: $AWS_BATCH_JOB_ID"
echo "jobQueue: $AWS_BATCH_JQ_NAME"
echo "computeEnvironment: $AWS_BATCH_CE_NAME"
SOURCE_REF=$1
WORK_DIR=$2
COMMAND=$3
############### NOT USED ATM ##################
SAVED_OUTPUT=$4
SAVE_PATH=$5
###############################################
REMOTE=$6
SAFE_TO_USE_SCRIPT=$7
ORIGINAL_REPO=${8:-'d2l-zh'}
# TODO @anirudhdagar: hardcode ORIGINAL_ORG
# Avoid ability to change org by restricting
# job definition arguments defined in d2l-infra
# This is only changed for testing purposes
ORIGINAL_ORG=${9:-'d2l-ai'}
# Copy the workflow from master branch
git clone https://github.com/"$ORIGINAL_ORG"/"$ORIGINAL_REPO".git
WORKFLOW_SCRIPTS="$ORIGINAL_REPO"/.github/workflow_scripts
if [ -d "$WORKFLOW_SCRIPTS" ]; then
cp -R "$ORIGINAL_REPO"/.github/workflow_scripts .
fi
cd "$ORIGINAL_REPO"
if [ ! -z $REMOTE ]; then
git remote set-url origin $REMOTE
fi
git fetch origin $SOURCE_REF:working
git checkout working
# Reset modification times for all notebooks using git-timesync
# We use this to make sure d2lbook build eval caching is valid
# even after cloning the repo for each run
# Modification times for original repo files are corrected and are now
# good for comparing with modification times of build files coming
# from the S3 bucket
git timesync *.md **/*.md
# If not safe to use script, we overwrite with the script from master branch
TRUE=true
if [[ ${SAFE_TO_USE_SCRIPT,,} != ${TRUE,,} ]]; then
if [ -d ../workflow_scripts ]; then
rm -rf .github/workflow_scripts
mv ../workflow_scripts .github/
else
echo Not safe to use user provided script, and could not find script from master branches
exit 1
fi
fi
cd $WORK_DIR
/bin/bash -o pipefail -c "eval $COMMAND"
COMMAND_EXIT_CODE=$?
exit $COMMAND_EXIT_CODE