Skip to content

Commit b737b16

Browse files
committed
Generate debian/watch to track git HEAD
if upstream has never tagged any release.
1 parent cb005b7 commit b737b16

File tree

2 files changed

+43
-16
lines changed

2 files changed

+43
-16
lines changed

make.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,8 +869,7 @@ func execMake(args []string, usage func()) {
869869
}
870870

871871
if err := writeTemplates(dir, gopkg, debsrc, debLib, debProg, debversion,
872-
pkgType, debdependencies, u.vendorDirs, u.hasGodeps,
873-
dep14, pristineTar); err != nil {
872+
pkgType, debdependencies, u, dep14, pristineTar); err != nil {
874873
log.Fatalf("Could not create debian/ from templates: %v\n", err)
875874
}
876875

template.go

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import (
1111
)
1212

1313
func writeTemplates(dir, gopkg, debsrc, debLib, debProg, debversion string,
14-
pkgType packageType, dependencies []string, vendorDirs []string,
15-
hasGodeps bool, dep14, pristineTar bool) error {
14+
pkgType packageType, dependencies []string, u *upstream, dep14, pristineTar bool) error {
1615
if err := os.Mkdir(filepath.Join(dir, "debian"), 0755); err != nil {
1716
return err
1817
}
@@ -26,7 +25,7 @@ func writeTemplates(dir, gopkg, debsrc, debLib, debProg, debversion string,
2625
if err := writeDebianControl(dir, gopkg, debsrc, debLib, debProg, pkgType, dependencies); err != nil {
2726
return err
2827
}
29-
if err := writeDebianCopyright(dir, gopkg, vendorDirs, hasGodeps); err != nil {
28+
if err := writeDebianCopyright(dir, gopkg, u.vendorDirs, u.hasGodeps); err != nil {
3029
return err
3130
}
3231
if err := writeDebianRules(dir, pkgType); err != nil {
@@ -38,7 +37,7 @@ func writeTemplates(dir, gopkg, debsrc, debLib, debProg, debversion string,
3837
if err := writeDebianGbpConf(dir, dep14, pristineTar); err != nil {
3938
return err
4039
}
41-
if err := writeDebianWatch(dir, gopkg, debsrc); err != nil {
40+
if err := writeDebianWatch(dir, gopkg, debsrc, u.hasRelease); err != nil {
4241
return err
4342
}
4443
if err := writeDebianPackageInstall(dir, debLib, debProg, pkgType); err != nil {
@@ -296,19 +295,48 @@ func writeDebianGbpConf(dir string, dep14, pristineTar bool) error {
296295
return nil
297296
}
298297

299-
func writeDebianWatch(dir, gopkg, debsrc string) error {
300-
if strings.HasPrefix(gopkg, "github.com/") {
301-
f, err := os.Create(filepath.Join(dir, "debian", "watch"))
302-
if err != nil {
303-
return err
304-
}
305-
defer f.Close()
298+
func writeDebianWatch(dir, gopkg, debsrc string, hasRelease bool) error {
299+
// TODO: Support other hosters too
300+
host := "github.com"
301+
302+
owner, repo, err := findGitHubRepo(gopkg)
303+
if err != nil {
304+
log.Printf("debian/watch: Unable to resolve %s to github.com, skipping\n", gopkg)
305+
return nil
306+
}
307+
if !strings.HasPrefix(gopkg, "github.com/") {
308+
log.Printf("debian/watch: %s resolves to %s/%s/%s\n", gopkg, host, owner, repo)
309+
}
306310

311+
f, err := os.Create(filepath.Join(dir, "debian", "watch"))
312+
if err != nil {
313+
return err
314+
}
315+
defer f.Close()
316+
317+
if hasRelease {
318+
log.Printf("Setting debian/watch to track release tarball")
307319
fmt.Fprintf(f, "version=4\n")
308-
fmt.Fprintf(f, `opts=filenamemangle=s/.+\/v?(\d\S*)\.tar\.gz/%s-\$1\.tar\.gz/,\`+"\n", debsrc)
309-
fmt.Fprintf(f, `uversionmangle=s/(\d)[_\.\-\+]?(RC|rc|pre|dev|beta|alpha)[.]?(\d*)$/\$1~\$2\$3/ \`+"\n")
310-
fmt.Fprintf(f, ` https://%s/tags .*/v?(\d\S*)\.tar\.gz`+"\n", gopkg)
320+
fmt.Fprintf(f, `opts="filenamemangle=s/.+\/v?(\d\S*)\.tar\.gz/%s-\$1\.tar\.gz/, \`+"\n", debsrc)
321+
fmt.Fprintf(f, ` uversionmangle=s/(\d)[_\.\-\+]?(RC|rc|pre|dev|beta|alpha)[.]?(\d*)$/\$1~\$2\$3/" \`+"\n")
322+
fmt.Fprintf(f, ` https://%s/%s/%s/tags .*/v?(\d\S*)\.tar\.gz debian`+"\n", host, owner, repo)
323+
} else {
324+
log.Printf("Setting debian/watch to track git HEAD")
325+
fmt.Fprintf(f, "version=4\n")
326+
fmt.Fprintf(f, `opts="mode=git, pgpmode=none" \`+"\n")
327+
fmt.Fprintf(f, ` https://%s/%s/%s.git \`+"\n", host, owner, repo)
328+
fmt.Fprintf(f, " HEAD debian\n")
329+
330+
// Anticipate that upstream would eventually switch to tagged releases
331+
fmt.Fprintf(f, "\n")
332+
fmt.Fprintf(f, "# Use the following when upstream starts to tag releases:\n")
333+
fmt.Fprintf(f, "#\n")
334+
fmt.Fprintf(f, "#version=4\n")
335+
fmt.Fprintf(f, `#opts="filenamemangle=s/.+\/v?(\d\S*)\.tar\.gz/%s-\$1\.tar\.gz/, \`+"\n", debsrc)
336+
fmt.Fprintf(f, `# uversionmangle=s/(\d)[_\.\-\+]?(RC|rc|pre|dev|beta|alpha)[.]?(\d*)$/\$1~\$2\$3/" \`+"\n")
337+
fmt.Fprintf(f, `# https://%s/%s/%s/tags .*/v?(\d\S*)\.tar\.gz debian`+"\n", host, owner, repo)
311338
}
339+
312340
return nil
313341
}
314342

0 commit comments

Comments
 (0)