Skip to content

Commit

Permalink
Remove debugging code
Browse files Browse the repository at this point in the history
  • Loading branch information
Naatan committed Sep 18, 2023
1 parent e26f6b9 commit 28f7393
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 162 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ name: Build-Test-Deploy
- synchronize
- reopened
schedule:
-
cron: 0 0 * * *
- cron: 0 0 * * *

# === Workflow Permissions ===
permissions:
Expand All @@ -25,7 +24,7 @@ permissions:

# === Workflow-level environment variables ===
env:
AWS_REGION : us-east-1
AWS_REGION: us-east-1
AWS_ROLE_SESSION_NAME: gha-activestate-cli

# === JOBS ===
Expand Down Expand Up @@ -100,9 +99,7 @@ jobs:
- # == Setup macOS ==
name: Setup (macOS)
shell: bash
run: |
rm /usr/local/bin/wget
brew install fish
run: brew install fish
if: runner.os == 'macOS'

- # === Install Deps ===
Expand Down Expand Up @@ -244,7 +241,7 @@ jobs:
name: Generate Remote Install Deployment
shell: bash
run: state run generate-remote-install-deployment

- # === Configure AWS credentials ==
name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
Expand Down
15 changes: 4 additions & 11 deletions installers/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,10 @@ MINGW*|MSYS*)
esac

# Determine a fetch method
if [ ! -z "`command -v wget`" ] && [ $OS != "darwin" ]; then
which wget
wget --version | head -1
FETCH="wget -nv -O"
if [ ! -z "`command -v wget`" ]; then
FETCH="wget -q -O"
elif [ ! -z "`command -v curl`" ]; then
which curl | head -1
curl --version
FETCH="curl -sS -v -o"
FETCH="curl -sS -o"
else
error "Either wget or curl is required to download files"
exit 1
Expand Down Expand Up @@ -137,9 +133,7 @@ fi
progress "Preparing Installer for State Tool Package Manager version $VERSION"
STATEURL="$BASE_FILE_URL/$RELURL"
ARCHIVE="$OS-amd64$DOWNLOADEXT"
echo "Downloading ${STATEURL} to ${TMPDIR}/${ARCHIVE}"
ls -l "${TMPDIR}/${ARCHIVE}"
$FETCH $TMPDIR/$ARCHIVE $STATEURL 2>&1 | grep -v "\* TLS\|^{ \|^} "
$FETCH $TMPDIR/$ARCHIVE $STATEURL
# wget and curl differ on how to handle AWS' "Forbidden" result for unknown versions.
# wget will exit with nonzero status. curl simply creates an XML file with the forbidden error.
# If curl was used, make sure the file downloaded is of type 'data', according to the UNIX `file`
Expand All @@ -157,7 +151,6 @@ if [ ! -z "$SUM" -a "`$SHA256SUM -b $TMPDIR/$ARCHIVE | cut -d ' ' -f1`" != "$SU
error "SHA256 sum did not match:"
error "Expected: $SUM"
error "Received: `$SHA256SUM -b $TMPDIR/$ARCHIVE | cut -d ' ' -f1`"
ls -l "${TMPDIR}/${ARCHIVE}"
error "Aborting installation."
exit 1
fi
Expand Down
89 changes: 2 additions & 87 deletions scripts/ci/s3-deployer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package main

import (
"bytes"
"crypto/sha256"
"encoding/hex"
"fmt"
"log"
"net/http"
Expand All @@ -16,7 +14,6 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/s3/s3manager"

"github.com/ActiveState/cli/internal/condition"
)
Expand Down Expand Up @@ -48,28 +45,11 @@ func run() {
createSession()
fileList := getFileList()

hasTmpDir := true
tmpDir, err := os.MkdirTemp("", "")
if err != nil {
fmt.Println(err)
hasTmpDir = false
}

// Upload the files
fmt.Printf("Uploading %d files\n", len(fileList))
for _, path := range fileList {
params := prepareFile(path)
uploadFile(params)

if hasTmpDir {
filename, err := downloadFile(tmpDir, params)
if err != nil {
fmt.Println(err)
continue
}
fmt.Printf("Downloaded %q with hash: ", filename)
fmt.Println(generateSHA256(filename))
}
}
}

Expand All @@ -82,8 +62,8 @@ func (l *logger) Log(v ...interface{}) {
func createSession() {
// Specify profile to load for the session's config
var err error
verboseErr := true
logLevel := aws.LogDebug
var verboseErr = true
var logLevel = aws.LogDebug
_ = logLevel
opts := session.Options{
Config: aws.Config{
Expand Down Expand Up @@ -163,71 +143,6 @@ func uploadFile(params *s3.PutObjectInput) {
}
}

func generateSHA256(path string) string {
hasher := sha256.New()
b, err := os.ReadFile(path)
if err != nil {
log.Fatalln(err)
}
if _, err := hasher.Write(b); err != nil {
log.Fatalln(err)
}

return hex.EncodeToString(hasher.Sum(nil))
}

/*func systemSHA256Sum(file string) (string, error) {
cmdText := "sha256sum"
var cmdArgs []string
if runtime.GOOS == "darwin" {
cmdText = "shasum"
cmdArgs = []string{"-a", "256"}
}
cmdArgs = append(cmdArgs, file)
cmd := exec.Command(cmdText, cmdArgs...)
out, err := cmd.CombinedOutput()
if err != nil {
return "", fmt.Errorf("failed to collect sha sum: gather combined output: %w\n", err)
}
rawText := string(out)
sum, _, ok := strings.Cut(rawText, " ")
if !ok {
return "", fmt.Errorf("failed to collect sha sum: cannot find sum in %q\n", rawText)
}
return sum, nil
}*/

func downloadFile(dir string, put *s3.PutObjectInput) (string, error) {
filename := filepath.Join(dir, *put.Key)

if err := os.MkdirAll(filepath.Dir(filename), 0o755); err != nil {
return "", err
}

file, err := os.Create(filename)
if err != nil {
return "", err
}
defer file.Close()

dler := s3manager.NewDownloader(sess)
params := &s3.GetObjectInput{
Bucket: put.Bucket,
Key: put.Key,
}

if _, err := dler.Download(file, params); err != nil {
return "", err
}

return filename, nil
}

func normalizePath(p string) string {
return path.Join(strings.Split(p, "\\")...)
}
Expand Down
66 changes: 9 additions & 57 deletions scripts/ci/update-generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"

"github.com/mholt/archiver"

Expand All @@ -29,7 +28,6 @@ var (
defaultBuildDir = filepath.Join(rootPath, "build")
defaultInputDir = filepath.Join(defaultBuildDir, "payload", constants.ToplevelInstallArchiveDir)
defaultOutputDir = filepath.Join(rootPath, "public")
infoFileName = "info.json"
)

func main() {
Expand All @@ -53,14 +51,11 @@ func fetchPlatform() string {

func generateSha256(path string) string {
hasher := sha256.New()
b, err := os.ReadFile(path)
b, err := ioutil.ReadFile(path)
if err != nil {
log.Fatalln(err)
log.Fatal(err)
}
if _, err := hasher.Write(b); err != nil {
log.Fatalln(err)
}

hasher.Write(b)
return hex.EncodeToString(hasher.Sum(nil))
}

Expand All @@ -71,34 +66,6 @@ func archiveMeta() (archiveMethod archiver.Archiver, ext string) {
return archiver.NewTarGz(), ".tar.gz"
}

func systemSHA256Sum(file string) string {
cmdText := "sha256sum"
var cmdArgs []string

if runtime.GOOS == "darwin" {
cmdText = "shasum"
cmdArgs = []string{"-a", "256"}
}

cmdArgs = append(cmdArgs, file)

cmd := exec.Command(cmdText, cmdArgs...)
out, err := cmd.CombinedOutput()
if err != nil {
fmt.Printf("error collecting sha sum: gather combined output: %v\n", err)
return ""
}

rawText := string(out)
sum, _, ok := strings.Cut(rawText, " ")
if !ok {
fmt.Printf("error collecting sha sum: cannot find sum in %q\n", rawText)
return ""
}

return sum
}

func createUpdate(outputPath, channel, version, platform, target string) error {
relChannelPath := filepath.Join(channel, platform)
relVersionedPath := filepath.Join(channel, version, platform)
Expand All @@ -117,39 +84,24 @@ func createUpdate(outputPath, channel, version, platform, target string) error {
return errs.Wrap(err, "Archiving failed")
}

tmpDir, err := os.MkdirTemp("", "")
if err != nil {
fmt.Printf("TmpDir creation failed: %v\n", err)
}
if err := archiver.Unarchive(archivePath, tmpDir); err != nil {
fmt.Printf("Unarchiving failed: %v\n", err)
}

avUpdate := updater.NewAvailableUpdate(channel, version, platform, filepath.ToSlash(relArchivePath), generateSha256(archivePath), "")
b, err := json.MarshalIndent(avUpdate, "", " ")
if err != nil {
return errs.Wrap(err, "Failed to marshal AvailableUpdate information.")
}

infoPath := filepath.Join(outputPath, relChannelPath, infoFileName)
infoPath := filepath.Join(outputPath, relChannelPath, "info.json")
fmt.Printf("Creating %s\n", infoPath)
err = os.WriteFile(infoPath, b, 0o755)
err = ioutil.WriteFile(infoPath, b, 0o755)
if err != nil {
return errs.Wrap(err, "Failed to write info file (%s).", infoPath)
return errs.Wrap(err, "Failed to write info.json.")
}

copyInfoPath := filepath.Join(outputPath, relVersionedPath, filepath.Base(infoPath))
fmt.Printf("Creating copy of info file as %s\n", copyInfoPath)
err = fileutils.CopyFile(infoPath, copyInfoPath)
err = fileutils.CopyFile(infoPath, filepath.Join(outputPath, relVersionedPath, filepath.Base(infoPath)))
if err != nil {
return errs.Wrap(err, "Could not copy info file to (%s).", copyInfoPath)
return errs.Wrap(err, "Could not copy info.json file")
}

fmt.Printf("Generated SHA sum: %s\n", avUpdate.Sha256)

systemSum := systemSHA256Sum(archivePath)
fmt.Printf("System calculated SHA sum: %s\n", systemSum)

return nil
}

Expand Down

0 comments on commit 28f7393

Please sign in to comment.