Skip to content

Commit 0aa2cd7

Browse files
authored
Merge pull request #8 from bitrise-io/copyReadmeToRemote
Embed readme file into plugin binary
2 parents ba54ab4 + 5d578f2 commit 0aa2cd7

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed
File renamed without changes.

ssh/ssh.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ssh
33
import (
44
"bufio"
55
"bytes"
6+
_ "embed"
67
"fmt"
78
"log"
89
"net"
@@ -21,13 +22,15 @@ import (
2122
const (
2223
BitriseHostPattern = "BitriseRunningVM"
2324
SSHKeyName = "id_bitrise_remote_access"
24-
localReadmeFilePath = "assets/README_REMOTE_ACCESS.md"
2525
remoteReadmeFileName = "README_REMOTE_ACCESS.md"
2626
sourceDirEnvVar = "BITRISE_SOURCE_DIR"
2727
revisionEnvVar = "BITRISE_OSX_STACK_REV_ID"
2828
osTypeEnvVar = "OSTYPE"
2929
)
3030

31+
//go:embed README_REMOTE_ACCESS.md
32+
var readmeFile string
33+
3134
type ConfigEntry struct {
3235
Host string
3336
HostName string
@@ -359,7 +362,7 @@ func getRemoteEnvVars(client *cryptoSSH.Client, envVars []string) (map[string]st
359362
return envMap, nil
360363
}
361364

362-
func copyFileToRemote(client *cryptoSSH.Client, localFilePath, remoteFilePath string, replace map[string]string) error {
365+
func copyReadmeToRemote(client *cryptoSSH.Client, remoteFilePath string, replace map[string]string) error {
363366
sftpClient, err := sftp.NewClient(client)
364367
if err != nil {
365368
return fmt.Errorf("create SFTP client: %w", err)
@@ -378,12 +381,7 @@ func copyFileToRemote(client *cryptoSSH.Client, localFilePath, remoteFilePath st
378381
}
379382
defer dstFile.Close()
380383

381-
content, err := os.ReadFile(localFilePath)
382-
if err != nil {
383-
return fmt.Errorf("read source file: %w", err)
384-
}
385-
386-
modifiedContent := string(content)
384+
modifiedContent := readmeFile
387385
for key, value := range replace {
388386
modifiedContent = strings.ReplaceAll(modifiedContent, key, value)
389387
}
@@ -459,6 +457,7 @@ func SetupRemoteConfig(configEntry *ConfigEntry) (bool, string, error) {
459457
log.Println("Connected to remote host")
460458
defer client.Close()
461459

460+
log.Println("Detecting remote environment...")
462461
envMap, err := getRemoteEnvVars(client, []string{sourceDirEnvVar, osTypeEnvVar, revisionEnvVar})
463462
if err != nil {
464463
return isMacOs, "", err
@@ -482,7 +481,7 @@ func SetupRemoteConfig(configEntry *ConfigEntry) (bool, string, error) {
482481
}
483482

484483
log.Printf("Copying README file to remote...")
485-
if err := copyFileToRemote(client, localReadmeFilePath, remotePath, replaceInFile); err != nil {
484+
if err := copyReadmeToRemote(client, remotePath, replaceInFile); err != nil {
486485
log.Printf("copy README file to remote: %s", err)
487486
} else {
488487
log.Println("README file copied")

0 commit comments

Comments
 (0)