FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix audit findings across vitals and sync commands · AndroidPoet/playconsole-cli@ede9458 · GitHub

Commit ede9458

Browse files
committed
Fix audit findings across vitals and sync commands
1 parent 18b8db7 commit ede9458

6 files changed

Lines changed: 522 additions & 349 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ jobs:
4747
with:
4848
version: latest
4949
args: --timeout=5m
50-
continue-on-error: true
5150

5251
validate-goreleaser:
5352
name: Validate GoReleaser
@@ -70,4 +69,3 @@ jobs:
7069
distribution: goreleaser
7170
version: latest
7271
args: check
73-
continue-on-error: true

‎cmd/playconsole-cli/commands/images/images.go‎

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99

1010
"github.com/spf13/cobra"
1111

12-
"github.com/AndroidPoet/playconsole-cli/internal/cli"
1312
"github.com/AndroidPoet/playconsole-cli/internal/api"
13+
"github.com/AndroidPoet/playconsole-cli/internal/cli"
1414
"github.com/AndroidPoet/playconsole-cli/internal/output"
1515
)
1616

@@ -136,9 +136,9 @@ func init() {
136136

137137
// ImageInfo represents image information
138138
type ImageInfo struct {
139-
ID string `json:"id"`
140-
URL string `json:"url,omitempty"`
141-
SHA1 string `json:"sha1,omitempty"`
139+
ID string `json:"id"`
140+
URL string `json:"url,omitempty"`
141+
SHA1 string `json:"sha1,omitempty"`
142142
SHA256 string `json:"sha256,omitempty"`
143143
}
144144

@@ -180,9 +180,9 @@ func runList(cmd *cobra.Command, args []string) error {
180180
result := make([]ImageInfo, 0, len(images.Images))
181181
for _, img := range images.Images {
182182
result = append(result, ImageInfo{
183-
ID: img.Id,
184-
URL: img.Url,
185-
SHA1: img.Sha1,
183+
ID: img.Id,
184+
URL: img.Url,
185+
SHA1: img.Sha1,
186186
SHA256: img.Sha256,
187187
})
188188
}
@@ -249,8 +249,8 @@ func runUpload(cmd *cobra.Command, args []string) error {
249249

250250
output.PrintSuccess("Image uploaded: %s", image.Image.Id)
251251
return output.Print(ImageInfo{
252-
ID: image.Image.Id,
253-
SHA1: image.Image.Sha1,
252+
ID: image.Image.Id,
253+
SHA1: image.Image.Sha1,
254254
SHA256: image.Image.Sha256,
255255
})
256256
}
@@ -372,6 +372,8 @@ func runSync(cmd *cobra.Command, args []string) error {
372372

373373
ctx := edit.Context()
374374
uploaded := 0
375+
changed := false
376+
failures := make([]string, 0)
375377

376378
// Walk directory: locale/imageType/files
377379
locales, err := os.ReadDir(absDir)
@@ -405,46 +407,61 @@ func runSync(cmd *cobra.Command, args []string) error {
405407
typeDir := filepath.Join(localeDir, typeName)
406408
files, err := os.ReadDir(typeDir)
407409
if err != nil {
410+
failures = append(failures, fmt.Sprintf("%s/%s: %v", localeName, typeName, err))
408411
continue
409412
}
410413

414+
localFiles := make([]string, 0)
411415
for _, fileEntry := range files {
412416
if fileEntry.IsDir() {
413417
continue
414418
}
415419

416-
filePath := filepath.Join(typeDir, fileEntry.Name())
417420
ext := strings.ToLower(filepath.Ext(fileEntry.Name()))
418421
if ext != ".png" && ext != ".jpg" && ext != ".jpeg" {
419422
continue
420423
}
421424

422-
if cli.IsDryRun() {
423-
output.PrintInfo("Dry run: would upload %s to %s/%s", fileEntry.Name(), localeName, typeName)
424-
continue
425-
}
425+
localFiles = append(localFiles, filepath.Join(typeDir, fileEntry.Name()))
426+
}
426427

427-
file, err := os.Open(filePath)
428+
if cli.IsDryRun() {
429+
output.PrintInfo("Dry run: would replace %s/%s with %d image(s)", localeName, typeName, len(localFiles))
430+
continue
431+
}
432+
433+
if _, err := edit.Images().Deleteall(client.GetPackageName(), edit.ID(), localeName, typeName).Context(ctx).Do(); err != nil {
434+
failures = append(failures, fmt.Sprintf("%s/%s: failed to clear existing images: %v", localeName, typeName, err))
435+
continue
436+
}
437+
changed = true
438+
439+
for _, localFile := range localFiles {
440+
file, err := os.Open(localFile)
428441
if err != nil {
429-
output.PrintWarning("Failed to open %s: %v", filePath, err)
442+
failures = append(failures, fmt.Sprintf("%s/%s/%s: %v", localeName, typeName, filepath.Base(localFile), err))
430443
continue
431444
}
432445

433446
_, err = edit.Images().Upload(client.GetPackageName(), edit.ID(), localeName, typeName).Media(file).Context(ctx).Do()
434447
file.Close()
435448

436449
if err != nil {
437-
output.PrintWarning("Failed to upload %s: %v", fileEntry.Name(), err)
450+
failures = append(failures, fmt.Sprintf("%s/%s/%s: %v", localeName, typeName, filepath.Base(localFile), err))
438451
continue
439452
}
440453

441-
output.PrintInfo("Uploaded: %s/%s/%s", localeName, typeName, fileEntry.Name())
454+
output.PrintInfo("Uploaded: %s/%s/%s", localeName, typeName, filepath.Base(localFile))
442455
uploaded++
443456
}
444457
}
445458
}
446459

447-
if !cli.IsDryRun() && uploaded > 0 {
460+
if len(failures) > 0 {
461+
return fmt.Errorf("image sync aborted; no changes committed. Failures: %s", strings.Join(failures, "; "))
462+
}
463+
464+
if !cli.IsDryRun() && changed {
448465
if err := edit.Commit(); err != nil {
449466
return err
450467
}

‎cmd/playconsole-cli/commands/listings/listings.go‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import (
44
"fmt"
55
"os"
66
"path/filepath"
7+
"strings"
78
"time"
89

910
"github.com/spf13/cobra"
1011
"google.golang.org/api/androidpublisher/v3"
1112

12-
"github.com/AndroidPoet/playconsole-cli/internal/cli"
1313
"github.com/AndroidPoet/playconsole-cli/internal/api"
14+
"github.com/AndroidPoet/playconsole-cli/internal/cli"
1415
"github.com/AndroidPoet/playconsole-cli/internal/output"
1516
)
1617

@@ -59,12 +60,12 @@ Expected structure (fastlane-compatible):
5960
}
6061

6162
var (
62-
locale string
63-
title string
64-
shortDesc string
65-
fullDesc string
66-
fullDescFile string
67-
syncDir string
63+
locale string
64+
title string
65+
shortDesc string
66+
fullDesc string
67+
fullDescFile string
68+
syncDir string
6869
)
6970

7071
func init() {
@@ -275,6 +276,7 @@ func runSync(cmd *cobra.Command, args []string) error {
275276

276277
ctx := edit.Context()
277278
updated := 0
279+
failures := make([]string, 0)
278280

279281
for _, entry := range entries {
280282
if !entry.IsDir() {
@@ -315,14 +317,18 @@ func runSync(cmd *cobra.Command, args []string) error {
315317

316318
_, err := edit.Listings().Update(client.GetPackageName(), edit.ID(), localeName, listing).Context(ctx).Do()
317319
if err != nil {
318-
output.PrintWarning("Failed to update locale '%s': %v", localeName, err)
320+
failures = append(failures, fmt.Sprintf("%s: %v", localeName, err))
319321
continue
320322
}
321323

322324
output.PrintInfo("Updated: %s", localeName)
323325
updated++
324326
}
325327

328+
if len(failures) > 0 {
329+
return fmt.Errorf("listing sync aborted; no changes committed. Failures: %s", strings.Join(failures, "; "))
330+
}
331+
326332
if !cli.IsDryRun() && updated > 0 {
327333
if err := edit.Commit(); err != nil {
328334
return err

‎cmd/playconsole-cli/commands/root.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Design Philosophy:
4141
• JSON-first output for automation
4242
• Explicit flags over cryptic shortcuts
4343
• No interactive prompts
44-
• Clean exit codes (0=success, 1=error, 2=validation)`,
44+
• Clean non-zero exits on failure`,
4545
SilenceUsage: true,
4646
SilenceErrors: true,
4747
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL