Skip to content

Commit cb1c1cb

Browse files
authored
Merge pull request #86 from codetocloudorg/feature/dagger_hackathon_git_action
DO NOT MERGE - CONNER TESTING FOR HACKATHON
2 parents 384616c + 236b7f5 commit cb1c1cb

17 files changed

Lines changed: 385 additions & 180 deletions
Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,51 @@
1-
name: dagger_hackathon # Name of the workflow
1+
name: dagger_hackathon
22

33
on:
4-
push:
5-
branches:
6-
- feature/dagger-hackathon-line-extraction
4+
pull_request:
5+
branches: [main]
6+
types: [opened, synchronize, reopened]
77

88
jobs:
9-
dagger-plan:
10-
runs-on: ubuntu-latest # Define the runner environment
9+
dagger-run-unit-tests:
10+
runs-on: ubuntu-latest
1111

1212
env:
1313
GITHUB_TOKEN: ${{ secrets.DAGGER_HACKATHON_GITHUB_TOKEN }}
14-
OPENAI_AZURE_VERSION: "2024-12-01-preview"
1514
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
16-
OPENAI_MODEL: "gpt-4o"
17-
OPENAI_BASE_URL: "https://vdfvdf.openai.azure.com/"
15+
CURRENT_BRANCH: ${{ github.head_ref }}
1816

1917
steps:
20-
- name: Checkout repository # Fetch the repository code
18+
- name: Checkout repo
2119
uses: actions/checkout@v4
2220

23-
- name: Install Dagger CLI # Download and install the Dagger CLI
21+
- name: Install Dagger CLI
2422
run: |
2523
curl -fsSL https://dl.dagger.io/dagger/install.sh | BIN_DIR=$HOME/.local/bin sh
26-
echo "$HOME/.local/bin" >> $GITHUB_PATH # Add Dagger to the system PATH
24+
echo "$HOME/.local/bin" >> $GITHUB_PATH
2725
28-
- name: Run Dagger plan
26+
- name: Create .env file
2927
working-directory: docs/dagger/dagger-hackathon/
3028
run: |
31-
dagger call debug-unit-test-agent --directory-arg="." \
32-
--github-token="GITHUB_TOKEN" \
33-
--github-branch=feature/dagger-hackathon-line-extraction \
34-
--github-repo=codetocloudorg/platform-engineering \
35-
--azure-model="gpt-4o" \
36-
--azure-endpoint="https://vdfvdf.openai.azure.com/" \
37-
--azure-api-key="OPENAI_API_KEY"
29+
cat <<EOF > .env
30+
OPENAI_BASE_URL=https://vdfvdf.openai.azure.com/
31+
OPENAI_MODEL=gpt-4o
32+
OPENAI_API_KEY=${OPENAI_API_KEY}
33+
OPENAI_AZURE_VERSION=2024-12-01-preview
34+
GITHUB_TOKEN=${GITHUB_TOKEN}
35+
EOF
36+
37+
- name: Dagger Run Unit Tests
38+
working-directory: docs/dagger/dagger-hackathon/
39+
env:
40+
DAGGER_SECRET_GITHUB_TOKEN: ${{ secrets.DAGGER_HACKATHON_GITHUB_TOKEN }}
41+
run: |
42+
export AZURE_OPENAI_API_KEY="${OPENAI_API_KEY}"
43+
export AZURE_OPENAI_ENDPOINT="https://vdfvdf.openai.azure.com/"
44+
dagger call \
45+
--source="." \
46+
--github_branch="${CURRENT_BRANCH}" \
47+
--github_repo="codetocloudorg/platform-engineering" \
48+
--github_token=DAGGER_SECRET_GITHUB_TOKEN \
49+
--azure_api_key="OPENAI_API_KEY" \
50+
--azure_endpoint="https://vdfvdf.openai.azure.com/" \
51+
fix-my-tests-agent
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
OPENAI_BASE_URL=""
2+
OPENAI_MODEL="gpt-4o"
3+
OPENAI_API_KEY=""
4+
OPENAI_AZURE_VERSION="2024-12-01-preview"
Lines changed: 181 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 🧑‍💻 Dagger Hackathon: June 18th, 2025
22

3-
Welcome to the Dagger hackathon hosted by the CNCF and Code to Cloud! By the end of this hack, you will have a good understanding of how to use Dagger and the various use cases it can help support.
3+
Welcome to the Dagger hackathon hosted by the [CNCF](https://community.cncf.io/cloud-native-calgary/) and [Code to Cloud](https://www.codetocloud.io/)! By the end of this hack, you will have a good understanding of how to use Dagger and the various use cases it can help support.
44

55
## 🎯 Expected Outcomes
66

@@ -10,36 +10,203 @@ Welcome to the Dagger hackathon hosted by the CNCF and Code to Cloud! By the end
1010

1111
✅ Dagger pipeline triggers LLM workflow if tests fail
1212

13-
✅ LLM provides feedback on why tests could be failing in a PR
13+
✅ LLM provides code suggestion to fix failing unit tests
14+
15+
✅ Code suggestion is added to PR
1416

1517
## ✅ Prerequisites
1618

1719
There are two options for this hackathon. We highly recommend the first option to avoid dependency issues.
1820

1921
### 1️⃣ Option 1: Github Codespace
2022

23+
See Getting Started
24+
2125
### 2️⃣ Option 2: Local
2226

27+
<img src="./assets/one_does_not_simply_meme.jpg" alt="anakin" width="400"/>
28+
2329
Make sure to follow the prerequisites defined [here](../README.md) in the main Dagger README.
2430

25-
## 🔨 Implementation
31+
## 🔨 Getting Started
32+
33+
---
34+
35+
### ✅ Step 1: Create a Dagger Cloud Account
36+
37+
- [Register for a account](https://dagger.io/cloud)
38+
- Under settings, create a `DAGGER_CLOUD_TOKEN` and copy the secret password somewhere temporary
39+
40+
> **Note:** This will be used to enable logging on the Dagger pipeline. Logs can be viewed in [Dagger Cloud](https://dagger.io/cloud) after step 5.
41+
42+
---
43+
44+
### ✅ Step 2: Fork This Repository
45+
46+
- Create a fork of this repository to your personal GitHub account
47+
If you already have a fork, either rebase to this repository or, if you don't have any work you want to keep, just delete and recreate.
48+
49+
- In the UI, create a new feature branch off `main`
50+
51+
---
52+
53+
### ✅ Step 2: Setup Codespace *(if you are setting up locally skip to Step 3)*
54+
55+
- In the GitHub UI, change to the newly created feature branch
56+
- Create a codespace on the feature branch
57+
58+
<img width="908" alt="image" src="https://github.com/user-attachments/assets/6d98a55a-207f-4389-b976-582fc3dec983" />
59+
60+
- This will auto-open VS Code in browser. If you don't want to work from here and have the VS Code app installed, you can close this and open it in the app
61+
62+
![image](https://github.com/user-attachments/assets/6b6b0702-b083-4e33-8868-675bfd6e5fc9)
63+
64+
---
65+
66+
### ✅ Step 3: Setup Locally *(if you did Step 2 then skip to Step 4)*
67+
68+
#### 🔧 Install required prerequisites
69+
70+
- Python 3.11+
71+
- [Docker Desktop](https://www.docker.com/products/docker-desktop/) or another container runtime (e.g. Colima on macOS and Linux)
72+
- [Dagger CLI](https://docs.dagger.io/install/)
73+
74+
#### 🔧 Additional Setup
75+
76+
- Start your container runtime
77+
- Clone the forked repository locally and switch to the newly created feature branch
78+
79+
---
80+
81+
### ✅ Step 4: Break Some Code and Open A PR
82+
83+
<img src="./assets/anakin_meme.webp" alt="anakin" width="400"/>
84+
85+
Now that we have all of our prerequisites setup, **this is where the fun begins!**
86+
87+
The below steps will take you through making a breaking change to a file in our application which will set us up in the next step to have our agent try and troubleshoot it.
2688

27-
All the code for the below can be found [here](./dagger-hackathon-pipeline/).
89+
- Open a terminal
90+
- Create an environment variable for `DAGGER_CLOUD_TOKEN`, e.g.
91+
```bash
92+
export DAGGER_CLOUD_TOKEN="XXX"
93+
```
94+
- Change directory into `docs/dagger/dagger-hackathon/`
95+
- Open the file `docs/dagger/dagger-hackathon/src/addition.py` and break the function
96+
For example, modify to: `return a + b * 4`
97+
- Run the unittests
98+
```bash
99+
python -m unittest discover tests -v
100+
```
101+
and confirm it fails
102+
- Push the modified `addition.py` to your new feature branch
103+
- In the GitHub UI, open a PR on the feature branch and compare to `main`
28104

29-
Make sure you have the repo cloned and you are in the `docs\dagger\dagger-hackathon-pipeline` directory:
105+
---
30106

31-
```bash
32-
# Clone the repository from GitHub
33-
git clone https://github.com/codetocloudorg/platform-engineering.git
107+
### ✅ Step 5: Run The Fix My Tests Agent
34108

35-
# Change directory to the Dagger hackathon pipeline documentation folder
36-
cd ./docs/dagger/dagger-hackathon-pipeline
109+
<img src="./assets/spongebob_meme.jpg" alt="spongebob" width="400"/>
110+
111+
- Rename `docs/dagger/dagger-hackathon/.env-example` to `.env`
112+
- Populate the placeholder keys with real values (we will provide for Hackathon day)
113+
- Create environment variables for `GITHUB_TOKEN`, `AZURE_API_KEY`, `AZURE_API_ENDPOINT`
114+
A GitHub Token can be created in GitHub under Settings → Developer Settings → Create a classic token
115+
Example:
116+
```bash
117+
export GITHUB_TOKEN="XXX"
118+
```
119+
120+
- Put in your values and run in CLI:
121+
```bash
122+
dagger call \
123+
--source="." \
124+
--github_branch="BRANCH-NAME" \
125+
--github_repo="USERNAME/REPO-NAME" \
126+
--github_token="GITHUB_TOKEN" \
127+
--azure_api_key="AZURE_API_KEY" \
128+
--azure_endpoint="AZURE_API_ENDPOINT" \
129+
fix-my-tests-agent
130+
```
131+
132+
> **💡 Tip:** This will be used to enable logging on the Dagger pipeline. Logs can be viewed in [Dagger Cloud](https://dagger.io/cloud) after step 5.
133+
134+
- If you see an error, it might be that the Agent has hallucinated — try again
135+
You can also debug via the Dagger Traces in Dagger Cloud
136+
137+
> **💡 Tip:** There is a prompt located at `docs\dagger\dagger-hackathon\dagger-hackathon-pipeline\debug_unit_test_prompt.md` that greatly influences the LLMs behavior. Make some changes to the prompt and see how it influences the results!
138+
139+
---
140+
141+
### ✅ Step 6: Explore Dagger Traces
142+
143+
<img src="./assets/fry_meme.jpg" alt="fry" width="400"/>
144+
145+
Being able to navigate and explore logs in Dagger Cloud is a great skill to have to be able to effectively troubleshoot and build pipelines in Dagger. Now that we have ran our first command in Dagger, lets jump into the logs to see what happened.
146+
147+
- Navigate to [Dagger Cloud](https://dagger.io/cloud)
148+
- You should see your trace(s)
149+
150+
![image](./assets/dagger_cloud.png)
151+
152+
- Select a trace and explore the logs
153+
- If all has gone well, you should see something like this at the bottom of the trace detailing the problematic file, line number, and fix for the failing unit test.
154+
155+
![image](./assets/agent_final_output.png)
156+
157+
---
158+
159+
### ✅ Step 7: Confirm The Agent Fixed the Code
160+
161+
<img src="./assets/pikachu_meme.jpg" alt="fry" width="400"/>
162+
163+
- If the Agent finished successfully, you should see something like below in the CLI
164+
```
165+
AgentResponse(pr_metadata=PrMetadataResult(pr_number='1', commit_id='c4293304b9fdccf2022e7e15e09e5b1604cecf04'), pr_suggestions=GitHubPrSuggestionResult(body='```suggestion\nreturn a + b\n```', comment_url='https://github.com/david-hurley/platform-engineering/pull/1#discussion_r2127910154'))
166+
```
167+
- Click the PR URL and see if there is a suggested code change
168+
169+
---
170+
171+
### ✅ Step 8: Trigger GitHub Action
172+
173+
- Delete the comment the Agent left on the PR in Step 6
174+
- [Create GitHub secrets](https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository) for everything in `.env` and name them `DAGGER_HACKATHON_GITHUB_TOKEN` and `OPENAI_API_KEY` for the GitHub token and Azure OpenAI API key respectively.
175+
- Make sure to update your GitHub Action to trigger on a pull request instead of a manual trigger.
176+
177+
Update the trigger from this:
178+
179+
```yaml
180+
on:
181+
workflow_dispatch:
182+
```
183+
184+
To this:
185+
```yaml
186+
on:
187+
pull_request:
188+
branches: [main]
189+
types: [opened, synchronize, reopened]
37190
```
38191
39-
### Step 1: Create a Feature Branch
192+
- Push your changes to Git and navigate back to your forked repo to see the GitHub Action running
193+
194+
![image](./assets/run_unit_tests.png)
195+
196+
---
197+
198+
### ✅ Step 9: Extend the Agent
199+
200+
The last step is to extend the Dagger agent to actually make the code fix itself and push the changes to the PR for the human to review. That way there is still a human-in-the-loop to validate the AI output.
40201
41-
### 🤖 Step 2: Select your LLM Provider
202+
---
42203
43-
### Step 3: Create a PR
204+
## ⚠️ Gotchas and Future Improvements
44205
45-
### Step 4: Run the Dagger Function
206+
- The agent can sometimes return incorrect paths to the file with breaking changes, incorrect line number of the breaking change, or incorrect fix (e.g. too verbose)
207+
- Current state of this does not work with multi-line code changes or multiple breaking changes.
208+
Only supports **1 breaking change on 1 line**
209+
- The way commit ID is retrieved is not robust — if a breaking change is pushed to a branch with an open PR and it is commit ID A, and then another file is pushed (commit ID B),
210+
the code is setup to grab the **latest commit ID**, not the one with the breaking change
211+
This may result in failure (i.e. no diff)
212+
- The agent leaves a comment on the PR as the idenity of whoever generated to token. In other words, if you leverage your GitHub token in the above steps, then the agent will leave a comment on the PR as you. This ideally should be a generic account in the future.
14.2 KB
Loading
24.9 KB
Loading
142 KB
Loading
52.2 KB
Loading
62.7 KB
Loading
49 KB
Loading
12.7 KB
Loading

0 commit comments

Comments
 (0)