Report temporary metadata cleanup failures
This commit is contained in:
@@ -3,6 +3,7 @@ package git
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -12,6 +13,10 @@ import (
|
||||
// on the captured commit. Once its type and ID are established, the ID is
|
||||
// returned even if a later verification fails.
|
||||
func CreateAnnotatedTag(ctx context.Context, repositoryDir, tag, commit string, note []byte) (string, error) {
|
||||
return createAnnotatedTag(ctx, repositoryDir, tag, commit, note, os.Remove)
|
||||
}
|
||||
|
||||
func createAnnotatedTag(ctx context.Context, repositoryDir, tag, commit string, note []byte, remove func(string) error) (objectID string, resultErr error) {
|
||||
if err := CheckTagRef(ctx, repositoryDir, tag); err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -23,7 +28,11 @@ func CreateAnnotatedTag(ctx context.Context, repositoryDir, tag, commit string,
|
||||
return "", fmt.Errorf("create temporary release note: %w", err)
|
||||
}
|
||||
messagePath := message.Name()
|
||||
defer os.Remove(messagePath)
|
||||
defer func() {
|
||||
if err := remove(messagePath); err != nil {
|
||||
resultErr = errors.Join(resultErr, fmt.Errorf("remove temporary release note %q: %w", messagePath, err))
|
||||
}
|
||||
}()
|
||||
if _, err := message.Write(note); err != nil {
|
||||
_ = message.Close()
|
||||
return "", fmt.Errorf("write temporary release note: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user