-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathaction.yml
More file actions
142 lines (126 loc) · 5.44 KB
/
action.yml
File metadata and controls
142 lines (126 loc) · 5.44 KB
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
name: "CodeGlide MCP Generator"
description: "Run codeglide to create MCP server for APIs. Input dir contains API source code."
branding:
icon: "zap"
color: "purple"
inputs:
input_directory:
description: 'Input directory containing API source code (relative to workspace). Defaults to project root.'
required: false
default: '.'
create_pr:
description: 'Create PR with generated code. Falls back to branch/commit or artifact upload if no push permissions.'
required: false
default: false
type: boolean
create_branch_and_commit:
description: 'Create branch and commit with generated code. Falls back to artifact upload if no push permissions.'
required: false
default: false
type: boolean
custom_headers:
description: 'Custom headers to include in all API requests (JSON format, e.g., {"Authorization": "Bearer token", "X-API-Key": "key"})'
required: false
default: '{}'
check_api_changes:
description: 'Enable API change detection'
required: false
default: true
type: boolean
changed_files:
description: 'List of changed files (newline-separated) to check for API changes'
required: false
default: ''
runs:
using: "composite"
steps:
- name: Run Codeglide MCP gen
shell: bash
run: |
mkdir -p "generated-mcp"
echo "Running container..."
# Handle directory mounting (defaults to project root)
if [[ "${{ inputs.input_directory }}" == "." ]] || [[ -z "${{ inputs.input_directory }}" ]]; then
INPUT_PATH="${{ github.workspace }}"
else
INPUT_PATH="${{ github.workspace }}/${{ inputs.input_directory }}"
fi
docker pull --quiet ghcr.io/codeglide/mcpgen:latest>/dev/null
docker run --rm \
-e GITHUB_REPOSITORY="${{ github.repository }}" \
-e GITHUB_ACTOR="${{ github.actor }}" \
-e GITHUB_ACTIONS=$GITHUB_ACTIONS \
-e CHECK_API_CHANGES="${{ inputs.check_api_changes }}" \
-e CHANGED_FILES="${{ inputs.changed_files }}" \
--env CUSTOM_HEADERS='${{ inputs.custom_headers }}' \
-v "$INPUT_PATH:/app/input" \
-v "${{ github.workspace }}/generated-mcp:/app/output" \
ghcr.io/codeglide/mcpgen:latest
- name: Create PR / Branch
if: ${{ (github.event_name == 'push' || inputs.create_pr == true || inputs.create_branch_and_commit == true) && hashFiles('generated-mcp/**') != '' }}
shell: bash
id: branch_creation
continue-on-error: true
env:
GH_TOKEN: ${{ github.token }}
run: |
echo "Creating branch and/or PR as requested..."
# Configure git with GitHub Actions identity
git config --global user.name "CodeGlide-[bot]"
git config --global user.email "codeglide-[bot]@users.noreply.github.com"
# Create new branch
BRANCH_NAME="feat/mcp-server-updated/$(date +%Y-%m-%d)--$(date +%H-%M-%S)"
git checkout -b $BRANCH_NAME
# Determine MCP directory location
if [[ "${{ inputs.input_directory }}" == "." ]] || [[ -z "${{ inputs.input_directory }}" ]]; then
MCP_DIR="MCP"
else
MCP_DIR="${{ inputs.input_directory }}/MCP"
fi
# Create MCP directory if it doesn't exist
mkdir -p "$MCP_DIR"
# Copy generated files
cp -r generated-mcp/* "$MCP_DIR/"
# Commit and push
git add "$MCP_DIR"
git commit -m "feat: codeglide Auto-generated MCP server code
Triggered by: @${{ github.actor }}"
# Try to push the branch
if git push origin $BRANCH_NAME; then
echo "Branch created and pushed successfully!"
echo "Branch name: $BRANCH_NAME"
# Try to create PR if requested
if [[ "${{ inputs.create_pr }}" == "true" ]]; then
echo "Creating pull request..."
PR_URL=$(gh pr create \
--base "${{ github.ref_name }}" \
--head "$BRANCH_NAME" \
--title "feat: Updated MCP server with latest generated code" \
--body "Auto generated PR with MCP server code by CodeGlide.
**Generated by:** CodeGlide MCP Generator
**Triggered by:** @${{ github.actor }}")
if [ $? -eq 0 ]; then
echo "Pull request created successfully!"
echo "View PR at: $PR_URL"
else
echo "Could not create PR (insufficient permissions)"
echo "To create a PR manually, visit:"
echo "https://github.com/${{ github.repository }}/compare/${{ github.ref_name }}...$BRANCH_NAME"
fi
else
echo "Branch created successfully (no PR requested)"
echo "To create a PR manually, visit:"
echo "https://github.com/${{ github.repository }}/compare/${{ github.ref_name }}...$BRANCH_NAME"
fi
echo "success=true" >> $GITHUB_OUTPUT
else
echo "Failed to push branch. Will upload as artifact instead."
echo "success=false" >> $GITHUB_OUTPUT
exit 1
fi
- name: Upload MCP Server as Artifact
if: ${{ ((inputs.create_pr != true && inputs.create_branch_and_commit != true) || (steps.branch_creation.outputs.success != 'true')) && hashFiles('generated-mcp/**') != '' }}
uses: actions/upload-artifact@v4
with:
name: generated-mcp-server
path: generated-mcp/