|
| 1 | +# Workflow: Triggers when a PR contains YAML in ea-agent/requests |
| 2 | +# This is decoupled from JIRA - can be triggered by: |
| 3 | +# 1. JIRA (via Workflow 1) - WIP |
| 4 | +# 2. Manual PR creation by developer - This workflow |
| 5 | +# 3. Comment "/generate-ea" on a PR - This workflow |
| 6 | + |
| 7 | +name: "Generate EA from YAML" |
| 8 | + |
| 9 | +on: |
| 10 | + pull_request: |
| 11 | + types: [opened] |
| 12 | + paths: |
| 13 | + - "ea-agent/requests/**/*.yaml" |
| 14 | + - "ea-agent/requests/**/*.yml" |
| 15 | + issue_comment: |
| 16 | + types: [created] |
| 17 | + |
| 18 | +jobs: |
| 19 | + generate-ea: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + # Run on PR events OR when "/generate-ea" comment is posted on a PR |
| 22 | + if: | |
| 23 | + github.event_name == 'pull_request' || |
| 24 | + (github.event_name == 'issue_comment' && |
| 25 | + github.event.issue.pull_request && |
| 26 | + contains(github.event.comment.body, '/generate-ea')) |
| 27 | + permissions: |
| 28 | + contents: write |
| 29 | + pull-requests: write |
| 30 | + id-token: write # Required for GCP authentication |
| 31 | + |
| 32 | + steps: |
| 33 | + - name: Get PR details (for comment trigger) |
| 34 | + if: github.event_name == 'issue_comment' |
| 35 | + id: pr |
| 36 | + uses: actions/github-script@v7 |
| 37 | + with: |
| 38 | + script: | |
| 39 | + const { data: pr } = await github.rest.pulls.get({ |
| 40 | + owner: context.repo.owner, |
| 41 | + repo: context.repo.repo, |
| 42 | + pull_number: context.issue.number |
| 43 | + }); |
| 44 | + core.setOutput('head_ref', pr.head.ref); |
| 45 | + core.setOutput('number', pr.number); |
| 46 | +
|
| 47 | + - name: Check out repository |
| 48 | + uses: actions/checkout@v4.2.2 |
| 49 | + with: |
| 50 | + ref: ${{ github.event_name == 'issue_comment' && steps.pr.outputs.head_ref || github.head_ref }} |
| 51 | + fetch-depth: 0 |
| 52 | + token: ${{ github.token }} |
| 53 | + |
| 54 | + - name: Install uv |
| 55 | + uses: astral-sh/setup-uv@v4 |
| 56 | + |
| 57 | + - name: Set up Python |
| 58 | + uses: actions/setup-python@v5.2.0 |
| 59 | + with: |
| 60 | + python-version: "3.11" |
| 61 | + |
| 62 | + - name: Authenticate to Google Cloud |
| 63 | + id: auth |
| 64 | + uses: google-github-actions/auth@b7593ed2efd1c1617e1b0254da33b86225adb2a5 # v2.1.12 |
| 65 | + with: |
| 66 | + credentials_json: ${{ secrets.CC_GHA_GCP_SERVICE_ACCOUNT_KEY }} |
| 67 | + create_credentials_file: true |
| 68 | + export_environment_variables: true |
| 69 | + env: |
| 70 | + # Ensure credentials are created outside the git repository |
| 71 | + GOOGLE_APPLICATION_CREDENTIALS_FILE_PATH: /tmp/gcp-credentials.json |
| 72 | + |
| 73 | + - name: Configure environment for Claude Code |
| 74 | + run: | |
| 75 | + echo "CLAUDE_CODE_USE_VERTEX=1" >> $GITHUB_ENV |
| 76 | + echo "CLOUD_ML_REGION=us-east5" >> $GITHUB_ENV |
| 77 | + echo "ANTHROPIC_VERTEX_PROJECT_ID=${{ secrets.CC_GHA_GCP_PROJECT_ID }}" >> $GITHUB_ENV |
| 78 | + echo "DISABLE_PROMPT_CACHING=0" >> $GITHUB_ENV |
| 79 | + echo "DISABLE_TELEMETRY=1" >> $GITHUB_ENV |
| 80 | + echo "DISABLE_ERROR_REPORTING=1" >> $GITHUB_ENV |
| 81 | + echo "DISABLE_BUG_COMMAND=1" >> $GITHUB_ENV |
| 82 | + echo "CI=true" >> $GITHUB_ENV |
| 83 | + echo "TERM=dumb" >> $GITHUB_ENV |
| 84 | + echo "NO_COLOR=1" >> $GITHUB_ENV |
| 85 | + echo "FORCE_COLOR=0" >> $GITHUB_ENV |
| 86 | + echo "DEBIAN_FRONTEND=noninteractive" >> $GITHUB_ENV |
| 87 | +
|
| 88 | + - name: Configure Git |
| 89 | + run: | |
| 90 | + git config --global user.name "github-actions[bot]" |
| 91 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 92 | +
|
| 93 | + - name: Get YAML file from PR |
| 94 | + id: yaml |
| 95 | + uses: actions/github-script@v7 |
| 96 | + with: |
| 97 | + script: | |
| 98 | + // Determine PR number based on trigger type |
| 99 | + const prNumber = context.eventName === 'issue_comment' |
| 100 | + ? context.issue.number |
| 101 | + : context.payload.pull_request.number; |
| 102 | +
|
| 103 | + // Get all files changed in this PR |
| 104 | + const files = await github.rest.pulls.listFiles({ |
| 105 | + owner: context.repo.owner, |
| 106 | + repo: context.repo.repo, |
| 107 | + pull_number: prNumber |
| 108 | + }); |
| 109 | +
|
| 110 | + console.log(`Found ${files.data.length} files in PR`); |
| 111 | +
|
| 112 | + // Find YAML file in ea-requests/ |
| 113 | + const yamlFile = files.data.find(f => |
| 114 | + f.filename.startsWith('ea-requests/') && |
| 115 | + (f.filename.endsWith('.yaml') || f.filename.endsWith('.yml')) && |
| 116 | + f.status !== 'removed' |
| 117 | + ); |
| 118 | +
|
| 119 | + if (!yamlFile) { |
| 120 | + core.setFailed('No YAML file found in ea-requests/'); |
| 121 | + return; |
| 122 | + } |
| 123 | +
|
| 124 | + console.log(`Found YAML file: ${yamlFile.filename}`); |
| 125 | +
|
| 126 | + // Extract JIRA key from filename (e.g., ea-requests/EA-123.yaml -> EA-123) |
| 127 | + const filename = yamlFile.filename.split('/').pop(); |
| 128 | + const jiraKey = filename.replace(/\.ya?ml$/, ''); |
| 129 | +
|
| 130 | + core.setOutput('file', yamlFile.filename); |
| 131 | + core.setOutput('jira_key', jiraKey); |
| 132 | +
|
| 133 | + console.log(`JIRA Key: ${jiraKey}`); |
| 134 | +
|
| 135 | + - name: Display found YAML |
| 136 | + run: | |
| 137 | + echo "📄 YAML File: ${{ steps.yaml.outputs.file }}" |
| 138 | + echo "🎫 JIRA Key: ${{ steps.yaml.outputs.jira_key }}" |
| 139 | + echo "" |
| 140 | + echo "=== YAML Contents ===" |
| 141 | + cat "${{ steps.yaml.outputs.file }}" |
| 142 | +
|
| 143 | + - name: Install dependencies |
| 144 | + run: | |
| 145 | + uv sync |
| 146 | +
|
| 147 | + - name: Install Node.js |
| 148 | + uses: actions/setup-node@v4.0.3 |
| 149 | + with: |
| 150 | + node-version: '22' |
| 151 | + |
| 152 | + - name: Install Claude Code |
| 153 | + run: | |
| 154 | + npm install -g @anthropic-ai/claude-code |
| 155 | +
|
| 156 | + - name: Run EA workflow |
| 157 | + id: ea |
| 158 | + run: | |
| 159 | + echo "🚀 Starting EA generation..." |
| 160 | + uv run python ea_agent.py "${{ steps.yaml.outputs.file }}" |
| 161 | +
|
| 162 | + - name: Check for changes |
| 163 | + id: changes |
| 164 | + run: | |
| 165 | + # Remove any sensitive files that might have been created |
| 166 | + find . -name "gha-creds-*.json" -delete || true |
| 167 | + find . -name "*-credentials.json" -delete || true |
| 168 | +
|
| 169 | + # Check for both modified files and untracked files |
| 170 | + MODIFIED_FILES=$(git diff --name-only) |
| 171 | + UNTRACKED_FILES=$(git ls-files --others --exclude-standard) |
| 172 | +
|
| 173 | + echo "Modified files: $MODIFIED_FILES" |
| 174 | + echo "Untracked files: $UNTRACKED_FILES" |
| 175 | +
|
| 176 | + if [ -z "$MODIFIED_FILES" ] && [ -z "$UNTRACKED_FILES" ]; then |
| 177 | + echo "No changes were made" |
| 178 | + echo "has_changes=false" >> $GITHUB_OUTPUT |
| 179 | + else |
| 180 | + echo "Changes detected" |
| 181 | + echo "has_changes=true" >> $GITHUB_OUTPUT |
| 182 | + |
| 183 | + # Show what files have changed (for debugging) |
| 184 | + echo "Files that changed:" |
| 185 | + git status --porcelain |
| 186 | + fi |
| 187 | +
|
| 188 | + - name: Commit generated code |
| 189 | + if: steps.changes.outputs.has_changes == 'true' |
| 190 | + id: commit |
| 191 | + run: | |
| 192 | + git add -A |
| 193 | +
|
| 194 | + git commit -m "feat(${{ steps.yaml.outputs.jira_key }}): Generated EA code" |
| 195 | + git push |
| 196 | + echo "has_changes=true" >> $GITHUB_OUTPUT |
| 197 | + echo "✅ Changes committed and pushed" |
| 198 | +
|
| 199 | + - name: Update PR description |
| 200 | + uses: actions/github-script@v7 |
| 201 | + with: |
| 202 | + script: | |
| 203 | + const jiraKey = '${{ steps.yaml.outputs.jira_key }}'; |
| 204 | + const yamlFile = '${{ steps.yaml.outputs.file }}'; |
| 205 | + const hasChanges = '${{ steps.changes.outputs.has_changes }}' === 'true'; |
| 206 | +
|
| 207 | + // Determine PR number based on trigger type |
| 208 | + const prNumber = context.eventName === 'issue_comment' |
| 209 | + ? context.issue.number |
| 210 | + : context.payload.pull_request.number; |
| 211 | +
|
| 212 | + const body = `## 📋 EA Request |
| 213 | +
|
| 214 | + | Field | Value | |
| 215 | + |-------|-------| |
| 216 | + | **JIRA Issue** | ${jiraKey} | |
| 217 | + | **YAML File** | \`${yamlFile}\` | |
| 218 | +
|
| 219 | + --- |
| 220 | +
|
| 221 | + ✅ **EA Generation Complete!** |
| 222 | +
|
| 223 | + ${hasChanges ? 'Generated code has been committed to this PR.' : 'No new code changes were generated.'} |
| 224 | +
|
| 225 | + ### Review Checklist |
| 226 | + - [ ] Code structure is correct |
| 227 | + - [ ] Tests pass |
| 228 | + - [ ] Configuration is correct |
| 229 | + - [ ] Documentation is adequate |
| 230 | +
|
| 231 | + --- |
| 232 | + _Ready for review and merge._`; |
| 233 | +
|
| 234 | + await github.rest.pulls.update({ |
| 235 | + owner: context.repo.owner, |
| 236 | + repo: context.repo.repo, |
| 237 | + pull_number: prNumber, |
| 238 | + body: body |
| 239 | + }); |
| 240 | +
|
| 241 | + console.log('✅ PR description updated'); |
0 commit comments