diff --git a/.goreleaser.yaml b/.goreleaser.yaml index f6a9ea5ef..9168cc63d 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -24,10 +24,10 @@ builds: - arm64 ldflags: > -s -w - -X github.com/algorand/indexer/version.Hash={{.FullCommit}} - -X github.com/algorand/indexer/version.ShortHash={{.ShortCommit}} - -X github.com/algorand/indexer/version.CompileTime={{.Timestamp}} - -X github.com/algorand/indexer/version.ReleaseVersion={{.Version}} + -X github.com/algorand/indexer/v3/version.Hash={{.FullCommit}} + -X github.com/algorand/indexer/v3/version.ShortHash={{.ShortCommit}} + -X github.com/algorand/indexer/v3/version.CompileTime={{.Timestamp}} + -X github.com/algorand/indexer/v3/version.ReleaseVersion={{.Version}} dockers: - use: buildx diff --git a/.version b/.version deleted file mode 100644 index 07d875c2d..000000000 --- a/.version +++ /dev/null @@ -1 +0,0 @@ -2.15.2 diff --git a/Makefile b/Makefile index 232faa10f..032aec190 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,6 @@ SRCPATH := $(shell pwd) -VERSION := $(shell $(SRCPATH)/mule/scripts/compute_build_number.sh) OS_TYPE ?= $(shell $(SRCPATH)/mule/scripts/ostype.sh) ARCH ?= $(shell $(SRCPATH)/mule/scripts/archtype.sh) -PKG_DIR = $(SRCPATH)/tmp/node_pkgs/$(OS_TYPE)/$(ARCH)/$(VERSION) ifeq ($(OS_TYPE), darwin) ifeq ($(ARCH), arm64) export CPATH=/opt/homebrew/include @@ -12,9 +10,9 @@ endif export GOPATH := $(shell go env GOPATH) GOPATH1 := $(firstword $(subst :, ,$(GOPATH))) -GOLDFLAGS += -X github.com/algorand/indexer/version.Hash=$(shell git log -n 1 --pretty="%H") -GOLDFLAGS += -X github.com/algorand/indexer/version.CompileTime=$(shell date -u +%Y-%m-%dT%H:%M:%S%z) -GOLDFLAGS += -X github.com/algorand/indexer/version.ReleaseVersion=$(shell cat .version) +GOLDFLAGS += -X github.com/algorand/indexer/v3/version.Hash=$(shell git log -n 1 --pretty="%H") +GOLDFLAGS += -X github.com/algorand/indexer/v3/version.CompileTime=$(shell date -u +%Y-%m-%dT%H:%M:%S%z) +GOLDFLAGS += -X "github.com/algorand/indexer/v3/version.ReleaseVersion=Dev Build" COVERPKG := $(shell go list ./... | grep -v '/cmd/' | egrep -v '(testing|test|mocks)$$' | paste -s -d, - ) @@ -39,17 +37,6 @@ idb/mocks/IndexerDb.go: idb/idb.go check: go build ./... -package: - rm -rf $(PKG_DIR) - mkdir -p $(PKG_DIR) - misc/release.py --host-only --outdir $(PKG_DIR) - -# used in travis test builds; doesn't verify that tag and .version match -fakepackage: - rm -rf $(PKG_DIR) - mkdir -p $(PKG_DIR) - misc/release.py --host-only --outdir $(PKG_DIR) --fake-release - test: idb/mocks/IndexerDb.go cmd/algorand-indexer/algorand-indexer go test -coverpkg=$(COVERPKG) ./... -coverprofile=coverage.txt -covermode=atomic ${TEST_FLAG} diff --git a/misc/release.py b/misc/release.py deleted file mode 100755 index 3ed55f684..000000000 --- a/misc/release.py +++ /dev/null @@ -1,339 +0,0 @@ -#!/usr/bin/env python3 -# -# usage: -# python3 -m venv ve3 -# ve3/bin/pip install markdown2 -# ve3/bin/python misc/release.py - -import argparse -import base64 -import io -import logging -import os -import re -import shlex -import subprocess -import tarfile -import time - -try: - import grp - - def groupname(gid): - return grp.getgrgid(gid)[0] - -except: - - def groupname(gid): - return str(gid) - - -import markdown2 - -logger = logging.getLogger(__name__) - -# GOOS GOARCH DEB_HOST_ARCH -osArchArch = [ - ("linux", "amd64", "amd64"), - ("linux", "arm", "armhf"), - ("linux", "arm64", "arm64"), - ("darwin", "amd64", None), - ("darwin", "arm64", None) -] - -channel = "indexer" - -indexer_filespec = [ - # [files], source path, deb path, tar path - [ - ["algorand-indexer.service", "algorand-indexer@.service"], - "misc/systemd", - "lib/systemd/system", - "", - ], - [ - ["algorand-indexer"], - "cmd/algorand-indexer", - "usr/bin", - "", - ], - [ - ["LICENSE"], - "", - None, - "", - ], -] - - -debian_copyright_top = """Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ -Upstream-Name: Algorand Indexer -Upstream-Contact: Algorand developers -Source: https://github.com/algorand/indexer - -Files: * -Copyright: Algorand developers -License: MIT -""" - - -def debian_copyright(outpath): - with open(outpath, "wt") as fout: - fout.write(debian_copyright_top) - with open("LICENSE") as fin: - for line in fin: - line = line.strip() - if not line: - line = " .\n" - else: - line = " " + line + "\n" - fout.write(line) - - -def arch_ver(outpath, inpath, debarch, version): - with open(outpath, "wt") as fout: - with open(inpath) as fin: - for line in fin: - line = line.replace("@ARCH@", debarch) - line = line.replace("@VER@", version) - line = line.replace("@CHANNEL@", channel) - fout.write(line) - - -def link(sourcepath, destpath): - if os.path.exists(destpath): - if os.path.getmtime(destpath) >= os.path.getmtime(sourcepath): - return # nothing to do - os.remove(destpath) - os.link(sourcepath, destpath) - - -_tagpat = re.compile(r"tag:\s+([^,\n]+)") - - -def compile_version_opts(release_version=None, allow_mismatch=False): - result = subprocess.run( - ["git", "log", "-n", "1", "--pretty=%H %D"], stdout=subprocess.PIPE - ) - result.check_returncode() - so = result.stdout.decode() - githash, desc = so.split(None, 1) - tags = [] - tag = None - for m in _tagpat.finditer(desc): - tag = m.group(1) - tags.append(tag) - if tag == release_version: - break - if tag != release_version: - if not allow_mismatch: - raise Exception( - ".version is {!r} but tags {!r}".format(release_version, tags) - ) - else: - logger.warning(".version is %r but tags %r", release_version, tags) - now = time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime()) + "+0000" - result = subprocess.run(["git", "status", "--porcelain"], stdout=subprocess.PIPE) - result.check_returncode() - if len(result.stdout) > 2: - dirty = "true" - else: - dirty = "" - # Note: keep these in sync with Makefile - ldflags = "-ldflags=-X github.com/algorand/indexer/version.Hash={}".format(githash) - ldflags += " -X github.com/algorand/indexer/version.Dirty={}".format(dirty) - ldflags += " -X github.com/algorand/indexer/version.CompileTime={}".format(now) - ldflags += " -X github.com/algorand/indexer/version.GitDecorateBase64={}".format( - base64.b64encode(desc.encode()).decode() - ) - if release_version: - ldflags += " -X github.com/algorand/indexer/version.ReleaseVersion={}".format( - release_version - ) - logger.debug( - "Hash=%r Dirty=%r CompileTime=%r decorate=%r ReleaseVersion=%r", - githash, - dirty, - now, - desc, - release_version, - ) - logger.debug("%s", ldflags) - return ldflags - - -def compile(path="cmd/algorand-indexer", goos=None, goarch=None, ldflags=None): - env = dict(os.environ) - if goos is not None: - env["GOOS"] = goos - if goarch is not None: - env["GOARCH"] = goarch - cmd = ["go", "build"] - if ldflags is not None: - cmd.append(ldflags) - subprocess.run(["go", "generate", "./..."], env=env).check_returncode() - subprocess.run(cmd, cwd=path, env=env).check_returncode() - - -def build_deb(debarch, version, filespec, outdir): - os.makedirs(".deb_tmp/DEBIAN", exist_ok=True) - debian_copyright(".deb_tmp/DEBIAN/copyright") - arch_ver(".deb_tmp/DEBIAN/control", "misc/debian/control", debarch, version) - os.makedirs(".deb_tmp/etc/apt/apt.conf.d", exist_ok=True) - arch_ver( - ".deb_tmp/etc/apt/apt.conf.d/52algorand-indexer-upgrades", - "misc/debian/52algorand-indexer-upgrades", - debarch, - version, - ) - for files, source_path, deb_path, _ in filespec: - if deb_path is None: - continue - for fname in files: - if deb_path: - os.makedirs(os.path.join(".deb_tmp", deb_path), exist_ok=True) - link( - os.path.join(source_path, fname), - os.path.join(".deb_tmp", deb_path, fname), - ) - debname = "algorand-indexer_{}_{}.deb".format(version, debarch) - debpath = os.path.join(outdir, debname) - subprocess.run(["dpkg-deb", "--build", ".deb_tmp", debpath]) - return debpath - - -def extract_usage(): - usage = False - usageBuffer = "" - with open("README.md") as infile: - for line in infile: - if "USAGE_START_MARKER" in line: - usage = True - continue - elif "USAGE_END_MARKER" in line: - usage = False - continue - elif usage: - usageBuffer += line - return usageBuffer - - -_usage_html = None - - -def usage_html(): - global _usage_html - if _usage_html is not None: - return _usage_html - md = extract_usage() - _usage_html = markdown2.markdown(md, extras=["tables", "fenced-code-blocks"]) - return _usage_html - - -def build_tar(name, goos, goarch, version, filespec, outdir): - rootdir = "{}_{}_{}_{}".format(name, goos, goarch, version) - tarname = os.path.join(outdir, rootdir) + ".tar.bz2" - tf = tarfile.open(tarname, "w:bz2") - for files, source_path, _, tar_path in filespec: - if tar_path is None: - continue - for fname in files: - tf.add( - os.path.join(source_path, fname), os.path.join(rootdir, tar_path, fname) - ) - ti = tarfile.TarInfo(name=os.path.join(rootdir, "usage.html")) - ti.mtime = time.time() - ti.mode = 0o444 - ti.type = tarfile.REGTYPE - ti.uid = os.getuid() - ti.uname = os.getenv("USER") or "" - ti.gid = os.getgid() - ti.gname = groupname(os.getgid()) - uhtml = usage_html().encode("utf-8") - ti.size = len(uhtml) - tf.addfile(ti, io.BytesIO(uhtml)) - tf.close() - return tarname - - -def hostOsArch(): - result = subprocess.run(["go", "env"], stdout=subprocess.PIPE) - result.check_returncode() - goenv = {} - for line in result.stdout.decode().splitlines(): - line = line.strip() - k, v = line.split("=", 1) - goenv[k] = shlex.split(v)[0] - return goenv["GOHOSTOS"], goenv["GOHOSTARCH"] - - -def main(): - start = time.time() - ap = argparse.ArgumentParser() - ap.add_argument( - "-o", - "--outdir", - help="The output directory for the build assets", - type=str, - default=".", - ) - ap.add_argument( - "--no-deb", - action="store_true", - default=False, - help="disable debian package building", - ) - ap.add_argument( - "--host-only", - action="store_true", - default=False, - help="only build for host OS and CPU", - ) - ap.add_argument( - "--build-only", - action="store_true", - default=False, - help="don't make tar or deb release", - ) - ap.add_argument( - "--fake-release", - action="store_true", - default=False, - help="relax some checks during release script development", - ) - ap.add_argument("--verbose", action="store_true", default=False) - args = ap.parse_args() - - if args.verbose: - logging.basicConfig(level=logging.DEBUG) - else: - logging.basicConfig(level=logging.INFO) - outdir = args.outdir - - if args.host_only: - hostos, hostarch = hostOsArch() - logger.info("will only run %s %s", hostos, hostarch) - with open(".version") as fin: - version = fin.read().strip() - ldflags = compile_version_opts(version, allow_mismatch=args.fake_release) - for goos, goarch, debarch in osArchArch: - if args.host_only and (goos != hostos or goarch != hostarch): - logger.debug("skip %s %s", goos, goarch) - continue - logger.info("GOOS=%s GOARCH=%s DEB_HOST_ARCH=%s", goos, goarch, debarch) - compile("cmd/algorand-indexer", goos, goarch, ldflags) - if args.build_only: - logger.debug("skip packaging") - continue - indexer_tarname = build_tar("algorand-indexer", goos, goarch, version, indexer_filespec, outdir) - logger.info("\t%s", indexer_tarname) - if (not args.no_deb) and (debarch is not None): - debname = build_deb(debarch, version, indexer_filespec, outdir) - logger.info("\t%s", debname) - dt = time.time() - start - logger.info("done %0.1fs", dt) - return - - -if __name__ == "__main__": - main() diff --git a/mule/scripts/compute_build_number.sh b/mule/scripts/compute_build_number.sh deleted file mode 100755 index bc945ae53..000000000 --- a/mule/scripts/compute_build_number.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -cat .version - diff --git a/version/strings.go b/version/strings.go index 20578da0d..725e8af3e 100644 --- a/version/strings.go +++ b/version/strings.go @@ -14,7 +14,7 @@ var ( // CompileTime YYYY-mm-ddTHH:MM:SS+ZZZZ CompileTime string - // ReleaseVersion What was in /.version when this was compiled. + // ReleaseVersion is set using -ldflags during build. ReleaseVersion string )