-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redo how the distribution artifact is created
- Add version information to the stitching tool
- Loading branch information
Showing
10 changed files
with
222 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) 2022 David Vogel | ||
// | ||
// This software is released under the MIT License. | ||
// https://opensource.org/licenses/MIT | ||
|
||
package main | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/coreos/go-semver/semver" | ||
) | ||
|
||
// versionString contains the semantic version of the software as a string. | ||
// | ||
// This variable is only used to transfer the correct version information into the build. | ||
// Don't use this variable in the software, use `version` instead. | ||
// | ||
// When building the software, the default `v0.0.0-development` is used. | ||
// To compile the program with the correct version information, compile the following way: | ||
// | ||
// `go build -ldflags="-X 'main.versionString=x.y.z'"`, where `x.y.z` is the correct and valid version from the git tag. | ||
// This variable may or may not contain the prefix v. | ||
var versionString = "0.0.0-development" | ||
|
||
// version of the program. | ||
// | ||
// When converted into a string, this will not contain the v prefix. | ||
var version = semver.Must(semver.NewVersion(strings.TrimPrefix(versionString, "v"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright (c) 2022 David Vogel | ||
// | ||
// This software is released under the MIT License. | ||
// https://opensource.org/licenses/MIT | ||
|
||
package main | ||
|
||
import ( | ||
"archive/zip" | ||
"io" | ||
"io/fs" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
|
||
"golang.org/x/exp/slices" | ||
) | ||
|
||
// addPathToZip adds the given file or directory at srcPath to the zipWriter. | ||
// | ||
// The ignorePaths list is compared to the archive path (archive base path + relative path). | ||
func addPathToZip(zipWriter *zip.Writer, srcPath, archiveBasePath string, ignorePaths []string) error { | ||
return filepath.WalkDir(srcPath, func(path string, d fs.DirEntry, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
|
||
relPath, err := filepath.Rel(srcPath, path) | ||
if err != nil { | ||
return err | ||
} | ||
archivePath := filepath.Join(archiveBasePath, relPath) | ||
|
||
// Skip if path is in ignore list. | ||
// This applies to directories or files. | ||
if slices.Contains(ignorePaths, archivePath) { | ||
log.Printf("Skipped %q", archivePath) | ||
if d.IsDir() { | ||
return fs.SkipDir | ||
} | ||
return nil | ||
} | ||
|
||
// Ignore directories. | ||
if d.IsDir() { | ||
return nil | ||
} | ||
|
||
fileToZip, err := os.Open(path) | ||
if err != nil { | ||
return err | ||
} | ||
defer fileToZip.Close() | ||
|
||
info, err := fileToZip.Stat() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
header, err := zip.FileInfoHeader(info) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
header.Name = archivePath | ||
header.Method = zip.Deflate | ||
|
||
writer, err := zipWriter.CreateHeader(header) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if _, err = io.Copy(writer, fileToZip); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) 2022 David Vogel | ||
// | ||
// This software is released under the MIT License. | ||
// https://opensource.org/licenses/MIT | ||
|
||
package main | ||
|
||
import ( | ||
"archive/zip" | ||
"compress/flate" | ||
"flag" | ||
"io" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"time" | ||
) | ||
|
||
func main() { | ||
clean := flag.Bool("clean", true, "Remove distribution dir before starting") | ||
dist := flag.String("dist", "dist", "Directory to put distribution files in") | ||
flag.Parse() | ||
|
||
start := time.Now() | ||
|
||
if *clean { | ||
os.RemoveAll(*dist) | ||
} | ||
|
||
// Create dist directory tree. | ||
os.MkdirAll(filepath.Join(*dist), 0755) | ||
|
||
toCopy := []string{ | ||
"AREAS.md", "compatibility.xml", "init.lua", "LICENSE", "mod.xml", "README.md", | ||
|
||
filepath.Join("bin", "capture-b", "capture.dll"), filepath.Join("bin", "capture-b", "README.md"), | ||
filepath.Join("bin", "stitch", "stitch.exe"), filepath.Join("bin", "stitch", "README.md"), | ||
filepath.Join("data"), | ||
filepath.Join("files"), | ||
filepath.Join("images"), | ||
} | ||
|
||
toIgnore := []string{ | ||
filepath.Join("noita-mapcap", "images", "coordinates.pdn"), | ||
} | ||
|
||
// Create distribution archive. | ||
newZipFile, err := os.Create(filepath.Join("dist", "dist.zip")) | ||
if err != nil { | ||
log.Panicf("Couldn't create output archive: %v", err) | ||
} | ||
defer newZipFile.Close() | ||
|
||
zipWriter := zip.NewWriter(newZipFile) | ||
defer zipWriter.Close() | ||
|
||
zipWriter.RegisterCompressor(zip.Deflate, func(out io.Writer) (io.WriteCloser, error) { | ||
return flate.NewWriter(out, flate.BestCompression) | ||
}) | ||
|
||
for _, v := range toCopy { | ||
srcPath, archivePath := filepath.Join(".", v), filepath.Join("noita-mapcap", v) | ||
if err := addPathToZip(zipWriter, srcPath, archivePath, toIgnore); err != nil { | ||
log.Panicf("Failed to copy %q into distribution directory: %v", v, err) | ||
} | ||
log.Printf("Copied %q", v) | ||
} | ||
|
||
log.Printf("Distribution script complete in %v", time.Since(start)) | ||
} |