Skip to content

Commit

Permalink
fix dry run check
Browse files Browse the repository at this point in the history
  • Loading branch information
looi committed Jun 4, 2021
1 parent 880db4b commit adc3ea3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ description: 'Gets diff of airflow DAG.'
outputs:
diff:
description: 'The diff of the DAGs.'
is_valid:
description: '1 if DAGs rendered successfully, else 0.'
runs:
using: 'docker'
image: 'Dockerfile'
1 change: 0 additions & 1 deletion dump_dags.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def dump_dags(output_base_path):
with open(os.path.join(output_base_path, dag_id), 'w') as outfile:
adj = defaultdict(list) # Adjacency list of DAG.
for task in dag.tasks:
task.dry_run() # Perform dry run to validate template fields.
for upstream_task_id in task.upstream_task_ids:
adj[upstream_task_id].append(task.task_id)

Expand Down
11 changes: 10 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ python /dump_dags.py /tmp/base
git checkout $GITHUB_HEAD_REF # Revert to head for printing dag below
DAG_IDS=$(basename -a /tmp/base/* /tmp/current/* | sort | uniq)
SUMMARY=""
IS_VALID=1
for dag_id in $DAG_IDS; do
DIFF=''
if [[ ! -f "/tmp/current/$dag_id" ]]; then
Expand Down Expand Up @@ -45,9 +46,16 @@ for dag_id in $DAG_IDS; do
fi
SUMMARY+=$'\n\n```\n'"$DIFF"$'\n```\n\n'
fi
# Attempt to render template to check jinja.
airflow backfill --dry_run --start_date 2001-01-01 --end_date 2001-01-01 $dag_id
retVal=$?
if [ $retVal -ne 0 ]; then
SUMMARY+=$'\n\nFailed to render DAG '"$dag_id"$'\n\n'
IS_VALID=0
fi
done
if [ -z "$SUMMARY" ]; then
SUMMARY='No diff'
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
Expand All @@ -56,4 +64,5 @@ SUMMARY="${SUMMARY//'%'/'%25'}"
SUMMARY="${SUMMARY//$'\n'/'%0A'}"
SUMMARY="${SUMMARY//$'\r'/'%0D'}"
echo "::set-output name=diff::$SUMMARY"
echo "::set-output name=is_valid::$IS_VALID"
exit 0

0 comments on commit adc3ea3

Please sign in to comment.