Skip to content

Commit 8f41d7c

Browse files
✨ Add github action to trigger airflow sync
🔒️ Add read permission to gha 🚧 Test another command ✨ Update sync to airflow 🚧 Testing to see if push of test dag works ✏️ Fix typo 🚧 Try now with an actual sectret 🚧 Testing blank bearwer token 🔐 Use include airflow pat 🧱 Don't trigger on pull request, only on push to main
1 parent eea17a6 commit 8f41d7c

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Export Repo to Airflow
2+
3+
# Controls when the workflow will run
4+
on:
5+
# Triggers the workflow on push events but only for the "main" branch
6+
push:
7+
branches: [ "main" ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
send-to-airflow-s3-bucket:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: send repository dispatch
18+
run: |
19+
curl -L \
20+
-X POST \
21+
-H "Accept: application/vnd.github+json" \
22+
-H "Authorization: Bearer ${{ secrets.INCLUDE_AF_PAT }}" \
23+
-H "X-GitHub-Api-Version: 2022-11-28" \
24+
https://api.github.com/repos/include-dcc/include-dbt-airflow-mirror/dispatches \
25+
-d '{"event_type":"export-to-airflow","client_payload":{"repo": "include-dbt-sandbox", "ref": "'${{ github.ref }}'", "run_id": "'${{ github.run_id }}'"}}'

dags/tutorial.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import textwrap
2+
from datetime import datetime, timedelta
3+
4+
# The DAG object; we'll need this to instantiate a DAG
5+
from airflow.models.dag import DAG
6+
7+
# Operators; we need this to operate!
8+
from airflow.operators.bash import BashOperator
9+
10+
with DAG(
11+
"tutorial",
12+
# These args will get passed on to each operator
13+
# You can override them on a per-task basis during operator initialization
14+
default_args={
15+
"depends_on_past": False,
16+
"email": ["[email protected]"],
17+
"email_on_failure": False,
18+
"email_on_retry": False,
19+
"retries": 1,
20+
"retry_delay": timedelta(minutes=5),
21+
# 'queue': 'bash_queue',
22+
# 'pool': 'backfill',
23+
# 'priority_weight': 10,
24+
# 'end_date': datetime(2016, 1, 1),
25+
# 'wait_for_downstream': False,
26+
# 'sla': timedelta(hours=2),
27+
# 'execution_timeout': timedelta(seconds=300),
28+
# 'on_failure_callback': some_function, # or list of functions
29+
# 'on_success_callback': some_other_function, # or list of functions
30+
# 'on_retry_callback': another_function, # or list of functions
31+
# 'sla_miss_callback': yet_another_function, # or list of functions
32+
# 'on_skipped_callback': another_function, #or list of functions
33+
# 'trigger_rule': 'all_success'
34+
},
35+
description="A simple tutorial DAG",
36+
schedule=timedelta(days=1),
37+
start_date=datetime(2021, 1, 1),
38+
catchup=False,
39+
tags=["example"],
40+
) as dag:
41+
42+
# t1, t2 and t3 are examples of tasks created by instantiating operators
43+
t1 = BashOperator(
44+
task_id="print_date",
45+
bash_command="date",
46+
)
47+
48+
t2 = BashOperator(
49+
task_id="sleep",
50+
depends_on_past=False,
51+
bash_command="sleep 5",
52+
retries=3,
53+
)
54+
t1.doc_md = textwrap.dedent(
55+
"""\
56+
#### Task Documentation
57+
You can document your task using the attributes `doc_md` (markdown),
58+
`doc` (plain text), `doc_rst`, `doc_json`, `doc_yaml` which gets
59+
rendered in the UI's Task Instance Details page.
60+
![img](https://imgs.xkcd.com/comics/fixing_problems.png)
61+
**Image Credit:** Randall Munroe, [XKCD](https://xkcd.com/license.html)
62+
"""
63+
)
64+
65+
dag.doc_md = __doc__ # providing that you have a docstring at the beginning of the DAG; OR
66+
dag.doc_md = """
67+
This is a documentation placed anywhere
68+
""" # otherwise, type it like this
69+
templated_command = textwrap.dedent(
70+
"""
71+
{% for i in range(5) %}
72+
echo "{{ ds }}"
73+
echo "{{ macros.ds_add(ds, 7)}}"
74+
{% endfor %}
75+
"""
76+
)
77+
78+
t3 = BashOperator(
79+
task_id="templated",
80+
depends_on_past=False,
81+
bash_command=templated_command,
82+
)
83+
84+
t1 >> [t2, t3]

0 commit comments

Comments
 (0)