2016-05-25 07:07:57 -05:00
// Copyright 2016 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
2021-10-08 10:23:25 -05:00
//go:build none
2016-05-25 07:07:57 -05:00
// +build none
/ *
The ci command is called from Continuous Integration scripts .
2017-11-28 03:45:48 -06:00
Usage : go run build / ci . go < command > < command flags / arguments >
2016-05-25 07:07:57 -05:00
Available commands are :
2024-10-29 06:21:17 -05:00
lint -- runs certain pre - selected linters
check_tidy -- verifies that everything is ' go mod tidy ' - ed
check_generate -- verifies that everything is ' go generate ' - ed
check_baddeps -- verifies that certain dependencies are avoided
install [ - arch architecture ] [ - cc compiler ] [ packages ... ] -- builds packages and executables
test [ - coverage ] [ packages ... ] -- runs the tests
2022-09-10 06:25:40 -05:00
archive [ - arch architecture ] [ - type zip | tar ] [ - signer key - envvar ] [ - signify key - envvar ] [ - upload dest ] -- archives build artifacts
importkeys -- imports signing keys from env
debsrc [ - signer key - id ] [ - upload dest ] -- creates a debian source package
nsis -- creates a Windows NSIS installer
purge [ - store blobstore ] [ - days threshold ] -- purges old archives from the blobstore
2016-05-25 07:07:57 -05:00
For all commands , - n prevents execution of external programs ( dry run mode ) .
* /
package main
import (
"bytes"
"encoding/base64"
"flag"
"fmt"
"log"
"os"
"os/exec"
2020-11-11 07:34:43 -06:00
"path"
2016-05-25 07:07:57 -05:00
"path/filepath"
"runtime"
2024-11-03 14:05:44 -06:00
"slices"
2016-05-25 07:07:57 -05:00
"strings"
"time"
2019-11-18 12:29:01 -06:00
"github.com/cespare/cp"
2020-12-09 08:43:36 -06:00
"github.com/ethereum/go-ethereum/crypto/signify"
2016-11-02 11:21:05 -05:00
"github.com/ethereum/go-ethereum/internal/build"
2024-10-20 11:28:39 -05:00
"github.com/ethereum/go-ethereum/internal/version"
2016-05-25 07:07:57 -05:00
)
var (
// Files that end up in the geth*.zip archive.
gethArchiveFiles = [ ] string {
"COPYING" ,
executablePath ( "geth" ) ,
}
// Files that end up in the geth-alltools*.zip archive.
allToolsArchiveFiles = [ ] string {
"COPYING" ,
executablePath ( "abigen" ) ,
executablePath ( "evm" ) ,
executablePath ( "geth" ) ,
executablePath ( "rlpdump" ) ,
2019-03-04 05:02:58 -06:00
executablePath ( "clef" ) ,
2016-05-25 07:07:57 -05:00
}
// A debian package is created for all executables listed here.
debExecutables = [ ] debExecutable {
{
2018-07-30 03:56:40 -05:00
BinaryName : "abigen" ,
2017-04-10 18:25:53 -05:00
Description : "Source code generator to convert Ethereum contract definitions into easy to use, compile-time type-safe Go packages." ,
2016-05-25 07:07:57 -05:00
} ,
{
2018-07-30 03:56:40 -05:00
BinaryName : "evm" ,
2016-05-25 07:07:57 -05:00
Description : "Developer utility version of the EVM (Ethereum Virtual Machine) that is capable of running bytecode snippets within a configurable environment and execution mode." ,
} ,
2016-11-28 04:25:19 -06:00
{
2018-07-30 03:56:40 -05:00
BinaryName : "geth" ,
2017-04-10 18:25:53 -05:00
Description : "Ethereum CLI client." ,
2016-11-28 04:25:19 -06:00
} ,
2017-04-10 18:25:53 -05:00
{
2018-07-30 03:56:40 -05:00
BinaryName : "rlpdump" ,
2017-04-10 18:25:53 -05:00
Description : "Developer utility tool that prints RLP structures." ,
} ,
2019-03-04 05:02:58 -06:00
{
BinaryName : "clef" ,
Description : "Ethereum account management tool." ,
} ,
2018-07-30 03:56:40 -05:00
}
// A debian package is created for all executables listed here.
debEthereum = debPackage {
Name : "ethereum" ,
2024-10-20 11:28:39 -05:00
Version : version . Semantic ,
2018-07-30 03:56:40 -05:00
Executables : debExecutables ,
}
// Debian meta packages to build and push to Ubuntu PPA
debPackages = [ ] debPackage {
debEthereum ,
}
2024-04-25 06:07:39 -05:00
// Distros for which packages are created
debDistros = [ ] string {
2024-10-12 04:25:58 -05:00
"xenial" , // 16.04, EOL: 04/2026
"bionic" , // 18.04, EOL: 04/2028
"focal" , // 20.04, EOL: 04/2030
"jammy" , // 22.04, EOL: 04/2032
"noble" , // 24.04, EOL: 04/2034
2024-10-18 06:49:27 -05:00
"oracular" , // 24.10, EOL: 07/2025
travis, build, internal: use own Go bundle for PPA builds (#20240)
* build: bump PPAs to Go 1.13 (via longsleep), keep Trusty on 1.11
* travis, build, vendor: use own Go bundle for PPA builds
* travis, build, internal, vendor: smarter Go bundler, own untar
* build: updated ci-notes with new Go bundling, only make, don't test
2019-11-05 07:32:42 -06:00
}
2020-11-11 07:34:43 -06:00
2023-08-26 08:42:27 -05:00
// This is where the tests should be unpacked.
executionSpecTestsDir = "tests/spec-tests"
2016-05-25 07:07:57 -05:00
)
var GOBIN , _ = filepath . Abs ( filepath . Join ( "build" , "bin" ) )
func executablePath ( name string ) string {
if runtime . GOOS == "windows" {
name += ".exe"
}
return filepath . Join ( GOBIN , name )
}
func main ( ) {
log . SetFlags ( log . Lshortfile )
2024-10-20 06:54:06 -05:00
if ! build . FileExist ( filepath . Join ( "build" , "ci.go" ) ) {
2016-05-25 07:07:57 -05:00
log . Fatal ( "this script must be run from the root of the repository" )
}
if len ( os . Args ) < 2 {
log . Fatal ( "need subcommand as first argument" )
}
switch os . Args [ 1 ] {
case "install" :
doInstall ( os . Args [ 2 : ] )
case "test" :
doTest ( os . Args [ 2 : ] )
2017-11-09 04:46:03 -06:00
case "lint" :
doLint ( os . Args [ 2 : ] )
2024-10-29 06:21:17 -05:00
case "check_tidy" :
doCheckTidy ( )
case "check_generate" :
doCheckGenerate ( )
case "check_baddeps" :
doCheckBadDeps ( )
2016-05-25 07:07:57 -05:00
case "archive" :
doArchive ( os . Args [ 2 : ] )
2024-09-30 07:39:53 -05:00
case "dockerx" :
doDockerBuildx ( os . Args [ 2 : ] )
2016-05-25 07:07:57 -05:00
case "debsrc" :
doDebianSource ( os . Args [ 2 : ] )
2016-11-08 15:55:39 -06:00
case "nsis" :
doWindowsInstaller ( os . Args [ 2 : ] )
2017-04-06 05:53:33 -05:00
case "purge" :
doPurge ( os . Args [ 2 : ] )
2023-10-13 07:14:48 -05:00
case "sanitycheck" :
doSanityCheck ( )
2016-05-25 07:07:57 -05:00
default :
log . Fatal ( "unknown command " , os . Args [ 1 ] )
}
}
// Compiling
func doInstall ( cmdline [ ] string ) {
2016-11-02 12:36:48 -05:00
var (
2022-08-10 03:30:59 -05:00
dlgo = flag . Bool ( "dlgo" , false , "Download Go and build with it" )
arch = flag . String ( "arch" , "" , "Architecture to cross build for" )
cc = flag . String ( "cc" , "" , "C compiler to cross build with" )
staticlink = flag . Bool ( "static" , false , "Create statically-linked executable" )
2016-11-02 12:36:48 -05:00
)
2016-05-25 07:07:57 -05:00
flag . CommandLine . Parse ( cmdline )
2023-08-11 17:21:46 -05:00
env := build . Env ( )
2016-05-25 07:07:57 -05:00
2021-05-04 06:01:20 -05:00
// Configure the toolchain.
tc := build . GoToolchain { GOARCH : * arch , CC : * cc }
if * dlgo {
csdb := build . MustLoadChecksums ( "build/checksums.txt" )
2023-10-13 07:14:48 -05:00
tc . Root = build . DownloadGo ( csdb )
2016-05-25 07:07:57 -05:00
}
2023-08-11 17:21:46 -05:00
// Disable CLI markdown doc generation in release builds.
buildTags := [ ] string { "urfave_cli_no_docs" }
// Enable linking the CKZG library since we can make it work with additional flags.
if env . UbuntuVersion != "trusty" {
buildTags = append ( buildTags , "ckzg" )
}
2022-08-10 03:30:59 -05:00
2021-05-04 06:01:20 -05:00
// Configure the build.
2022-08-10 03:30:59 -05:00
gobuild := tc . Go ( "build" , buildFlags ( env , * staticlink , buildTags ) ... )
2020-11-11 07:34:43 -06:00
2020-11-11 15:08:22 -06:00
// We use -trimpath to avoid leaking local paths into the built executables.
gobuild . Args = append ( gobuild . Args , "-trimpath" )
2020-11-11 07:34:43 -06:00
// Show packages during build.
gobuild . Args = append ( gobuild . Args , "-v" )
// Now we choose what we're even building.
// Default: collect all 'main' packages in cmd/ and build those.
packages := flag . Args ( )
if len ( packages ) == 0 {
packages = build . FindMainPackages ( "./cmd" )
}
// Do the build!
for _ , pkg := range packages {
2024-11-03 14:05:44 -06:00
args := slices . Clone ( gobuild . Args )
2020-11-11 07:34:43 -06:00
args = append ( args , "-o" , executablePath ( path . Base ( pkg ) ) )
args = append ( args , pkg )
build . MustRun ( & exec . Cmd { Path : gobuild . Path , Args : args , Env : gobuild . Env } )
2016-11-02 12:36:48 -05:00
}
2016-05-25 07:07:57 -05:00
}
2020-11-11 07:34:43 -06:00
// buildFlags returns the go tool flags for building.
2022-08-10 03:30:59 -05:00
func buildFlags ( env build . Environment , staticLinking bool , buildTags [ ] string ) ( flags [ ] string ) {
2017-03-29 05:20:57 -05:00
var ld [ ] string
2024-08-23 02:48:24 -05:00
// See https://github.com/golang/go/issues/33772#issuecomment-528176001
// We need to set --buildid to the linker here, and also pass --build-id to the
// cgo-linker further down.
ld = append ( ld , "--buildid=none" )
2016-09-30 15:03:08 -05:00
if env . Commit != "" {
2022-09-23 07:08:25 -05:00
ld = append ( ld , "-X" , "github.com/ethereum/go-ethereum/internal/version.gitCommit=" + env . Commit )
ld = append ( ld , "-X" , "github.com/ethereum/go-ethereum/internal/version.gitDate=" + env . Date )
2017-03-29 05:20:57 -05:00
}
2020-11-11 07:34:43 -06:00
// Strip DWARF on darwin. This used to be required for certain things,
// and there is no downside to this, so we just keep doing it.
2017-03-29 05:20:57 -05:00
if runtime . GOOS == "darwin" {
ld = append ( ld , "-s" )
}
2021-10-11 08:48:41 -05:00
if runtime . GOOS == "linux" {
2022-08-10 03:30:59 -05:00
// Enforce the stacksize to 8M, which is the case on most platforms apart from
// alpine Linux.
2024-08-20 08:33:28 -05:00
// See https://sourceware.org/binutils/docs-2.23.1/ld/Options.html#Options
// regarding the options --build-id=none and --strip-all. It is needed for
// reproducible builds; removing references to temporary files in C-land, and
2024-11-22 02:02:45 -06:00
// making build-id reproducibly absent.
2024-08-20 08:33:28 -05:00
extld := [ ] string { "-Wl,-z,stack-size=0x800000,--build-id=none,--strip-all" }
2022-08-10 03:30:59 -05:00
if staticLinking {
extld = append ( extld , "-static" )
// Under static linking, use of certain glibc features must be
// disabled to avoid shared library dependencies.
buildTags = append ( buildTags , "osusergo" , "netgo" )
}
ld = append ( ld , "-extldflags" , "'" + strings . Join ( extld , " " ) + "'" )
2021-10-11 08:48:41 -05:00
}
2017-03-29 05:20:57 -05:00
if len ( ld ) > 0 {
flags = append ( flags , "-ldflags" , strings . Join ( ld , " " ) )
2016-05-25 07:07:57 -05:00
}
2022-08-10 03:30:59 -05:00
if len ( buildTags ) > 0 {
flags = append ( flags , "-tags" , strings . Join ( buildTags , "," ) )
}
2016-05-25 07:07:57 -05:00
return flags
}
// Running The Tests
//
// "tests" also includes static analysis tools such as vet.
func doTest ( cmdline [ ] string ) {
2021-05-04 06:01:20 -05:00
var (
dlgo = flag . Bool ( "dlgo" , false , "Download Go and build with it" )
arch = flag . String ( "arch" , "" , "Run tests for given architecture" )
cc = flag . String ( "cc" , "" , "Sets C compiler binary" )
coverage = flag . Bool ( "coverage" , false , "Whether to record code coverage" )
verbose = flag . Bool ( "v" , false , "Whether to log verbosely" )
2021-10-11 12:37:18 -05:00
race = flag . Bool ( "race" , false , "Execute the race detector" )
2023-12-30 10:02:48 -06:00
short = flag . Bool ( "short" , false , "Pass the 'short'-flag to go test" )
2023-08-26 08:42:27 -05:00
cachedir = flag . String ( "cachedir" , "./build/cache" , "directory for caching downloads" )
2021-05-04 06:01:20 -05:00
)
2016-05-25 07:07:57 -05:00
flag . CommandLine . Parse ( cmdline )
2016-10-28 12:05:01 -05:00
2023-08-26 08:42:27 -05:00
// Get test fixtures.
csdb := build . MustLoadChecksums ( "build/checksums.txt" )
downloadSpecTestFixtures ( csdb , * cachedir )
2021-05-04 06:01:20 -05:00
// Configure the toolchain.
tc := build . GoToolchain { GOARCH : * arch , CC : * cc }
if * dlgo {
2023-10-13 07:14:48 -05:00
tc . Root = build . DownloadGo ( csdb )
2016-05-25 07:07:57 -05:00
}
2023-08-11 17:21:46 -05:00
gotest := tc . Go ( "test" )
2023-08-01 02:08:19 -05:00
// CI needs a bit more time for the statetests (default 10m).
2024-09-05 03:50:34 -05:00
gotest . Args = append ( gotest . Args , "-timeout=30m" )
2017-03-23 09:46:03 -05:00
2023-08-11 17:21:46 -05:00
// Enable CKZG backend in CI.
gotest . Args = append ( gotest . Args , "-tags=ckzg" )
2023-10-25 10:57:12 -05:00
// Enable integration-tests
gotest . Args = append ( gotest . Args , "-tags=integrationtests" )
2016-09-26 06:41:18 -05:00
// Test a single package at a time. CI builders are slow
// and some tests run into timeouts under load.
2020-05-05 07:11:00 -05:00
gotest . Args = append ( gotest . Args , "-p" , "1" )
2016-05-25 07:07:57 -05:00
if * coverage {
gotest . Args = append ( gotest . Args , "-covermode=atomic" , "-cover" )
}
2019-11-18 08:48:20 -06:00
if * verbose {
gotest . Args = append ( gotest . Args , "-v" )
}
2021-10-11 12:37:18 -05:00
if * race {
gotest . Args = append ( gotest . Args , "-race" )
}
2023-10-20 06:35:49 -05:00
if * short {
gotest . Args = append ( gotest . Args , "-short" )
}
2017-11-09 04:46:03 -06:00
2021-05-04 06:01:20 -05:00
packages := [ ] string { "./..." }
if len ( flag . CommandLine . Args ( ) ) > 0 {
packages = flag . CommandLine . Args ( )
}
2016-05-25 07:07:57 -05:00
gotest . Args = append ( gotest . Args , packages ... )
build . MustRun ( gotest )
}
2023-08-26 08:42:27 -05:00
// downloadSpecTestFixtures downloads and extracts the execution-spec-tests fixtures.
func downloadSpecTestFixtures ( csdb * build . ChecksumDB , cachedir string ) string {
2023-10-13 07:14:48 -05:00
executionSpecTestsVersion , err := build . Version ( csdb , "spec-tests" )
if err != nil {
log . Fatal ( err )
}
2023-08-26 08:42:27 -05:00
ext := ".tar.gz"
2023-10-16 13:10:05 -05:00
base := "fixtures_develop" // TODO(MariusVanDerWijden) rename once the version becomes part of the filename
2023-08-26 08:42:27 -05:00
url := fmt . Sprintf ( "https://github.com/ethereum/execution-spec-tests/releases/download/v%s/%s%s" , executionSpecTestsVersion , base , ext )
archivePath := filepath . Join ( cachedir , base + ext )
if err := csdb . DownloadFile ( url , archivePath ) ; err != nil {
log . Fatal ( err )
}
if err := build . ExtractArchive ( archivePath , executionSpecTestsDir ) ; err != nil {
log . Fatal ( err )
}
return filepath . Join ( cachedir , base )
}
2024-10-29 06:21:17 -05:00
// doCheckTidy assets that the Go modules files are tidied already.
func doCheckTidy ( ) {
targets := [ ] string { "go.mod" , "go.sum" }
2024-07-01 10:16:15 -05:00
2024-10-29 06:21:17 -05:00
hashes , err := build . HashFiles ( targets )
if err != nil {
log . Fatalf ( "failed to hash go.mod/go.sum: %v" , err )
2024-08-12 13:46:15 -05:00
}
2024-10-29 06:21:17 -05:00
build . MustRun ( new ( build . GoToolchain ) . Go ( "mod" , "tidy" ) )
2024-08-12 13:46:15 -05:00
2024-10-29 06:21:17 -05:00
tidied , err := build . HashFiles ( targets )
2024-08-12 13:46:15 -05:00
if err != nil {
2024-10-29 06:21:17 -05:00
log . Fatalf ( "failed to rehash go.mod/go.sum: %v" , err )
2024-08-12 13:46:15 -05:00
}
2024-10-29 06:21:17 -05:00
if updates := build . DiffHashes ( hashes , tidied ) ; len ( updates ) > 0 {
log . Fatalf ( "files changed on running 'go mod tidy': %v" , updates )
2024-08-12 13:46:15 -05:00
}
2024-10-29 06:21:17 -05:00
fmt . Println ( "No untidy module files detected." )
2024-08-12 13:46:15 -05:00
}
2024-10-29 06:21:17 -05:00
// doCheckGenerate ensures that re-generating generated files does not cause
// any mutations in the source file tree.
func doCheckGenerate ( ) {
2024-07-01 10:16:15 -05:00
var (
cachedir = flag . String ( "cachedir" , "./build/cache" , "directory for caching binaries." )
)
2024-10-29 06:21:17 -05:00
// Compute the origin hashes of all the files
var hashes map [ string ] [ 32 ] byte
2024-07-01 10:16:15 -05:00
2024-10-29 06:21:17 -05:00
var err error
hashes , err = build . HashFolder ( "." , [ ] string { "tests/testdata" , "build/cache" } )
if err != nil {
log . Fatal ( "Error computing hashes" , "err" , err )
2024-07-01 10:16:15 -05:00
}
2024-10-29 06:21:17 -05:00
// Run any go generate steps we might be missing
var (
protocPath = downloadProtoc ( * cachedir )
protocGenGoPath = downloadProtocGenGo ( * cachedir )
)
c := new ( build . GoToolchain ) . Go ( "generate" , "./..." )
2024-07-01 10:16:15 -05:00
pathList := [ ] string { filepath . Join ( protocPath , "bin" ) , protocGenGoPath , os . Getenv ( "PATH" ) }
c . Env = append ( c . Env , "PATH=" + strings . Join ( pathList , string ( os . PathListSeparator ) ) )
build . MustRun ( c )
2024-10-29 06:21:17 -05:00
// Check if generate file hashes have changed
generated , err := build . HashFolder ( "." , [ ] string { "tests/testdata" , "build/cache" } )
2024-07-01 10:16:15 -05:00
if err != nil {
2024-10-29 06:21:17 -05:00
log . Fatalf ( "Error re-computing hashes: %v" , err )
2024-07-01 10:16:15 -05:00
}
2024-10-29 06:21:17 -05:00
updates := build . DiffHashes ( hashes , generated )
for _ , file := range updates {
log . Printf ( "File changed: %s" , file )
2024-07-01 10:16:15 -05:00
}
if len ( updates ) != 0 {
log . Fatal ( "One or more generated files were updated by running 'go generate ./...'" )
}
2024-10-29 06:21:17 -05:00
fmt . Println ( "No stale files detected." )
}
// doCheckBadDeps verifies whether certain unintended dependencies between some
// packages leak into the codebase due to a refactor. This is not an exhaustive
// list, rather something we build up over time at sensitive places.
func doCheckBadDeps ( ) {
baddeps := [ ] [ 2 ] string {
// Rawdb tends to be a dumping ground for db utils, sometimes leaking the db itself
{ "github.com/ethereum/go-ethereum/core/rawdb" , "github.com/ethereum/go-ethereum/ethdb/leveldb" } ,
{ "github.com/ethereum/go-ethereum/core/rawdb" , "github.com/ethereum/go-ethereum/ethdb/pebbledb" } ,
}
tc := new ( build . GoToolchain )
var failed bool
for _ , rule := range baddeps {
out , err := tc . Go ( "list" , "-deps" , rule [ 0 ] ) . CombinedOutput ( )
if err != nil {
log . Fatalf ( "Failed to list '%s' dependencies: %v" , rule [ 0 ] , err )
}
for _ , line := range strings . Split ( string ( out ) , "\n" ) {
if strings . TrimSpace ( line ) == rule [ 1 ] {
log . Printf ( "Found bad dependency '%s' -> '%s'" , rule [ 0 ] , rule [ 1 ] )
failed = true
}
}
}
if failed {
log . Fatalf ( "Bad dependencies detected." )
}
fmt . Println ( "No bad dependencies detected." )
2024-07-01 10:16:15 -05:00
}
2019-11-18 02:49:18 -06:00
// doLint runs golangci-lint on requested packages.
2017-11-09 04:46:03 -06:00
func doLint ( cmdline [ ] string ) {
2019-11-18 02:49:18 -06:00
var (
cachedir = flag . String ( "cachedir" , "./build/cache" , "directory for caching golangci-lint binary." )
)
2017-11-09 04:46:03 -06:00
flag . CommandLine . Parse ( cmdline )
packages := [ ] string { "./..." }
if len ( flag . CommandLine . Args ( ) ) > 0 {
packages = flag . CommandLine . Args ( )
2017-01-13 03:54:17 -06:00
}
2019-11-18 02:49:18 -06:00
linter := downloadLinter ( * cachedir )
lflags := [ ] string { "run" , "--config" , ".golangci.yml" }
2023-12-19 01:55:04 -06:00
build . MustRunCommandWithOutput ( linter , append ( lflags , packages ... ) ... )
2019-11-18 02:49:18 -06:00
fmt . Println ( "You have achieved perfection." )
}
// downloadLinter downloads and unpacks golangci-lint.
func downloadLinter ( cachedir string ) string {
csdb := build . MustLoadChecksums ( "build/checksums.txt" )
2023-10-13 07:14:48 -05:00
version , err := build . Version ( csdb , "golangci" )
if err != nil {
log . Fatal ( err )
}
2022-01-31 06:17:18 -06:00
arch := runtime . GOARCH
2022-03-15 04:24:45 -05:00
ext := ".tar.gz"
2022-03-16 01:27:16 -05:00
if runtime . GOOS == "windows" {
ext = ".zip"
}
if arch == "arm" {
2022-01-31 06:17:18 -06:00
arch += "v" + os . Getenv ( "GOARM" )
}
base := fmt . Sprintf ( "golangci-lint-%s-%s-%s" , version , runtime . GOOS , arch )
2022-03-15 04:24:45 -05:00
url := fmt . Sprintf ( "https://github.com/golangci/golangci-lint/releases/download/v%s/%s%s" , version , base , ext )
archivePath := filepath . Join ( cachedir , base + ext )
2019-11-18 02:49:18 -06:00
if err := csdb . DownloadFile ( url , archivePath ) ; err != nil {
log . Fatal ( err )
}
2020-11-11 07:34:43 -06:00
if err := build . ExtractArchive ( archivePath , cachedir ) ; err != nil {
2019-11-18 02:49:18 -06:00
log . Fatal ( err )
2017-11-10 11:06:45 -06:00
}
2019-11-18 02:49:18 -06:00
return filepath . Join ( cachedir , base , "golangci-lint" )
2017-01-13 03:54:17 -06:00
}
2024-07-01 10:16:15 -05:00
// protocArchiveBaseName returns the name of the protoc archive file for
// the current system, stripped of version and file suffix.
func protocArchiveBaseName ( ) ( string , error ) {
switch runtime . GOOS + "-" + runtime . GOARCH {
case "windows-amd64" :
return "win64" , nil
case "windows-386" :
return "win32" , nil
case "linux-arm64" :
return "linux-aarch_64" , nil
case "linux-386" :
return "linux-x86_32" , nil
case "linux-amd64" :
return "linux-x86_64" , nil
case "darwin-arm64" :
return "osx-aarch_64" , nil
case "darwin-amd64" :
return "osx-x86_64" , nil
default :
return "" , fmt . Errorf ( "no prebuilt release of protoc available for this system (os: %s, arch: %s)" , runtime . GOOS , runtime . GOARCH )
}
}
// downloadProtocGenGo downloads protoc-gen-go, which is used by protoc
// in the generate command. It returns the full path of the directory
// containing the 'protoc-gen-go' executable.
func downloadProtocGenGo ( cachedir string ) string {
csdb := build . MustLoadChecksums ( "build/checksums.txt" )
version , err := build . Version ( csdb , "protoc-gen-go" )
if err != nil {
log . Fatal ( err )
}
baseName := fmt . Sprintf ( "protoc-gen-go.v%s.%s.%s" , version , runtime . GOOS , runtime . GOARCH )
archiveName := baseName
if runtime . GOOS == "windows" {
archiveName += ".zip"
} else {
archiveName += ".tar.gz"
}
url := fmt . Sprintf ( "https://github.com/protocolbuffers/protobuf-go/releases/download/v%s/%s" , version , archiveName )
archivePath := path . Join ( cachedir , archiveName )
if err := csdb . DownloadFile ( url , archivePath ) ; err != nil {
log . Fatal ( err )
}
extractDest := filepath . Join ( cachedir , baseName )
if err := build . ExtractArchive ( archivePath , extractDest ) ; err != nil {
log . Fatal ( err )
}
extractDest , err = filepath . Abs ( extractDest )
if err != nil {
log . Fatal ( "error resolving absolute path for protoc" , "err" , err )
}
return extractDest
}
// downloadProtoc downloads the prebuilt protoc binary used to lint generated
// files as a CI step. It returns the full path to the directory containing
// the protoc executable.
func downloadProtoc ( cachedir string ) string {
csdb := build . MustLoadChecksums ( "build/checksums.txt" )
version , err := build . Version ( csdb , "protoc" )
if err != nil {
log . Fatal ( err )
}
baseName , err := protocArchiveBaseName ( )
if err != nil {
log . Fatal ( err )
}
fileName := fmt . Sprintf ( "protoc-%s-%s" , version , baseName )
archiveFileName := fileName + ".zip"
url := fmt . Sprintf ( "https://github.com/protocolbuffers/protobuf/releases/download/v%s/%s" , version , archiveFileName )
archivePath := filepath . Join ( cachedir , archiveFileName )
if err := csdb . DownloadFile ( url , archivePath ) ; err != nil {
log . Fatal ( err )
}
extractDest := filepath . Join ( cachedir , fileName )
if err := build . ExtractArchive ( archivePath , extractDest ) ; err != nil {
log . Fatal ( err )
}
extractDest , err = filepath . Abs ( extractDest )
if err != nil {
log . Fatal ( "error resolving absolute path for protoc" , "err" , err )
}
return extractDest
}
2016-05-25 07:07:57 -05:00
// Release Packaging
func doArchive ( cmdline [ ] string ) {
var (
2020-11-27 05:13:54 -06:00
arch = flag . String ( "arch" , runtime . GOARCH , "Architecture cross packaging" )
atype = flag . String ( "type" , "zip" , "Type of archive to write (zip|tar)" )
signer = flag . String ( "signer" , "" , ` Environment variable holding the signing key (e.g. LINUX_SIGNING_KEY) ` )
signify = flag . String ( "signify" , "" , ` Environment variable holding the signify key (e.g. LINUX_SIGNIFY_KEY) ` )
upload = flag . String ( "upload" , "" , ` Destination to upload the archives (usually "gethstore/builds") ` )
ext string
2016-05-25 07:07:57 -05:00
)
flag . CommandLine . Parse ( cmdline )
switch * atype {
case "zip" :
ext = ".zip"
case "tar" :
ext = ".tar.gz"
default :
log . Fatal ( "unknown archive type: " , atype )
}
2016-09-30 15:03:08 -05:00
2016-11-03 07:44:16 -05:00
var (
2021-05-04 06:01:20 -05:00
env = build . Env ( )
2024-10-20 11:28:39 -05:00
basegeth = archiveBasename ( * arch , version . Archive ( env . Commit ) )
2018-07-30 03:56:40 -05:00
geth = "geth-" + basegeth + ext
alltools = "geth-alltools-" + basegeth + ext
2016-11-03 07:44:16 -05:00
)
2016-09-30 15:03:08 -05:00
maybeSkipArchive ( env )
2016-11-03 07:44:16 -05:00
if err := build . WriteArchive ( geth , gethArchiveFiles ) ; err != nil {
2016-05-25 07:07:57 -05:00
log . Fatal ( err )
}
2016-11-03 07:44:16 -05:00
if err := build . WriteArchive ( alltools , allToolsArchiveFiles ) ; err != nil {
2016-05-25 07:07:57 -05:00
log . Fatal ( err )
}
2019-05-16 18:06:20 -05:00
for _ , archive := range [ ] string { geth , alltools } {
2020-11-27 05:13:54 -06:00
if err := archiveUpload ( archive , * upload , * signer , * signify ) ; err != nil {
2016-11-02 11:21:05 -05:00
log . Fatal ( err )
}
}
2016-05-25 07:07:57 -05:00
}
2018-07-30 03:56:40 -05:00
func archiveBasename ( arch string , archiveVersion string ) string {
2016-11-02 12:36:48 -05:00
platform := runtime . GOOS + "-" + arch
2016-11-04 06:48:20 -05:00
if arch == "arm" {
platform += os . Getenv ( "GOARM" )
}
2016-10-17 07:17:14 -05:00
if arch == "android" {
platform = "android-all"
}
2016-11-09 03:13:37 -06:00
if arch == "ios" {
platform = "ios-all"
}
2018-07-30 03:56:40 -05:00
return platform + "-" + archiveVersion
2016-05-25 07:07:57 -05:00
}
2020-12-09 08:43:36 -06:00
func archiveUpload ( archive string , blobstore string , signer string , signifyVar string ) error {
2016-11-02 11:21:05 -05:00
// If signing was requested, generate the signature files
if signer != "" {
2019-02-12 03:55:25 -06:00
key := getenvBase64 ( signer )
if err := build . PGPSignFile ( archive , archive + ".asc" , string ( key ) ) ; err != nil {
2016-11-02 11:21:05 -05:00
return err
}
}
2020-12-09 08:43:36 -06:00
if signifyVar != "" {
key := os . Getenv ( signifyVar )
untrustedComment := "verify with geth-release.pub"
trustedComment := fmt . Sprintf ( "%s (%s)" , archive , time . Now ( ) . UTC ( ) . Format ( time . RFC1123 ) )
if err := signify . SignFile ( archive , archive + ".sig" , key , untrustedComment , trustedComment ) ; err != nil {
2020-11-27 05:13:54 -06:00
return err
}
}
2016-11-02 11:21:05 -05:00
// If uploading to Azure was requested, push the archive possibly with its signature
if blobstore != "" {
auth := build . AzureBlobstoreConfig {
Account : strings . Split ( blobstore , "/" ) [ 0 ] ,
Token : os . Getenv ( "AZURE_BLOBSTORE_TOKEN" ) ,
Container : strings . SplitN ( blobstore , "/" , 2 ) [ 1 ] ,
}
2016-11-08 16:46:46 -06:00
if err := build . AzureBlobstoreUpload ( archive , filepath . Base ( archive ) , auth ) ; err != nil {
2016-11-02 11:21:05 -05:00
return err
}
if signer != "" {
2016-11-08 16:46:46 -06:00
if err := build . AzureBlobstoreUpload ( archive + ".asc" , filepath . Base ( archive + ".asc" ) , auth ) ; err != nil {
2016-11-02 11:21:05 -05:00
return err
}
}
2020-12-09 08:43:36 -06:00
if signifyVar != "" {
2020-11-27 05:13:54 -06:00
if err := build . AzureBlobstoreUpload ( archive + ".sig" , filepath . Base ( archive + ".sig" ) , auth ) ; err != nil {
return err
}
}
2016-11-02 11:21:05 -05:00
}
return nil
}
2016-09-30 15:03:08 -05:00
// skips archiving for some build configurations.
func maybeSkipArchive ( env build . Environment ) {
if env . IsPullRequest {
2021-05-04 06:01:20 -05:00
log . Printf ( "skipping archive creation because this is a PR build" )
2016-09-30 15:03:08 -05:00
os . Exit ( 0 )
}
2016-11-15 07:11:27 -06:00
if env . Branch != "master" && ! strings . HasPrefix ( env . Tag , "v1." ) {
2021-07-29 10:36:15 -05:00
log . Printf ( "skipping archive creation because branch %q, tag %q is not on the inclusion list" , env . Branch , env . Tag )
2016-09-30 15:03:08 -05:00
os . Exit ( 0 )
}
}
2021-06-17 02:47:45 -05:00
// Builds the docker images and optionally uploads them to Docker Hub.
2024-09-30 07:39:53 -05:00
func doDockerBuildx ( cmdline [ ] string ) {
2021-06-17 02:47:45 -05:00
var (
2024-09-30 07:39:53 -05:00
platform = flag . String ( "platform" , "" , ` Push a multi-arch docker image for the specified architectures (usually "linux/amd64,linux/arm64") ` )
2021-06-18 07:28:30 -05:00
upload = flag . String ( "upload" , "" , ` Where to upload the docker image (usually "ethereum/client-go") ` )
2021-06-17 02:47:45 -05:00
)
flag . CommandLine . Parse ( cmdline )
// Skip building and pushing docker images for PR builds
env := build . Env ( )
maybeSkipArchive ( env )
2021-06-18 07:28:30 -05:00
// Retrieve the upload credentials and authenticate
user := getenvBase64 ( "DOCKER_HUB_USERNAME" )
pass := getenvBase64 ( "DOCKER_HUB_PASSWORD" )
if len ( user ) > 0 && len ( pass ) > 0 {
auther := exec . Command ( "docker" , "login" , "-u" , string ( user ) , "--password-stdin" )
auther . Stdin = bytes . NewReader ( pass )
build . MustRun ( auther )
}
2021-06-17 02:47:45 -05:00
// Retrieve the version infos to build and push to the following paths:
// - ethereum/client-go:latest - Pushes to the master branch, Geth only
// - ethereum/client-go:stable - Version tag publish on GitHub, Geth only
// - ethereum/client-go:alltools-latest - Pushes to the master branch, Geth & tools
// - ethereum/client-go:alltools-stable - Version tag publish on GitHub, Geth & tools
// - ethereum/client-go:release-<major>.<minor> - Version tag publish on GitHub, Geth only
// - ethereum/client-go:alltools-release-<major>.<minor> - Version tag publish on GitHub, Geth & tools
// - ethereum/client-go:v<major>.<minor>.<patch> - Version tag publish on GitHub, Geth only
// - ethereum/client-go:alltools-v<major>.<minor>.<patch> - Version tag publish on GitHub, Geth & tools
var tags [ ] string
switch {
case env . Branch == "master" :
tags = [ ] string { "latest" }
case strings . HasPrefix ( env . Tag , "v1." ) :
2024-10-20 11:28:39 -05:00
tags = [ ] string { "stable" , fmt . Sprintf ( "release-%v" , version . Family ) , "v" + version . Semantic }
2021-06-17 02:47:45 -05:00
}
2024-09-30 07:39:53 -05:00
// Need to create a mult-arch builder
build . MustRunCommand ( "docker" , "buildx" , "create" , "--use" , "--name" , "multi-arch-builder" , "--platform" , * platform )
for _ , spec := range [ ] struct {
file string
base string
} {
{ file : "Dockerfile" , base : fmt . Sprintf ( "%s:" , * upload ) } ,
{ file : "Dockerfile.alltools" , base : fmt . Sprintf ( "%s:alltools-" , * upload ) } ,
} {
for _ , tag := range tags { // latest, stable etc
gethImage := fmt . Sprintf ( "%s%s" , spec . base , tag )
build . MustRunCommand ( "docker" , "buildx" , "build" ,
"--build-arg" , "COMMIT=" + env . Commit ,
2024-10-20 11:28:39 -05:00
"--build-arg" , "VERSION=" + version . WithMeta ,
2024-09-30 07:39:53 -05:00
"--build-arg" , "BUILDNUM=" + env . Buildnum ,
"--tag" , gethImage ,
"--platform" , * platform ,
"--push" ,
"--file" , spec . file , "." )
2021-06-18 07:28:30 -05:00
}
2021-06-17 02:47:45 -05:00
}
}
2016-05-25 07:07:57 -05:00
// Debian Packaging
2016-09-30 15:03:08 -05:00
func doDebianSource ( cmdline [ ] string ) {
var (
2020-11-11 07:34:43 -06:00
cachedir = flag . String ( "cachedir" , "./build/cache" , ` Filesystem path to cache the downloaded Go bundles at ` )
signer = flag . String ( "signer" , "" , ` Signing key name, also used as package author ` )
upload = flag . String ( "upload" , "" , ` Where to upload the source package (usually "ethereum/ethereum") ` )
sshUser = flag . String ( "sftp-user" , "" , ` Username for SFTP upload (usually "geth-ci") ` )
workdir = flag . String ( "workdir" , "" , ` Output directory for packages (uses temp dir if unset) ` )
now = time . Now ( )
2016-09-30 15:03:08 -05:00
)
2016-05-25 07:07:57 -05:00
flag . CommandLine . Parse ( cmdline )
2016-09-30 15:03:08 -05:00
* workdir = makeWorkdir ( * workdir )
env := build . Env ( )
2021-05-04 06:01:20 -05:00
tc := new ( build . GoToolchain )
2016-09-30 15:03:08 -05:00
maybeSkipArchive ( env )
2016-05-25 07:07:57 -05:00
// Import the signing key.
2019-02-12 03:55:25 -06:00
if key := getenvBase64 ( "PPA_SIGNING_KEY" ) ; len ( key ) > 0 {
2016-05-25 07:07:57 -05:00
gpg := exec . Command ( "gpg" , "--import" )
gpg . Stdin = bytes . NewReader ( key )
build . MustRun ( gpg )
}
2023-02-20 00:53:15 -06:00
// Download and verify the Go source packages.
var (
2024-04-25 03:50:25 -05:00
gobootbundles = downloadGoBootstrapSources ( * cachedir )
gobundle = downloadGoSources ( * cachedir )
2023-02-20 00:53:15 -06:00
)
2019-11-21 08:14:31 -06:00
// Download all the dependencies needed to build the sources and run the ci script
2021-05-04 06:01:20 -05:00
srcdepfetch := tc . Go ( "mod" , "download" )
srcdepfetch . Env = append ( srcdepfetch . Env , "GOPATH=" + filepath . Join ( * workdir , "modgopath" ) )
2019-11-21 08:14:31 -06:00
build . MustRun ( srcdepfetch )
2021-05-04 06:01:20 -05:00
cidepfetch := tc . Go ( "run" , "./build/ci.go" )
cidepfetch . Env = append ( cidepfetch . Env , "GOPATH=" + filepath . Join ( * workdir , "modgopath" ) )
2019-11-21 08:14:31 -06:00
cidepfetch . Run ( ) // Command fails, don't care, we only need the deps to start it
2019-11-20 06:56:07 -06:00
2019-11-18 02:49:18 -06:00
// Create Debian packages and upload them.
2018-07-30 03:56:40 -05:00
for _ , pkg := range debPackages {
2024-04-25 06:07:39 -05:00
for _ , distro := range debDistros {
2019-11-18 02:49:18 -06:00
// Prepare the debian package with the go-ethereum sources.
2024-04-25 06:07:39 -05:00
meta := newDebMetadata ( distro , * signer , env , now , pkg . Name , pkg . Version , pkg . Executables )
2018-07-30 03:56:40 -05:00
pkgdir := stageDebianSource ( * workdir , meta )
travis, build, internal: use own Go bundle for PPA builds (#20240)
* build: bump PPAs to Go 1.13 (via longsleep), keep Trusty on 1.11
* travis, build, vendor: use own Go bundle for PPA builds
* travis, build, internal, vendor: smarter Go bundler, own untar
* build: updated ci-notes with new Go bundling, only make, don't test
2019-11-05 07:32:42 -06:00
2023-02-20 00:53:15 -06:00
// Add bootstrapper Go source code
2024-04-25 03:50:25 -05:00
for i , gobootbundle := range gobootbundles {
if err := build . ExtractArchive ( gobootbundle , pkgdir ) ; err != nil {
log . Fatalf ( "Failed to extract bootstrapper Go sources: %v" , err )
}
if err := os . Rename ( filepath . Join ( pkgdir , "go" ) , filepath . Join ( pkgdir , fmt . Sprintf ( ".goboot-%d" , i + 1 ) ) ) ; err != nil {
log . Fatalf ( "Failed to rename bootstrapper Go source folder: %v" , err )
}
2023-02-20 00:53:15 -06:00
}
// Add builder Go source code
2020-11-11 07:34:43 -06:00
if err := build . ExtractArchive ( gobundle , pkgdir ) ; err != nil {
2023-02-20 00:53:15 -06:00
log . Fatalf ( "Failed to extract builder Go sources: %v" , err )
travis, build, internal: use own Go bundle for PPA builds (#20240)
* build: bump PPAs to Go 1.13 (via longsleep), keep Trusty on 1.11
* travis, build, vendor: use own Go bundle for PPA builds
* travis, build, internal, vendor: smarter Go bundler, own untar
* build: updated ci-notes with new Go bundling, only make, don't test
2019-11-05 07:32:42 -06:00
}
if err := os . Rename ( filepath . Join ( pkgdir , "go" ) , filepath . Join ( pkgdir , ".go" ) ) ; err != nil {
2023-02-20 00:53:15 -06:00
log . Fatalf ( "Failed to rename builder Go source folder: %v" , err )
travis, build, internal: use own Go bundle for PPA builds (#20240)
* build: bump PPAs to Go 1.13 (via longsleep), keep Trusty on 1.11
* travis, build, vendor: use own Go bundle for PPA builds
* travis, build, internal, vendor: smarter Go bundler, own untar
* build: updated ci-notes with new Go bundling, only make, don't test
2019-11-05 07:32:42 -06:00
}
2019-11-18 11:18:50 -06:00
// Add all dependency modules in compressed form
2019-11-20 06:56:07 -06:00
os . MkdirAll ( filepath . Join ( pkgdir , ".mod" , "cache" ) , 0755 )
if err := cp . CopyAll ( filepath . Join ( pkgdir , ".mod" , "cache" , "download" ) , filepath . Join ( * workdir , "modgopath" , "pkg" , "mod" , "cache" , "download" ) ) ; err != nil {
2019-11-18 12:29:01 -06:00
log . Fatalf ( "Failed to copy Go module dependencies: %v" , err )
}
travis, build, internal: use own Go bundle for PPA builds (#20240)
* build: bump PPAs to Go 1.13 (via longsleep), keep Trusty on 1.11
* travis, build, vendor: use own Go bundle for PPA builds
* travis, build, internal, vendor: smarter Go bundler, own untar
* build: updated ci-notes with new Go bundling, only make, don't test
2019-11-05 07:32:42 -06:00
// Run the packaging and upload to the PPA
2019-11-21 10:18:59 -06:00
debuild := exec . Command ( "debuild" , "-S" , "-sa" , "-us" , "-uc" , "-d" , "-Zxz" , "-nc" )
2018-07-30 03:56:40 -05:00
debuild . Dir = pkgdir
build . MustRun ( debuild )
2016-05-25 07:07:57 -05:00
2019-02-14 09:10:09 -06:00
var (
2021-03-04 05:04:50 -06:00
basename = fmt . Sprintf ( "%s_%s" , meta . Name ( ) , meta . VersionString ( ) )
source = filepath . Join ( * workdir , basename + ".tar.xz" )
dsc = filepath . Join ( * workdir , basename + ".dsc" )
changes = filepath . Join ( * workdir , basename + "_source.changes" )
buildinfo = filepath . Join ( * workdir , basename + "_source.buildinfo" )
2019-02-14 09:10:09 -06:00
)
2018-07-30 03:56:40 -05:00
if * signer != "" {
build . MustRunCommand ( "debsign" , changes )
}
if * upload != "" {
2021-03-04 05:04:50 -06:00
ppaUpload ( * workdir , * upload , * sshUser , [ ] string { source , dsc , changes , buildinfo } )
2018-07-30 03:56:40 -05:00
}
2016-05-25 07:07:57 -05:00
}
}
}
2024-04-25 03:50:25 -05:00
// downloadGoBootstrapSources downloads the Go source tarball(s) that will be used
2023-02-20 00:53:15 -06:00
// to bootstrap the builder Go.
2024-04-25 03:50:25 -05:00
func downloadGoBootstrapSources ( cachedir string ) [ ] string {
2023-02-20 00:53:15 -06:00
csdb := build . MustLoadChecksums ( "build/checksums.txt" )
2024-04-25 03:50:25 -05:00
var bundles [ ] string
for _ , booter := range [ ] string { "ppa-builder-1" , "ppa-builder-2" } {
gobootVersion , err := build . Version ( csdb , booter )
if err != nil {
log . Fatal ( err )
}
file := fmt . Sprintf ( "go%s.src.tar.gz" , gobootVersion )
url := "https://dl.google.com/go/" + file
dst := filepath . Join ( cachedir , file )
if err := csdb . DownloadFile ( url , dst ) ; err != nil {
log . Fatal ( err )
}
bundles = append ( bundles , dst )
2023-02-20 00:53:15 -06:00
}
2024-04-25 03:50:25 -05:00
return bundles
2023-02-20 00:53:15 -06:00
}
2020-11-11 07:34:43 -06:00
// downloadGoSources downloads the Go source tarball.
func downloadGoSources ( cachedir string ) string {
2019-11-18 02:49:18 -06:00
csdb := build . MustLoadChecksums ( "build/checksums.txt" )
2023-10-13 07:14:48 -05:00
dlgoVersion , err := build . Version ( csdb , "golang" )
if err != nil {
log . Fatal ( err )
}
2020-11-11 07:34:43 -06:00
file := fmt . Sprintf ( "go%s.src.tar.gz" , dlgoVersion )
2019-11-18 02:49:18 -06:00
url := "https://dl.google.com/go/" + file
dst := filepath . Join ( cachedir , file )
if err := csdb . DownloadFile ( url , dst ) ; err != nil {
log . Fatal ( err )
}
return dst
}
2019-02-14 09:10:09 -06:00
func ppaUpload ( workdir , ppa , sshUser string , files [ ] string ) {
2019-02-12 03:55:25 -06:00
p := strings . Split ( ppa , "/" )
if len ( p ) != 2 {
log . Fatal ( "-upload PPA name must contain single /" )
}
2019-02-14 09:10:09 -06:00
if sshUser == "" {
sshUser = p [ 0 ]
2019-02-12 03:55:25 -06:00
}
2019-02-14 09:10:09 -06:00
incomingDir := fmt . Sprintf ( "~%s/ubuntu/%s" , p [ 0 ] , p [ 1 ] )
// Create the SSH identity file if it doesn't exist.
var idfile string
2019-02-12 03:55:25 -06:00
if sshkey := getenvBase64 ( "PPA_SSH_KEY" ) ; len ( sshkey ) > 0 {
2019-02-14 09:10:09 -06:00
idfile = filepath . Join ( workdir , "sshkey" )
2024-10-20 06:54:06 -05:00
if ! build . FileExist ( idfile ) {
2022-05-16 04:59:35 -05:00
os . WriteFile ( idfile , sshkey , 0600 )
2019-02-14 09:10:09 -06:00
}
}
// Upload
dest := sshUser + "@ppa.launchpad.net"
if err := build . UploadSFTP ( idfile , dest , incomingDir , files ) ; err != nil {
log . Fatal ( err )
2019-02-12 03:55:25 -06:00
}
}
func getenvBase64 ( variable string ) [ ] byte {
dec , err := base64 . StdEncoding . DecodeString ( os . Getenv ( variable ) )
if err != nil {
log . Fatal ( "invalid base64 " + variable )
}
return [ ] byte ( dec )
}
2016-09-30 15:03:08 -05:00
func makeWorkdir ( wdflag string ) string {
var err error
if wdflag != "" {
err = os . MkdirAll ( wdflag , 0744 )
} else {
2022-05-16 04:59:35 -05:00
wdflag , err = os . MkdirTemp ( "" , "geth-build-" )
2016-09-30 15:03:08 -05:00
}
if err != nil {
log . Fatal ( err )
}
return wdflag
}
func isUnstableBuild ( env build . Environment ) bool {
2016-11-18 12:55:19 -06:00
if env . Tag != "" {
2016-09-30 15:03:08 -05:00
return false
}
return true
2016-05-25 07:07:57 -05:00
}
2018-07-30 03:56:40 -05:00
type debPackage struct {
2019-05-16 18:06:20 -05:00
Name string // the name of the Debian package to produce, e.g. "ethereum"
Version string // the clean version of the debPackage, e.g. 1.8.12, without any metadata
2018-07-30 03:56:40 -05:00
Executables [ ] debExecutable // executables to be included in the package
}
2016-05-25 07:07:57 -05:00
type debMetadata struct {
2024-04-25 06:07:39 -05:00
Env build . Environment
2018-07-30 03:56:40 -05:00
PackageName string
2016-05-25 07:07:57 -05:00
// go-ethereum version being built. Note that this
// is not the debian package version. The package version
// is constructed by VersionString.
Version string
2016-09-30 15:03:08 -05:00
Author string // "name <email>", also selects signing key
Distro , Time string
Executables [ ] debExecutable
2016-05-25 07:07:57 -05:00
}
2016-09-30 15:03:08 -05:00
type debExecutable struct {
2018-07-30 03:56:40 -05:00
PackageName string
BinaryName string
Description string
}
// Package returns the name of the package if present, or
// fallbacks to BinaryName
func ( d debExecutable ) Package ( ) string {
if d . PackageName != "" {
return d . PackageName
}
return d . BinaryName
2016-09-30 15:03:08 -05:00
}
2024-04-25 06:07:39 -05:00
func newDebMetadata ( distro , author string , env build . Environment , t time . Time , name string , version string , exes [ ] debExecutable ) debMetadata {
2016-05-25 07:07:57 -05:00
if author == "" {
// No signing key, use default author.
author = "Ethereum Builds <fjl@ethereum.org>"
}
return debMetadata {
2024-04-25 06:07:39 -05:00
PackageName : name ,
Env : env ,
Author : author ,
Distro : distro ,
Version : version ,
Time : t . Format ( time . RFC1123Z ) ,
Executables : exes ,
2016-05-25 07:07:57 -05:00
}
}
// Name returns the name of the metapackage that depends
// on all executable packages.
func ( meta debMetadata ) Name ( ) string {
2016-09-30 15:03:08 -05:00
if isUnstableBuild ( meta . Env ) {
2018-07-30 03:56:40 -05:00
return meta . PackageName + "-unstable"
2016-05-25 07:07:57 -05:00
}
2018-07-30 03:56:40 -05:00
return meta . PackageName
2016-05-25 07:07:57 -05:00
}
// VersionString returns the debian version of the packages.
func ( meta debMetadata ) VersionString ( ) string {
vsn := meta . Version
2016-09-30 15:03:08 -05:00
if meta . Env . Buildnum != "" {
vsn += "+build" + meta . Env . Buildnum
2016-05-25 07:07:57 -05:00
}
if meta . Distro != "" {
vsn += "+" + meta . Distro
}
return vsn
}
// ExeList returns the list of all executable packages.
func ( meta debMetadata ) ExeList ( ) string {
names := make ( [ ] string , len ( meta . Executables ) )
for i , e := range meta . Executables {
names [ i ] = meta . ExeName ( e )
}
return strings . Join ( names , ", " )
}
// ExeName returns the package name of an executable package.
func ( meta debMetadata ) ExeName ( exe debExecutable ) string {
2016-09-30 15:03:08 -05:00
if isUnstableBuild ( meta . Env ) {
2018-07-30 03:56:40 -05:00
return exe . Package ( ) + "-unstable"
2016-05-25 07:07:57 -05:00
}
2018-07-30 03:56:40 -05:00
return exe . Package ( )
}
2016-05-25 07:07:57 -05:00
// ExeConflicts returns the content of the Conflicts field
// for executable packages.
func ( meta debMetadata ) ExeConflicts ( exe debExecutable ) string {
2016-09-30 15:03:08 -05:00
if isUnstableBuild ( meta . Env ) {
2016-05-25 07:07:57 -05:00
// Set up the conflicts list so that the *-unstable packages
// cannot be installed alongside the regular version.
//
// https://www.debian.org/doc/debian-policy/ch-relationships.html
// is very explicit about Conflicts: and says that Breaks: should
// be preferred and the conflicting files should be handled via
// alternates. We might do this eventually but using a conflict is
// easier now.
2018-07-30 03:56:40 -05:00
return "ethereum, " + exe . Package ( )
2016-05-25 07:07:57 -05:00
}
return ""
}
func stageDebianSource ( tmpdir string , meta debMetadata ) ( pkgdir string ) {
pkg := meta . Name ( ) + "-" + meta . VersionString ( )
pkgdir = filepath . Join ( tmpdir , pkg )
if err := os . Mkdir ( pkgdir , 0755 ) ; err != nil {
log . Fatal ( err )
}
// Copy the source code.
build . MustRunCommand ( "git" , "checkout-index" , "-a" , "--prefix" , pkgdir + string ( filepath . Separator ) )
// Put the debian build files in place.
debian := filepath . Join ( pkgdir , "debian" )
2018-07-30 03:56:40 -05:00
build . Render ( "build/deb/" + meta . PackageName + "/deb.rules" , filepath . Join ( debian , "rules" ) , 0755 , meta )
build . Render ( "build/deb/" + meta . PackageName + "/deb.changelog" , filepath . Join ( debian , "changelog" ) , 0644 , meta )
build . Render ( "build/deb/" + meta . PackageName + "/deb.control" , filepath . Join ( debian , "control" ) , 0644 , meta )
build . Render ( "build/deb/" + meta . PackageName + "/deb.copyright" , filepath . Join ( debian , "copyright" ) , 0644 , meta )
2016-05-25 07:07:57 -05:00
build . RenderString ( "8\n" , filepath . Join ( debian , "compat" ) , 0644 , meta )
build . RenderString ( "3.0 (native)\n" , filepath . Join ( debian , "source/format" ) , 0644 , meta )
for _ , exe := range meta . Executables {
2016-09-30 15:03:08 -05:00
install := filepath . Join ( debian , meta . ExeName ( exe ) + ".install" )
docs := filepath . Join ( debian , meta . ExeName ( exe ) + ".docs" )
2018-07-30 03:56:40 -05:00
build . Render ( "build/deb/" + meta . PackageName + "/deb.install" , install , 0644 , exe )
build . Render ( "build/deb/" + meta . PackageName + "/deb.docs" , docs , 0644 , exe )
2016-05-25 07:07:57 -05:00
}
return pkgdir
}
2016-08-08 05:41:55 -05:00
2016-11-08 15:55:39 -06:00
// Windows installer
func doWindowsInstaller ( cmdline [ ] string ) {
// Parse the flags and make skip installer generation on PRs
var (
arch = flag . String ( "arch" , runtime . GOARCH , "Architecture for cross build packaging" )
signer = flag . String ( "signer" , "" , ` Environment variable holding the signing key (e.g. WINDOWS_SIGNING_KEY) ` )
2020-11-27 05:13:54 -06:00
signify = flag . String ( "signify key" , "" , ` Environment variable holding the signify signing key (e.g. WINDOWS_SIGNIFY_KEY) ` )
2016-11-08 15:55:39 -06:00
upload = flag . String ( "upload" , "" , ` Destination to upload the archives (usually "gethstore/builds") ` )
workdir = flag . String ( "workdir" , "" , ` Output directory for packages (uses temp dir if unset) ` )
)
flag . CommandLine . Parse ( cmdline )
* workdir = makeWorkdir ( * workdir )
env := build . Env ( )
maybeSkipArchive ( env )
// Aggregate binaries that are included in the installer
var (
devTools [ ] string
allTools [ ] string
gethTool string
)
for _ , file := range allToolsArchiveFiles {
if file == "COPYING" { // license, copied later
continue
}
allTools = append ( allTools , filepath . Base ( file ) )
if filepath . Base ( file ) == "geth.exe" {
gethTool = file
} else {
devTools = append ( devTools , file )
}
}
// Render NSIS scripts: Installer NSIS contains two installer sections,
// first section contains the geth binary, second section holds the dev tools.
templateData := map [ string ] interface { } {
"License" : "COPYING" ,
"Geth" : gethTool ,
"DevTools" : devTools ,
}
build . Render ( "build/nsis.geth.nsi" , filepath . Join ( * workdir , "geth.nsi" ) , 0644 , nil )
build . Render ( "build/nsis.install.nsh" , filepath . Join ( * workdir , "install.nsh" ) , 0644 , templateData )
build . Render ( "build/nsis.uninstall.nsh" , filepath . Join ( * workdir , "uninstall.nsh" ) , 0644 , allTools )
2016-12-10 17:01:57 -06:00
build . Render ( "build/nsis.pathupdate.nsh" , filepath . Join ( * workdir , "PathUpdate.nsh" ) , 0644 , nil )
2016-11-08 15:55:39 -06:00
build . Render ( "build/nsis.envvarupdate.nsh" , filepath . Join ( * workdir , "EnvVarUpdate.nsh" ) , 0644 , nil )
2019-11-18 12:29:01 -06:00
if err := cp . CopyFile ( filepath . Join ( * workdir , "SimpleFC.dll" ) , "build/nsis.simplefc.dll" ) ; err != nil {
2022-05-03 16:37:37 -05:00
log . Fatalf ( "Failed to copy SimpleFC.dll: %v" , err )
2019-11-18 12:29:01 -06:00
}
if err := cp . CopyFile ( filepath . Join ( * workdir , "COPYING" ) , "COPYING" ) ; err != nil {
2022-05-03 16:37:37 -05:00
log . Fatalf ( "Failed to copy copyright note: %v" , err )
2019-11-18 12:29:01 -06:00
}
2016-11-08 15:55:39 -06:00
// Build the installer. This assumes that all the needed files have been previously
// built (don't mix building and packaging to keep cross compilation complexity to a
// minimum).
2024-10-20 11:28:39 -05:00
ver := strings . Split ( version . Semantic , "." )
2016-11-08 15:55:39 -06:00
if env . Commit != "" {
2024-10-20 11:28:39 -05:00
ver [ 2 ] += "-" + env . Commit [ : 8 ]
2016-11-08 15:55:39 -06:00
}
2024-10-20 11:28:39 -05:00
installer , err := filepath . Abs ( "geth-" + archiveBasename ( * arch , version . Archive ( env . Commit ) ) + ".exe" )
2022-08-30 07:40:15 -05:00
if err != nil {
log . Fatalf ( "Failed to convert installer file path: %v" , err )
}
2016-11-08 15:55:39 -06:00
build . MustRunCommand ( "makensis.exe" ,
"/DOUTPUTFILE=" + installer ,
2024-10-20 11:28:39 -05:00
"/DMAJORVERSION=" + ver [ 0 ] ,
"/DMINORVERSION=" + ver [ 1 ] ,
"/DBUILDVERSION=" + ver [ 2 ] ,
2016-11-08 15:55:39 -06:00
"/DARCH=" + * arch ,
filepath . Join ( * workdir , "geth.nsi" ) ,
)
// Sign and publish installer.
2020-11-27 05:13:54 -06:00
if err := archiveUpload ( installer , * upload , * signer , * signify ) ; err != nil {
2016-11-08 15:55:39 -06:00
log . Fatal ( err )
}
2016-11-09 03:13:37 -06:00
}
2016-10-17 07:17:14 -05:00
2017-04-06 05:53:33 -05:00
// Binary distribution cleanups
func doPurge ( cmdline [ ] string ) {
var (
store = flag . String ( "store" , "" , ` Destination from where to purge archives (usually "gethstore/builds") ` )
2018-09-28 13:05:46 -05:00
limit = flag . Int ( "days" , 30 , ` Age threshold above which to delete unstable archives ` )
2017-04-06 05:53:33 -05:00
)
flag . CommandLine . Parse ( cmdline )
if env := build . Env ( ) ; ! env . IsCronJob {
log . Printf ( "skipping because not a cron job" )
os . Exit ( 0 )
}
// Create the azure authentication and list the current archives
auth := build . AzureBlobstoreConfig {
Account : strings . Split ( * store , "/" ) [ 0 ] ,
Token : os . Getenv ( "AZURE_BLOBSTORE_TOKEN" ) ,
Container : strings . SplitN ( * store , "/" , 2 ) [ 1 ] ,
}
blobs , err := build . AzureBlobstoreList ( auth )
if err != nil {
log . Fatal ( err )
}
2020-07-04 13:10:48 -05:00
fmt . Printf ( "Found %d blobs\n" , len ( blobs ) )
2017-04-06 05:53:33 -05:00
// Iterate over the blobs, collect and sort all unstable builds
for i := 0 ; i < len ( blobs ) ; i ++ {
2022-03-02 05:05:14 -06:00
if ! strings . Contains ( * blobs [ i ] . Name , "unstable" ) {
2017-04-06 05:53:33 -05:00
blobs = append ( blobs [ : i ] , blobs [ i + 1 : ] ... )
i --
}
}
for i := 0 ; i < len ( blobs ) ; i ++ {
for j := i + 1 ; j < len ( blobs ) ; j ++ {
2022-03-02 05:05:14 -06:00
if blobs [ i ] . Properties . LastModified . After ( * blobs [ j ] . Properties . LastModified ) {
2017-04-06 05:53:33 -05:00
blobs [ i ] , blobs [ j ] = blobs [ j ] , blobs [ i ]
}
}
}
// Filter out all archives more recent that the given threshold
for i , blob := range blobs {
2022-03-02 05:05:14 -06:00
if time . Since ( * blob . Properties . LastModified ) < time . Duration ( * limit ) * 24 * time . Hour {
2017-04-06 05:53:33 -05:00
blobs = blobs [ : i ]
break
}
}
2020-07-04 13:10:48 -05:00
fmt . Printf ( "Deleting %d blobs\n" , len ( blobs ) )
2017-04-06 05:53:33 -05:00
// Delete all marked as such and return
if err := build . AzureBlobstoreDelete ( auth , blobs ) ; err != nil {
log . Fatal ( err )
}
}
2023-10-13 07:14:48 -05:00
func doSanityCheck ( ) {
build . DownloadAndVerifyChecksums ( build . MustLoadChecksums ( "build/checksums.txt" ) )
}