mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 23:47:07 -05:00
Output SHA1 checksum for released packages
This commit is contained in:
parent
ed5be19dbe
commit
639bcad78d
@ -31,6 +31,7 @@ deploy:
|
|||||||
- "$GOPATH/bin/v2ray-linux-32.zip"
|
- "$GOPATH/bin/v2ray-linux-32.zip"
|
||||||
- "$GOPATH/bin/v2ray-linux-arm.zip"
|
- "$GOPATH/bin/v2ray-linux-arm.zip"
|
||||||
- "$GOPATH/bin/v2ray-linux-arm64.zip"
|
- "$GOPATH/bin/v2ray-linux-arm64.zip"
|
||||||
|
- "$GOPATH/bin/metadata.txt"
|
||||||
skip_cleanup: true
|
skip_cleanup: true
|
||||||
on:
|
on:
|
||||||
tags: true
|
tags: true
|
||||||
|
@ -11,9 +11,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
flagTargetOS = flag.String("os", runtime.GOOS, "Target OS of this build.")
|
flagTargetOS = flag.String("os", runtime.GOOS, "Target OS of this build.")
|
||||||
flagTargetArch = flag.String("arch", runtime.GOARCH, "Target CPU arch of this build.")
|
flagTargetArch = flag.String("arch", runtime.GOARCH, "Target CPU arch of this build.")
|
||||||
flagArchive = flag.Bool("zip", false, "Whether to make an archive of files or not.")
|
flagArchive = flag.Bool("zip", false, "Whether to make an archive of files or not.")
|
||||||
|
flagMetadataFile = flag.String("metadata", "metadata.txt", "File to store metadata info of released packages.")
|
||||||
|
|
||||||
binPath string
|
binPath string
|
||||||
)
|
)
|
||||||
@ -45,10 +46,10 @@ func getBinPath() string {
|
|||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
binPath = getBinPath()
|
binPath = getBinPath()
|
||||||
build(*flagTargetOS, *flagTargetArch, *flagArchive, "")
|
build(*flagTargetOS, *flagTargetArch, *flagArchive, "", *flagMetadataFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
func build(targetOS, targetArch string, archive bool, version string) {
|
func build(targetOS, targetArch string, archive bool, version string, metadataFile string) {
|
||||||
v2rayOS := parseOS(targetOS)
|
v2rayOS := parseOS(targetOS)
|
||||||
v2rayArch := parseArch(targetArch)
|
v2rayArch := parseArch(targetArch)
|
||||||
|
|
||||||
@ -91,7 +92,18 @@ func build(targetOS, targetArch string, archive bool, version string) {
|
|||||||
root := filepath.Base(targetDir)
|
root := filepath.Base(targetDir)
|
||||||
err = zipFolder(root, zipFile)
|
err = zipFolder(root, zipFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Unable to create archive (%s): %v\n", zipFile, err)
|
fmt.Printf("Unable to create archive (%s): %v\n", zipFile, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
metadataWriter, err := os.OpenFile(filepath.Join(binPath, metadataFile), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Unable to create metadata file (%s): %v\n", metadataFile, err)
|
||||||
|
}
|
||||||
|
defer metadataWriter.Close()
|
||||||
|
|
||||||
|
err = CalcMetadata(zipFile, metadataWriter)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Failed to calculate metadata for file (%s): %v", zipFile, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,21 +36,21 @@ func TestBuildMacOS(t *testing.T) {
|
|||||||
binPath = filepath.Join(os.Getenv("GOPATH"), "testing")
|
binPath = filepath.Join(os.Getenv("GOPATH"), "testing")
|
||||||
cleanBinPath()
|
cleanBinPath()
|
||||||
|
|
||||||
build("macos", "amd64", true, "test")
|
build("macos", "amd64", true, "test", "metadata.txt")
|
||||||
assert.Bool(allFilesExists(
|
assert.Bool(allFilesExists(
|
||||||
"v2ray-macos.zip",
|
"v2ray-macos.zip",
|
||||||
"v2ray-test-macos",
|
"v2ray-test-macos",
|
||||||
filepath.Join("v2ray-test-macos", "config.json"),
|
filepath.Join("v2ray-test-macos", "config.json"),
|
||||||
filepath.Join("v2ray-test-macos", "v2ray"))).IsTrue()
|
filepath.Join("v2ray-test-macos", "v2ray"))).IsTrue()
|
||||||
|
|
||||||
build("windows", "amd64", true, "test")
|
build("windows", "amd64", true, "test", "metadata.txt")
|
||||||
assert.Bool(allFilesExists(
|
assert.Bool(allFilesExists(
|
||||||
"v2ray-windows-64.zip",
|
"v2ray-windows-64.zip",
|
||||||
"v2ray-test-windows-64",
|
"v2ray-test-windows-64",
|
||||||
filepath.Join("v2ray-test-windows-64", "config.json"),
|
filepath.Join("v2ray-test-windows-64", "config.json"),
|
||||||
filepath.Join("v2ray-test-windows-64", "v2ray.exe"))).IsTrue()
|
filepath.Join("v2ray-test-windows-64", "v2ray.exe"))).IsTrue()
|
||||||
|
|
||||||
build("linux", "amd64", true, "test")
|
build("linux", "amd64", true, "test", "metadata.txt")
|
||||||
assert.Bool(allFilesExists(
|
assert.Bool(allFilesExists(
|
||||||
"v2ray-linux-64.zip",
|
"v2ray-linux-64.zip",
|
||||||
"v2ray-test-linux-64",
|
"v2ray-test-linux-64",
|
||||||
|
31
tools/build/metadata.go
Normal file
31
tools/build/metadata.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/sha1"
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CalcMetadata(file string, writer io.Writer) error {
|
||||||
|
fileReader, err := os.Open(file)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer fileReader.Close()
|
||||||
|
|
||||||
|
hasher := sha1.New()
|
||||||
|
nBytes, err := io.Copy(hasher, fileReader)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
sha1sum := hasher.Sum(nil)
|
||||||
|
filename := filepath.Base(file)
|
||||||
|
fmt.Fprintf(writer, "File: %s\n", filename)
|
||||||
|
fmt.Fprintf(writer, "Size: %d\n", nBytes)
|
||||||
|
fmt.Fprintf(writer, "SHA1: %s\n", hex.EncodeToString(sha1sum))
|
||||||
|
fmt.Fprintln(writer)
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user