Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jun 11, 2025

The deploy workflow was failing on scheduled runs with the error:

fatal: not a git repository (or any of the parent directories): .git
InvalidOperation: You cannot call a method on a null-valued expression.

This occurred because the deploy job attempted to execute git describe --tags --abbrev=0 without having access to the git repository, causing:

  1. git describe to fail with "fatal: not a git repository"
  2. $tagVersion to become null
  3. .StartsWith() method calls to fail with null reference errors

Changes Made

Added Git Repository Access

  • Added actions/checkout@v4 step to the deploy job with fetch-depth: 0 and fetch-tags: true
  • This provides the necessary git repository context for tag operations

Added Robust Error Handling

  • Wrapped git describe --tags --abbrev=0 calls with proper error checking using $LASTEXITCODE
  • Added fallback version logic (0.0.1) when no tags are found
  • Applied consistent error handling to both build-and-pack and deploy jobs

Before (failing):

$tagVersion = & git describe --tags --abbrev=0  # Fails with no git repo
if ($tagVersion.StartsWith("v")) {              # Null reference error
  $tagVersion = $tagVersion.Substring(1)
}

After (working):

$latestTag = & git describe --tags --abbrev=0 2>&1
if ($LASTEXITCODE -eq 0) {
  $tagVersion = $latestTag
  if ($tagVersion.StartsWith("v")) {
    $tagVersion = $tagVersion.Substring(1)
  }
} else {
  Write-Host "No tags found, using fallback version"
  $tagVersion = "0.0.1"
}

The fix ensures scheduled deployments work correctly even in repositories without existing tags, while maintaining backward compatibility with tagged releases.

Fixes #241.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…ror handling

Co-authored-by: BenjaminMichaelis <22186029+BenjaminMichaelis@users.noreply.github.com>
Copilot AI changed the title [WIP] On scheduled run, deploy erro Fix deploy workflow error on scheduled runs - add git checkout and error handling Jun 11, 2025
Copilot AI requested a review from BenjaminMichaelis June 11, 2025 21:01
Copilot finished work on behalf of BenjaminMichaelis June 11, 2025 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

On scheduled run, deploy erro

2 participants