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 a3f57e0 commit 8a8a691
Show file tree
Hide file tree
Showing 5 changed files with 335 additions and 117 deletions.
59 changes: 2 additions & 57 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,62 +51,7 @@ jobs:
run: bash ./apply_patch.bash "${{ github.event.inputs.version }}"

- name: Build
run: go run . -dst=dist -goos=${{ matrix.goos }} -goarch=${{ matrix.goarch }}
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"

# This step gets the exact version of Go we're releasing (including minor), so if we give the input as `1.17` this might return `encore-go1.17.5`.
- name: 'Read the version of Go we built'
id: encore_go_version
run: echo "::set-output name=version::$(go run . --read-built-version)"

- name: 'Tar artifacts'
run: tar -czvf ${{ steps.encore_go_version.outputs.version }}-${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz -C dist/${{ matrix.goos }}_${{ matrix.goarch }} .

- name: 'Upload build artifact'
uses: actions/upload-artifact@v2
with:
name: ${{ steps.encore_go_version.outputs.version }}-${{ matrix.goos }}_${{ matrix.goarch }}
path: ${{ steps.encore_go_version.outputs.version }}-${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz
release:
runs-on: ubuntu-20.04
needs: build
steps:
- name: 'Download artifacts from build steps'
uses: actions/download-artifact@v2

- name: 'Convert windows artifact to zip'
run: |
cd ${{needs.build.outputs.built_version}}-windows_amd64
tar -xzf ${{needs.build.outputs.built_version}}-windows_amd64.tar.gz
zip -r ${{needs.build.outputs.built_version}}-windows_amd64.zip encore-go
- name: 'Move, rename and create checksums for the artifacts'
run: |
mkdir output
mv ${{needs.build.outputs.built_version}}-linux_amd64/${{needs.build.outputs.built_version}}-linux_amd64.tar.gz output/linux_x86-64.tar.gz
mv ${{needs.build.outputs.built_version}}-linux_arm64/${{needs.build.outputs.built_version}}-linux_arm64.tar.gz output/linux_arm64.tar.gz
mv ${{needs.build.outputs.built_version}}-darwin_amd64/${{needs.build.outputs.built_version}}-darwin_amd64.tar.gz output/macos_x86-64.tar.gz
mv ${{needs.build.outputs.built_version}}-darwin_arm64/${{needs.build.outputs.built_version}}-darwin_arm64.tar.gz output/macos_arm64.tar.gz
mv ${{needs.build.outputs.built_version}}-windows_amd64/${{needs.build.outputs.built_version}}-windows_amd64.tar.gz output/windows_x86-64.tar.gz
mv ${{needs.build.outputs.built_version}}-windows_amd64/${{needs.build.outputs.built_version}}-windows_amd64.zip output/windows_x86-64.zip
cd output
sha256sum * > checksums.txt
ls -R .
mv * ../
cd ..
cat checksums.txt
- name: 'Publish release'
uses: DomBlack/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ needs.build.outputs.built_version }}
name: ${{ needs.build.outputs.built_version }}
body: >
This release is the compiled version of ${{ needs.build.outputs.built_version }}
draft: false
allow_override: true
prerelease: ${{ github.event.inputs.prerelease }}
gzip: false
files: linux_x86-64.tar.gz linux_arm64.tar.gz windows_x86-64.tar.gz windows_x86-64.zip macos_arm64.tar.gz macos_x86-64.tar.gz checksums.txt
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 8a8a691

Please sign in to comment.