Add release:os-package command
This commit is contained in:
parent
c1bd463c46
commit
46fd8b9daf
61
magefile.go
61
magefile.go
|
@ -198,7 +198,7 @@ func checkAndInstallGoTool(tool, importPath string) {
|
|||
}
|
||||
|
||||
// Calculates a hash of a file
|
||||
func calculateHashOfFile(path string) (hash string, err error) {
|
||||
func calculateSha256FileHash(path string) (hash string, err error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
@ -213,6 +213,28 @@ func calculateHashOfFile(path string) (hash string, err error) {
|
|||
return fmt.Sprintf("%x", h.Sum(nil)), nil
|
||||
}
|
||||
|
||||
// Copy the src file to dst. Any existing file will be overwritten and will not
|
||||
// copy file attributes.
|
||||
func copyFile(src, dst string) error {
|
||||
in, err := os.Open(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer in.Close()
|
||||
|
||||
out, err := os.Create(dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
_, err = io.Copy(out, in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return out.Close()
|
||||
}
|
||||
|
||||
// Formats the code using go fmt
|
||||
func Fmt() {
|
||||
args := append([]string{"-s", "-w"}, GoFiles...)
|
||||
|
@ -282,7 +304,7 @@ func (Check) GotSwag() {
|
|||
// swag is not capable of just outputting the generated docs to stdout, therefore we need to do it this way.
|
||||
// Another drawback of this is obviously it will only work once - we're not resetting the newly generated
|
||||
// docs after the check. This behaviour is good enough for ci though.
|
||||
oldHash, err := calculateHashOfFile(RootPath + "/pkg/swagger/swagger.json")
|
||||
oldHash, err := calculateSha256FileHash(RootPath + "/pkg/swagger/swagger.json")
|
||||
if err != nil {
|
||||
fmt.Printf("Error getting old hash of the swagger docs: %s", err)
|
||||
os.Exit(1)
|
||||
|
@ -290,7 +312,7 @@ func (Check) GotSwag() {
|
|||
|
||||
DoTheSwag()
|
||||
|
||||
newHash, err := calculateHashOfFile(RootPath + "/pkg/swagger/swagger.json")
|
||||
newHash, err := calculateSha256FileHash(RootPath + "/pkg/swagger/swagger.json")
|
||||
if err != nil {
|
||||
fmt.Printf("Error getting new hash of the swagger docs: %s", err)
|
||||
os.Exit(1)
|
||||
|
@ -466,19 +488,46 @@ func (Release) Compress(ctx context.Context) error {
|
|||
|
||||
// Copies all built binaries to dist/release/ in preparation for creating the os packages
|
||||
func (Release) Copy() {
|
||||
// $(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
|
||||
filepath.Walk(RootPath+"/"+DIST+"/binaries/", func(path string, info os.FileInfo, err error) error {
|
||||
// Only executable files
|
||||
if !strings.Contains(info.Name(), Executable) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return os.Link(path, RootPath+"/"+DIST+"/release/"+info.Name())
|
||||
return copyFile(path, RootPath+"/"+DIST+"/release/"+info.Name())
|
||||
})
|
||||
}
|
||||
|
||||
func (Release) OsPackage() {
|
||||
// Creates a folder for each
|
||||
func (Release) OsPackage() error {
|
||||
|
||||
// $(foreach file,$(filter-out %.sha256,$(wildcard $(DIST)/release/$(EXECUTABLE)-*)),
|
||||
// mkdir $(file)-full;mv $(file) $(file)-full/; mv $(file).sha256 $(file)-full/; cp config.yml.sample $(file)-full/config.yml; cp LICENSE $(file)-full/; )
|
||||
|
||||
p := RootPath + "/" + DIST + "/release/"
|
||||
|
||||
return filepath.Walk(p, func(path string, info os.FileInfo, err error) error {
|
||||
if strings.Contains(info.Name(), ".sha256") {
|
||||
return nil
|
||||
}
|
||||
|
||||
folder := p + info.Name() + "-full/"
|
||||
|
||||
if err := os.Mkdir(folder, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.Rename(p+info.Name()+".sha256", folder+info.Name()+".sha256"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := copyFile(RootPath+"/config.yml.sample", folder+"config.yml.sample"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := copyFile(RootPath+"/LICENSE", folder+"LICENSE"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (Release) Zip() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user