Replace version and binlocation strings in nfpm config

This commit is contained in:
kolaente 2020-10-18 12:30:38 +02:00
parent 20c33abd15
commit 0508d9880b
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 24 additions and 3 deletions

1
.gitignore vendored
View File

@ -22,3 +22,4 @@ files/
!pkg/files/
vikunja-dump*
vendor/
os-packages/

View File

@ -668,7 +668,7 @@ func (Release) Reprepro() {
runAndStreamOutput("reprepro_expect", "debian", "includedeb", "strech", RootPath+"/"+Executable+"-"+Version+"_amd64.deb")
}
func (Release) Packages() {
func (Release) Packages() error {
mg.Deps(initVars)
if err := exec.Command("nfpm").Run(); err != nil && strings.Contains(err.Error(), "executable file not found") {
fmt.Println("Please manually install nfpm by running")
@ -676,8 +676,28 @@ func (Release) Packages() {
os.Exit(1)
}
runAndStreamOutput("nfpm", "pkg", "--packager", "deb", "--target", "release/deb")
runAndStreamOutput("nfpm", "pkg", "--packager", "rpm", "--target", "release/rpm")
// Because nfpm does not support templating, we replace the values in the config file and restore it after running
nfpmConfigPath := RootPath + "/nfpm.yaml"
nfpmconfig, err := ioutil.ReadFile(nfpmConfigPath)
if err != nil {
return err
}
fixedConfig := strings.ReplaceAll(string(nfpmconfig), "<version>", VersionNumber)
fixedConfig = strings.ReplaceAll(fixedConfig, "<binlocation>", BinLocation)
if err := ioutil.WriteFile(nfpmConfigPath, []byte(fixedConfig), 0); err != nil {
return err
}
releasePath := RootPath + "/os-packages/"
if err := os.MkdirAll(releasePath, 0755); err != nil {
return err
}
runAndStreamOutput("nfpm", "pkg", "--packager", "deb", "--target", releasePath)
runAndStreamOutput("nfpm", "pkg", "--packager", "rpm", "--target", releasePath)
return ioutil.WriteFile(nfpmConfigPath, nfpmconfig, 0)
}
type Dev mg.Namespace