Skip to content

Commit 8962bd5

Browse files
committed
Improved empty repo handling on deploy scripts, and added step to coder workflow to comment on issue once work is in progress
1 parent ddd0af0 commit 8962bd5

File tree

3 files changed

+104
-4
lines changed

3 files changed

+104
-4
lines changed

.github/workflows/copilot-coder-master.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ jobs:
100100
gh issue edit ${{ env.ISSUE_NUMBER }} \
101101
--add-label "in-progress" \
102102
--remove-label "copilot"
103+
104+
# Add comment to notify that Copilot is working on this issue
105+
COMMENT="## 🤖 Copilot is on it!
106+
107+
Copilot has been assigned to work on this issue. You can view progress under [GitHub Actions](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}), and once completed a PR will be linked here."
108+
109+
gh issue comment "${{ env.ISSUE_NUMBER }}" --body "${COMMENT}"
103110
env:
104111
GH_TOKEN: ${{ secrets.GH_TOKEN }}
105112

scripts/deploy-to-repo.ps1

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,27 @@ try {
129129
git config user.name "GitHub Copilot Setup"
130130
git config user.email "copilot-setup@$GhesHost"
131131

132+
# Check if repo is empty (no commits yet)
133+
$IsEmptyRepo = $false
134+
git rev-parse HEAD 2>$null
135+
if ($LASTEXITCODE -ne 0) {
136+
$IsEmptyRepo = $true
137+
Write-Warning "Empty repository detected - will initialize with main branch"
138+
}
139+
132140
# Create branch for deployment
133141
$BranchName = "setup/copilot-workflows"
134-
git checkout -b $BranchName 2>$null
135-
if ($LASTEXITCODE -ne 0) {
136-
git checkout $BranchName
142+
143+
if ($IsEmptyRepo) {
144+
# For empty repos, create the main branch
145+
git checkout -b main 2>$null
146+
}
147+
else {
148+
# For existing repos, create feature branch
149+
git checkout -b $BranchName 2>$null
150+
if ($LASTEXITCODE -ne 0) {
151+
git checkout $BranchName
152+
}
137153
}
138154

139155
Write-Step "Creating directory structure..."
@@ -185,6 +201,38 @@ Prerequisites:
185201
git commit -m $CommitMessage
186202

187203
Write-Step "Pushing branch..."
204+
205+
if ($IsEmptyRepo) {
206+
# For empty repos: just push main directly (no PR needed)
207+
Write-Warning "Initializing main branch..."
208+
git push -u origin main
209+
if ($LASTEXITCODE -ne 0) {
210+
throw "Failed to push main branch"
211+
}
212+
213+
Write-Host ""
214+
Write-ColorOutput "============================================================================" "Green"
215+
Write-ColorOutput " ✅ Deployment Complete (Empty Repository Initialized)!" "Green"
216+
Write-ColorOutput "============================================================================" "Green"
217+
Write-Host ""
218+
Write-Host "Workflows committed directly to main branch: " -NoNewline
219+
Write-ColorOutput "https://$GhesHost/$Owner/$Repo" "Cyan"
220+
Write-Host ""
221+
Write-ColorOutput "⚠️ Next Steps:" "Yellow"
222+
Write-Host ""
223+
Write-Host "1. Add these secrets to the organization or repository:"
224+
Write-Host " - GH_TOKEN: Classic PAT with repo, workflow scopes (from GHES)"
225+
Write-Host " - COPILOT_TOKEN: Token for Copilot API"
226+
Write-Host " - CONTEXT7_API_KEY: (Optional) Context7 API key"
227+
Write-Host ""
228+
Write-Host "2. Ensure your self-hosted runner has GitHub CLI installed:"
229+
Write-Host " See: https://cli.github.com/manual/installation"
230+
Write-Host ""
231+
Write-ColorOutput "Done!" "Green"
232+
return
233+
}
234+
235+
# For existing repos: push feature branch and create PR
188236
git push -u origin $BranchName
189237
if ($LASTEXITCODE -ne 0) {
190238
throw "Failed to push branch"

scripts/deploy-to-repo.sh

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,24 @@ cd target-repo
7777
git config user.name "GitHub Copilot Setup"
7878
git config user.email "copilot-setup@${GHES_HOST}"
7979

80+
# Check if repo is empty (no commits yet)
81+
IS_EMPTY_REPO=false
82+
if ! git rev-parse HEAD >/dev/null 2>&1; then
83+
IS_EMPTY_REPO=true
84+
echo -e "${YELLOW} ⚠ Empty repository detected - will initialize with main branch${NC}"
85+
fi
86+
8087
# Create branch for deployment
8188
BRANCH_NAME="setup/copilot-workflows"
82-
git checkout -b "$BRANCH_NAME" 2>/dev/null || git checkout "$BRANCH_NAME"
89+
90+
if [ "$IS_EMPTY_REPO" = true ]; then
91+
# For empty repos, we need to create the main branch first with an initial commit
92+
# then create the feature branch from it
93+
git checkout -b main 2>/dev/null || true
94+
else
95+
# For existing repos, create feature branch
96+
git checkout -b "$BRANCH_NAME" 2>/dev/null || git checkout "$BRANCH_NAME"
97+
fi
8398

8499
echo ""
85100
echo -e "${YELLOW}📁 Creating directory structure...${NC}"
@@ -145,6 +160,36 @@ Prerequisites:
145160

146161
echo ""
147162
echo -e "${YELLOW}🚀 Pushing branch...${NC}"
163+
164+
if [ "$IS_EMPTY_REPO" = true ]; then
165+
# For empty repos: just push main directly (no PR needed)
166+
echo -e "${YELLOW} Initializing main branch...${NC}"
167+
git push -u origin main
168+
169+
echo ""
170+
echo -e "${GREEN}============================================================================${NC}"
171+
echo -e "${GREEN} ✅ Deployment Complete (Empty Repository Initialized)!${NC}"
172+
echo -e "${GREEN}============================================================================${NC}"
173+
echo ""
174+
echo -e "Workflows committed directly to main branch: ${BLUE}https://${GHES_HOST}/${OWNER}/${REPO}${NC}"
175+
echo ""
176+
echo -e "${YELLOW}⚠️ Next Steps:${NC}"
177+
echo ""
178+
echo "1. Add these secrets to the repository:"
179+
echo " - GH_TOKEN: Classic PAT with repo, workflow scopes (from GHES)"
180+
echo " - COPILOT_TOKEN: Token for Copilot API"
181+
echo " - CONTEXT7_API_KEY: (Optional) Context7 API key"
182+
echo ""
183+
echo "2. Ensure your self-hosted runner has GitHub CLI installed:"
184+
echo " curl -L https://github.com/cli/cli/releases/download/v2.62.0/gh_2.62.0_linux_amd64.tar.gz -o /tmp/gh.tar.gz"
185+
echo " tar -xzf /tmp/gh.tar.gz -C /tmp"
186+
echo " sudo mv /tmp/gh_2.62.0_linux_amd64/bin/gh /usr/local/bin/"
187+
echo ""
188+
echo -e "${GREEN}Done!${NC}"
189+
exit 0
190+
fi
191+
192+
# For existing repos: push feature branch and create PR
148193
git push -u origin "$BRANCH_NAME"
149194

150195
echo ""

0 commit comments

Comments
 (0)