Skip to content

Commit

Permalink
Tweak release process
Browse files Browse the repository at this point in the history
  • Loading branch information
eandre committed Mar 19, 2024
1 parent c7b167e commit b015448
Show file tree
Hide file tree
Showing 5 changed files with 390 additions and 60 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/release-2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Release

on:
workflow_dispatch:
inputs:
version:
description: 'Go version to build ("1.21")'
required: true
prerelease:
description: 'Is this a pre-release?'
required: true
default: 'false'

jobs:
build:
strategy:
matrix:
include:
- builder: macos-latest
goos: darwin
goarch: arm64
- builder: macos-latest
goos: darwin
goarch: amd64
- builder: ubuntu-20.04
goos: linux
goarch: amd64
- builder: ubuntu-20.04
goos: linux
goarch: arm64
- builder: windows-latest
goos: windows
goarch: amd64

runs-on: ${{ matrix.builder }}
outputs:
built_version: ${{ steps.encore_go_version.outputs.version }}
steps:
- name: Check out repo
uses: actions/checkout@v2
with:
fetch-depth: 0 # We need the full history for the Go submodule
submodules: true # Checkout the Go submodule

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.20'

- name: 'Create patched runtime'
run: bash ./apply_patch.bash "${{ github.event.inputs.version }}"

- name: Build
run: go run . -dst=dist -goos=${{ matrix.goos }} -goarch=${{ matrix.goarch }} -upload=true
env:
ENCORE_RELEASER_GCS_KEY: ${{ secrets.ENCORE_RELEASER_GCS_KEY }}
GO111MODULE: "on"
113 changes: 112 additions & 1 deletion builder/encore-build.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package builder

import (
"context"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strings"

"cloud.google.com/go/storage"
"google.golang.org/api/option"
)

type Builder struct {
Expand Down Expand Up @@ -118,6 +125,54 @@ func (b *Builder) CleanOutput() error {
return nil
}

func (b *Builder) Upload() error {
ctx := context.Background()
creds := os.Getenv("ENCORE_RELEASER_GCS_KEY")
client, err := storage.NewClient(ctx, option.WithCredentialsJSON([]byte(creds)))
if err != nil {
return err
}

// Tar the artifacts.
goVersion, err := readBuiltVersion()
if err != nil {
return fmt.Errorf("unable to read built version: %v", err)
}

// Create a tar.gz file.
fmt.Println("Creating tar.gz file...")
filename := fmt.Sprintf("%s-%s_%s.tar.gz", goVersion, b.GOOS, b.GOARCH)
srcDir := filepath.Join(b.dst, b.GOOS+"_"+b.GOARCH)
cmd := exec.Command("tar", "-czvf", filename, "-C", srcDir, ".")

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("tar: %v", err)
}

objectPath := fmt.Sprintf("encore-go/%s/%s-%s.tar.gz", goVersion, b.GOOS, b.GOARCH)
obj := client.Bucket("encore-releaser").Object(objectPath)

{
input, err := os.Open(filename)
if err != nil {
return fmt.Errorf("unable to open file: %v", err)
}
ctx, cancel := context.WithCancel(ctx)
defer cancel()
w := obj.NewWriter(ctx)
if _, err := io.Copy(w, input); err != nil {
return fmt.Errorf("unable to copy file: %v", err)
}
if err := w.Close(); err != nil {
return fmt.Errorf("unable to complete upload: %v", err)
}
}

return nil
}

func join(strs ...string) string {
return filepath.Join(strs...)
}
Expand All @@ -130,7 +185,7 @@ func all(src string, all ...string) []string {
return res
}

func BuildEncoreGo(goos, goarch, root, dst string) error {
func BuildEncoreGo(goos, goarch, root, dst string, upload bool) error {
if _, err := os.Stat(filepath.Join(root, "go", "src", "make.bash")); err != nil {
return fmt.Errorf("unexpected location for build script, expected in encore-go root")
}
Expand Down Expand Up @@ -167,8 +222,64 @@ func BuildEncoreGo(goos, goarch, root, dst string) error {
}
}

if upload {
if err := b.Upload(); err != nil {
return err
}
}

return nil
}

// exe suffix
var exe string

func readBuiltVersion() (version string, err error) {
var str string
if isfile("go/VERSION") {
// If we're building from a release branch, we use this as the base
str, err = readfile("go/VERSION")
if err != nil {
return "", fmt.Errorf("unable to read file: %w", err)
}
// Then we repeat the replace we do within the src/cmd/dist/build.go
str = strings.Replace(str, "go1.", "encore-go1.", 1)
} else {
// Otherwise we read the cache file which would be created by the build process
// if there was no VERSION file present
str, err = readfile("go/VERSION.cache")
if err != nil {
return "", fmt.Errorf("unable to read file: %w", err)
}
}

// With our patches there must always be an `encore-go1.xx` version in this string
// (there may be other bits, like "devel" or "beta" which we don't care about)
re, err := regexp.Compile("(encore-go[^ ]+)")
if err != nil {
return "", fmt.Errorf("unable to compile regex: %w", err)
}
version = re.FindString(str)
if version == "" {
return "", fmt.Errorf("unable to extract version, read: %s", version)
}

// In Go 1.21 the time was added as the second line of the VERSION file
// so we only want the first line
version, _, _ = strings.Cut(version, "\n")
version = strings.TrimSpace(version)

return version, nil
}

// isfile reports whether p names an existing file.
func isfile(p string) bool {
fi, err := os.Stat(p)
return err == nil && fi.Mode().IsRegular()
}

// readfile returns the content of the named file.
func readfile(file string) (string, error) {
data, err := os.ReadFile(file)
return strings.TrimRight(string(data), " \t\r\n"), err
}
37 changes: 37 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
module go.encore.dev/go

go 1.20

require (
cloud.google.com/go v0.112.1 // indirect
cloud.google.com/go/compute v1.24.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.6 // indirect
cloud.google.com/go/storage v1.39.1 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.2 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.48.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.48.0 // indirect
go.opentelemetry.io/otel v1.23.0 // indirect
go.opentelemetry.io/otel/metric v1.23.0 // indirect
go.opentelemetry.io/otel/trace v1.23.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/oauth2 v0.17.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/api v0.167.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240304161311-37d4d3c04a78 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240228224816-df926f6c8641 // indirect
google.golang.org/grpc v1.62.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
)
Loading

0 comments on commit b015448

Please sign in to comment.