Created
November 29, 2024 07:25
-
-
Save initcron/b88fcaa35b36af01669ceb1441551382 to your computer and use it in GitHub Desktop.
Tests with Databrics Job Trigger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test and Trigger Databricks Job | |
# Trigger the workflow on push to the main branch | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout the repository | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# Step 2: Set up Python environment | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.9 | |
# Step 3: Install dependencies | |
- name: Install dependencies | |
run: | | |
pip install -r requirements.txt | |
pip install pytest | |
# Step 4: Run tests | |
- name: Run tests | |
run: pytest tests/ | |
trigger-databricks-job: | |
runs-on: ubuntu-latest | |
needs: test | |
steps: | |
# Step 1: Set up environment variables | |
- name: Export Databricks Environment Variables | |
env: | |
DATABRICKS_TOKEN: ${{ secrets.DATABRICKS_PAT }} | |
DATABRICKS_HOST: ${{ secrets.DATABRICKS_HOST }} | |
run: echo "Databricks Environment Variables Set" | |
# Step 2: Trigger the Databricks Job | |
- name: Trigger Databricks Job | |
run: | | |
curl -X POST "$DATABRICKS_HOST/api/2.1/jobs/run-now" \ | |
-H "Authorization: Bearer $DATABRICKS_TOKEN" \ | |
-H "Content-Type: application/json" \ | |
-d '{ | |
"job_id": "<YOUR_JOB_ID>" | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment