@@ -3,6 +3,7 @@ package ssh
3
3
import (
4
4
"bufio"
5
5
"bytes"
6
+ _ "embed"
6
7
"fmt"
7
8
"log"
8
9
"net"
@@ -21,13 +22,15 @@ import (
21
22
const (
22
23
BitriseHostPattern = "BitriseRunningVM"
23
24
SSHKeyName = "id_bitrise_remote_access"
24
- localReadmeFilePath = "assets/README_REMOTE_ACCESS.md"
25
25
remoteReadmeFileName = "README_REMOTE_ACCESS.md"
26
26
sourceDirEnvVar = "BITRISE_SOURCE_DIR"
27
27
revisionEnvVar = "BITRISE_OSX_STACK_REV_ID"
28
28
osTypeEnvVar = "OSTYPE"
29
29
)
30
30
31
+ //go:embed README_REMOTE_ACCESS.md
32
+ var readmeFile string
33
+
31
34
type ConfigEntry struct {
32
35
Host string
33
36
HostName string
@@ -359,7 +362,7 @@ func getRemoteEnvVars(client *cryptoSSH.Client, envVars []string) (map[string]st
359
362
return envMap , nil
360
363
}
361
364
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 {
363
366
sftpClient , err := sftp .NewClient (client )
364
367
if err != nil {
365
368
return fmt .Errorf ("create SFTP client: %w" , err )
@@ -378,12 +381,7 @@ func copyFileToRemote(client *cryptoSSH.Client, localFilePath, remoteFilePath st
378
381
}
379
382
defer dstFile .Close ()
380
383
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
387
385
for key , value := range replace {
388
386
modifiedContent = strings .ReplaceAll (modifiedContent , key , value )
389
387
}
@@ -459,6 +457,7 @@ func SetupRemoteConfig(configEntry *ConfigEntry) (bool, string, error) {
459
457
log .Println ("Connected to remote host" )
460
458
defer client .Close ()
461
459
460
+ log .Println ("Detecting remote environment..." )
462
461
envMap , err := getRemoteEnvVars (client , []string {sourceDirEnvVar , osTypeEnvVar , revisionEnvVar })
463
462
if err != nil {
464
463
return isMacOs , "" , err
@@ -482,7 +481,7 @@ func SetupRemoteConfig(configEntry *ConfigEntry) (bool, string, error) {
482
481
}
483
482
484
483
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 {
486
485
log .Printf ("copy README file to remote: %s" , err )
487
486
} else {
488
487
log .Println ("README file copied" )
0 commit comments