File size: 8,014 Bytes
4b07aaf 85b7ac8 a7caaff 85b7ac8 4b07aaf 85b7ac8 4b07aaf 85b7ac8 4b07aaf 85b7ac8 4b07aaf 85b7ac8 4b07aaf 85b7ac8 4b07aaf 85b7ac8 4b07aaf | 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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | """Task 3: Workflow Syntax and Structure — EASY.
Agent fixes GitHub Actions YAML syntax and job structure issues:
step ordering, missing runs-on, invalid triggers, duplicate job IDs,
and missing 'on' trigger.
"""
from server.models import TaskDifficulty
from server.tasks.base import BaseTask
class WorkflowSyntaxStructureTask(BaseTask):
NAME = "Workflow Syntax and Structure"
DESCRIPTION = "Fix GitHub Actions YAML syntax and job structure issues"
DIFFICULTY = TaskDifficulty.EASY
AVAILABLE_SECRETS = ["GITHUB_TOKEN"]
SCENARIOS = [
# Scenario 1: Checkout happens after build (wrong step order)
{
"id": "checkout_after_build",
"files": [
{
"path": ".github/workflows/build.yml",
"type": "workflow",
"content": (
"name: Build\n"
"on: push\n"
"\n"
"jobs:\n"
" build:\n"
" runs-on: ubuntu-latest\n"
" steps:\n"
" - name: Build Docker image\n"
" run: docker build -t myapp .\n"
" - uses: actions/checkout@v4\n"
" - name: Run tests\n"
" run: docker run myapp pytest"
),
},
{
"path": "Dockerfile",
"type": "dockerfile",
"content": (
"FROM python:3.11-slim\n"
"WORKDIR /app\n"
"COPY . .\n"
'CMD ["python", "app.py"]'
),
},
],
"error": {
"phase": "workflow_parse",
"message": (
"unable to prepare context: unable to evaluate symlinks "
"in Dockerfile path: lstat /home/runner/work/repo/repo/Dockerfile: "
"no such file or directory"
),
"exit_code": 1,
"failed_step": "Build Docker image",
},
"expected_fixes": [
{
"file": ".github/workflows/build.yml",
"type": "contains",
"expected": "- uses: actions/checkout@v4",
"hint": "Checkout must happen before any build commands",
}
],
},
# Scenario 2: Missing runs-on field in job
{
"id": "missing_runs_on",
"files": [
{
"path": ".github/workflows/ci.yml",
"type": "workflow",
"content": (
"name: CI Pipeline\n"
"on: [push, pull_request]\n"
"\n"
"jobs:\n"
" test:\n"
" steps:\n"
" - uses: actions/checkout@v4\n"
" - name: Run tests\n"
" run: npm test"
),
},
],
"error": {
"phase": "workflow_parse",
"message": "Job 'test' is missing required field 'runs-on'",
"exit_code": 1,
},
"expected_fixes": [
{
"file": ".github/workflows/ci.yml",
"type": "contains",
"expected": "runs-on:",
"hint": "Every job must specify a 'runs-on' field (e.g. runs-on: ubuntu-latest)",
}
],
},
# Scenario 3: Invalid event trigger syntax
{
"id": "invalid_trigger_syntax",
"files": [
{
"path": ".github/workflows/deploy.yml",
"type": "workflow",
"content": (
"name: Deploy\n"
"on:\n"
" push:\n"
" branches: main\n"
"\n"
"jobs:\n"
" deploy:\n"
" runs-on: ubuntu-latest\n"
" steps:\n"
" - uses: actions/checkout@v4\n"
" - name: Deploy\n"
" run: echo 'deploying...'"
),
},
],
"error": {
"phase": "workflow_parse",
"message": (
"Unexpected value 'main' for 'on.push.branches'. "
"Expected a sequence (list) value."
),
"exit_code": 1,
},
"expected_fixes": [
{
"file": ".github/workflows/deploy.yml",
"type": "contains",
"expected": "branches: [main]",
"hint": "branches must be a list: branches: [main] or branches:\\n - main",
}
],
},
# Scenario 4: Duplicate step IDs / missing step name
{
"id": "missing_step_uses_or_run",
"files": [
{
"path": ".github/workflows/lint.yml",
"type": "workflow",
"content": (
"name: Lint\n"
"on: push\n"
"\n"
"jobs:\n"
" lint:\n"
" runs-on: ubuntu-latest\n"
" steps:\n"
" - uses: actions/checkout@v4\n"
" - name: Install dependencies\n"
" run: npm ci\n"
" - name: Run linter\n"
),
},
],
"error": {
"phase": "workflow_parse",
"message": "Every step must define a 'uses' or 'run' key. Step 'Run linter' has neither.",
"exit_code": 1,
},
"expected_fixes": [
{
"file": ".github/workflows/lint.yml",
"type": "contains",
"expected": "run:",
"hint": "The 'Run linter' step is missing a 'run' command — add e.g. run: npm run lint",
}
],
},
# Scenario 5: Missing 'on' trigger entirely
{
"id": "missing_on_trigger",
"files": [
{
"path": ".github/workflows/test.yml",
"type": "workflow",
"content": (
"name: Test Suite\n"
"\n"
"jobs:\n"
" test:\n"
" runs-on: ubuntu-latest\n"
" steps:\n"
" - uses: actions/checkout@v4\n"
" - name: Run tests\n"
" run: pytest tests/ -v"
),
},
],
"error": {
"phase": "workflow_parse",
"message": "Workflow must define an 'on' trigger event",
"exit_code": 1,
},
"expected_fixes": [
{
"file": ".github/workflows/test.yml",
"type": "contains",
"expected": "on:",
"hint": "Workflow is missing the required 'on' trigger — add e.g. on: push",
}
],
},
]
|