-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathentrypoint.sh
executable file
·66 lines (65 loc) · 2.44 KB
/
entrypoint.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
#!/bin/bash -l
export HOME=/home/airflow
export PATH="$HOME/.local/bin:$PATH"
export AIRFLOW__CORE__DAGS_FOLDER=${GITHUB_WORKSPACE}/
export AIRFLOW__CORE__PLUGINS_FOLDER=${GITHUB_WORKSPACE}/plugins/
export AIRFLOW__CORE__LOGS_FOLDER="/tmp/logs/"
export FERNET_KEY=$(openssl rand -base64 32)
RUN_ID=$(uuidgen)
RESULTS_DIR=${GITHUB_WORKSPACE}/airflow-diff-results
git config --global --add safe.directory $GITHUB_WORKSPACE
mkdir -p $RESULTS_DIR
echo Base ref is $GITHUB_BASE_REF, head ref is $GITHUB_HEAD_REF
airflow initdb
if ! python /dump_dags.py /tmp/current ; then
echo "::set-output name=diff::ERROR: Failed to parse DAGs."
exit 0 # Avoid failing the script so the PR comment can be posted.
fi
git checkout $GITHUB_BASE_REF
if ! python /dump_dags.py /tmp/base ; then
echo "::set-output name=diff::ERROR: Failed to parse base DAGs."
exit 0 # Avoid failing the script so the PR comment can be posted.
fi
git checkout $GITHUB_HEAD_REF # Revert to head for printing dag below
DAG_IDS=$(basename -a /tmp/base/* /tmp/current/* | sort | uniq)
SUMMARY=""
for dag_id in $DAG_IDS; do
DIFF=''
if [[ ! -f "/tmp/current/$dag_id" ]]; then
SUMMARY+="**DAG deleted: $dag_id**"$'\n\n'
elif [[ ! -f "/tmp/base/$dag_id" ]]; then
DIFF=$(< /tmp/current/$dag_id)
if [ -n "$DIFF" ]; then
SUMMARY+="**DAG added: $dag_id**"
fi
else
DIFF=$(diff -u /tmp/base/$dag_id /tmp/current/$dag_id)
if [ -n "$DIFF" ]; then
# Strip first 2 lines with the filenames.
DIFF=$(echo "$DIFF" | tail -n +3)
SUMMARY+="**DAG modified: $dag_id**"
fi
fi
if [ -n "$DIFF" ]; then
echo "$DIFF" > $RESULTS_DIR/$dag_id.txt
airflow show_dag -s $RESULTS_DIR/$dag_id.png $dag_id
if [ -n "$S3_PROXY_URL" ]; then
SUMMARY+=" ([diff]($S3_PROXY_URL/$S3_BASE_DIR/$RUN_ID/$dag_id.txt)) ([image]($S3_PROXY_URL/$S3_BASE_DIR/$RUN_ID/$dag_id.png))"
fi
if [ $(echo "$DIFF" | wc -l) -gt 100 ]; then
DIFF="Large diff omitted"
fi
SUMMARY+=$'\n\n```\n'"$DIFF"$'\n```\n\n'
fi
done
if [ -z "$SUMMARY" ]; then
SUMMARY='No diff in DAG structure'
fi
if [ -n "$S3_PROXY_URL" ] && [ "$(ls $RESULTS_DIR)" ]; then
aws s3 cp $RESULTS_DIR "s3://$S3_BUCKET/$S3_BASE_DIR/$RUN_ID" --recursive
fi
SUMMARY="${SUMMARY//'%'/'%25'}"
SUMMARY="${SUMMARY//$'\n'/'%0A'}"
SUMMARY="${SUMMARY//$'\r'/'%0D'}"
echo "::set-output name=diff::$SUMMARY"
exit 0