-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(release): package the release in the DevPod format
- Loading branch information
1 parent
bd19409
commit 6dba4d8
Showing
7 changed files
with
284 additions
and
98 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 was deleted.
Oops, something went wrong.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,63 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
export GO111MODULE=on | ||
# export GOFLAGS=-mod=vendor | ||
|
||
PROVIDER_ROOT=$(git rev-parse --show-toplevel) | ||
COMMIT_HASH=$(git rev-parse --short HEAD 2>/dev/null) | ||
DATE=$(date "+%Y-%m-%d") | ||
BUILD_PLATFORM=$(uname -a | awk '{print tolower($1);}') | ||
|
||
echo "Current working directory is $(pwd)" | ||
echo "PATH is $PATH" | ||
echo "GOPATH is $GOPATH" | ||
|
||
if [[ "$(pwd)" != "${PROVIDER_ROOT}" ]]; then | ||
echo "you are not in the root of the repo" 1>&2 | ||
echo "please cd to ${PROVIDER_ROOT} before running this script" 1>&2 | ||
exit 1 | ||
fi | ||
|
||
GO_BUILD_CMD="go build" | ||
GO_BUILD_LDFLAGS="-w -s -X ${GIT_REPO}/cmd.Version=${RELEASE_VERSION} -X ${GIT_REPO}/cmd.GitCommit=${GIT_COMMIT}" | ||
|
||
if [[ -z "${PROVIDER_BUILD_PLATFORMS}" ]]; then | ||
PROVIDER_BUILD_PLATFORMS="linux windows darwin" | ||
fi | ||
|
||
if [[ -z "${PROVIDER_BUILD_ARCHS}" ]]; then | ||
PROVIDER_BUILD_ARCHS="amd64 arm64" | ||
fi | ||
|
||
# Create the dist directory | ||
mkdir -p "${PROVIDER_ROOT}/dist" | ||
|
||
for OS in ${PROVIDER_BUILD_PLATFORMS[@]}; do | ||
for ARCH in ${PROVIDER_BUILD_ARCHS[@]}; do | ||
NAME="devpod-provider-hetzner-${OS}-${ARCH}" | ||
if [[ "${OS}" == "windows" ]]; then | ||
NAME="${NAME}.exe" | ||
fi | ||
|
||
# darwin 386 is deprecated and shouldn't be used anymore | ||
if [[ "${ARCH}" == "386" && "${OS}" == "darwin" ]]; then | ||
echo "Building for ${OS}/${ARCH} not supported." | ||
continue | ||
fi | ||
|
||
# arm64 build is only supported for darwin | ||
if [[ "${ARCH}" == "arm64" && "${OS}" == "windows" ]]; then | ||
echo "Building for ${OS}/${ARCH} not supported." | ||
continue | ||
fi | ||
|
||
echo "Building for ${OS}/${ARCH}" | ||
GOARCH=${ARCH} GOOS=${OS} ${GO_BUILD_CMD} -ldflags "${GO_BUILD_LDFLAGS}"\ | ||
-o "${PROVIDER_ROOT}/dist/${NAME}" main.go | ||
shasum -a 256 "${PROVIDER_ROOT}/dist/${NAME}" | cut -d ' ' -f 1 > "${PROVIDER_ROOT}/dist/${NAME}".sha256 | ||
done | ||
done | ||
|
||
# generate provider.yaml | ||
go run "${PROVIDER_ROOT}/hack/provider/main.go" ${RELEASE_VERSION} > "${PROVIDER_ROOT}/dist/provider.yaml" |
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,62 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/sha256" | ||
"encoding/hex" | ||
"fmt" | ||
"io" | ||
"os" | ||
"strings" | ||
) | ||
|
||
var checksumMap = map[string]string{ | ||
"./dist/devpod-provider-hetzner-linux-amd64": "##CHECKSUM_LINUX_AMD64##", | ||
"./dist/devpod-provider-hetzner-linux-arm64": "##CHECKSUM_LINUX_ARM64##", | ||
"./dist/devpod-provider-hetzner-darwin-amd64": "##CHECKSUM_DARWIN_AMD64##", | ||
"./dist/devpod-provider-hetzner-darwin-arm64": "##CHECKSUM_DARWIN_ARM64##", | ||
"./dist/devpod-provider-hetzner-windows-amd64.exe": "##CHECKSUM_WINDOWS_AMD64##", | ||
} | ||
|
||
func main() { | ||
if len(os.Args) != 2 { | ||
fmt.Fprintln(os.Stderr, "Expected version as argument") | ||
os.Exit(1) | ||
return | ||
} | ||
|
||
content, err := os.ReadFile("./hack/provider/provider.yaml") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
replaced := strings.Replace(string(content), "##VERSION##", os.Args[1], -1) | ||
for k, v := range checksumMap { | ||
checksum, err := File(k) | ||
if err != nil { | ||
panic(fmt.Errorf("generate checksum for %s: %v", k, err)) | ||
} | ||
|
||
replaced = strings.Replace(replaced, v, checksum, -1) | ||
} | ||
|
||
fmt.Print(replaced) | ||
} | ||
|
||
// File hashes a given file to a sha256 string | ||
func File(filePath string) (string, error) { | ||
file, err := os.Open(filePath) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer func() { | ||
err = file.Close() | ||
}() | ||
|
||
hash := sha256.New() | ||
_, err = io.Copy(hash, file) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return strings.ToLower(hex.EncodeToString(hash.Sum(nil))), err | ||
} |
Oops, something went wrong.