Skip to content

Commit 869b680

Browse files
committed
Updated android studio, aws-cli, aws-profile and homebrew to use the new pty + tests
1 parent aed04e8 commit 869b680

File tree

17 files changed

+164
-172
lines changed

17 files changed

+164
-172
lines changed

package-lock.json

Lines changed: 17 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
"ajv": "^8.12.0",
2727
"ajv-formats": "^2.1.1",
2828
"chalk": "^5.3.0",
29-
"codify-plugin-lib": "^1.0.181",
30-
"codify-schemas": "1.0.63",
29+
"codify-plugin-lib": "1.0.182-beta18",
30+
"codify-schemas": "1.0.86-beta5",
3131
"debug": "^4.3.4",
3232
"lodash.isequal": "^4.5.0",
3333
"nanoid": "^5.0.9",
@@ -55,7 +55,7 @@
5555
"@types/node": "^18",
5656
"@types/plist": "^3.0.5",
5757
"@types/semver": "^7.5.4",
58-
"codify-plugin-test": "0.0.53",
58+
"codify-plugin-test": "0.0.53-beta7",
5959
"commander": "^12.1.0",
6060
"eslint": "^8.51.0",
6161
"eslint-config-oclif": "^5",

scripts/init.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
tart clone ghcr.io/kevinwang5658/sonoma-codify:v0.0.3 codify-test-vm
2+
tart set codify-test-vm --memory 6124 --cpu 4
3+
24
# tart clone ghcr.io/kevinwang5658/sonoma-codify:v0.0.3 codify-sonoma

scripts/run-tests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async function launchTestAll(debug: boolean): Promise<void> {
3939

4040
async function launchSingleTest(test: string, debug: boolean) {
4141
console.log(`Running test: ${test}`)
42-
await run(`cirrus run --lazy-pull integration_individual_test_linux -e FILE_NAME="${test}" -o simple`, debug)
42+
await run(`cirrus run --lazy-pull integration_individual_test -e FILE_NAME="${test}" -o simple`, debug)
4343
}
4444

4545
async function run(cmd: string, debug: boolean, simple = true) {

src/resources/android/android-studio.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { CreatePlan, Resource, ResourceSettings } from 'codify-plugin-lib';
2-
import { ResourceConfig } from 'codify-schemas';
3-
import * as fs from 'node:fs';
1+
import { CreatePlan, Resource, ResourceSettings, getPty } from 'codify-plugin-lib';
2+
import { OS, ResourceConfig } from 'codify-schemas';
3+
import * as fs from 'node:fs/promises';
4+
import os from 'node:os';
45
import path from 'node:path';
56
import plist from 'plist';
67

7-
import { codifySpawn } from '../../utils/codify-spawn.js';
88
import { Utils } from '../../utils/index.js';
99
import Schema from './android-studio-schema.json';
1010
import { AndroidStudioPlist, AndroidStudioVersionData } from './types.js';
@@ -21,6 +21,7 @@ export class AndroidStudioResource extends Resource<AndroidStudioConfig> {
2121
override getSettings(): ResourceSettings<AndroidStudioConfig> {
2222
return {
2323
id: 'android-studio',
24+
operatingSystems: [OS.Darwin],
2425
schema: Schema,
2526
parameterSettings: {
2627
directory: { type: 'directory', default: '/Applications' },
@@ -50,6 +51,8 @@ export class AndroidStudioResource extends Resource<AndroidStudioConfig> {
5051
}
5152

5253
override async create(plan: CreatePlan<AndroidStudioConfig>): Promise<void> {
54+
const $ = getPty();
55+
5356
if (!this.allAndroidStudioVersions) {
5457
this.allAndroidStudioVersions = await this.fetchAllAndroidStudioVersions()
5558
}
@@ -64,16 +67,14 @@ export class AndroidStudioResource extends Resource<AndroidStudioConfig> {
6467
: versionToDownload.download.find((v) => v.link.includes('mac.dmg'))!
6568

6669
// Create a temporary tmp dir
67-
const temporaryDirQuery = await codifySpawn('mktemp -d');
68-
const temporaryDir = temporaryDirQuery.data.trim();
70+
const temporaryDir = await fs.mkdtemp(path.join(os.tmpdir(), 'codify-android-'))
6971

7072
try {
7173

7274
// Download and unzip the terraform binary
73-
await codifySpawn(`curl -fsSL --progress-bar ${downloadLink.link} -o android-studio.dmg`, { cwd: temporaryDir });
74-
75+
await $.spawn(`curl -fsSL ${downloadLink.link} -o android-studio.dmg`, { cwd: temporaryDir });
7576

76-
const { data } = await codifySpawn('hdiutil attach android-studio.dmg', { cwd: temporaryDir });
77+
const { data } = await $.spawn('hdiutil attach android-studio.dmg', { cwd: temporaryDir });
7778
const mountedDir = data.split(/\n/)
7879
.find((l) => l.includes('/Volumes/'))
7980
?.split(' ')
@@ -85,28 +86,27 @@ export class AndroidStudioResource extends Resource<AndroidStudioConfig> {
8586
}
8687

8788
try {
88-
const { data: contents } = await codifySpawn('ls', { cwd: mountedDir })
89+
const contents = await fs.readdir(mountedDir);
8990

9091
// Depending on it's preview or regular the name is different
91-
const appName = contents.split(/\n/)
92+
const appName = contents
9293
.find((l) => l.includes('Android'))
9394

94-
await codifySpawn(`rsync -rl "${appName}" Applications/`, { cwd: mountedDir, requiresRoot: true })
95-
96-
95+
// Must rsync because mounted dirs are read-only (can't delete via mv)
96+
await $.spawn(`rsync -rl "${appName}" Applications/`, { cwd: mountedDir })
9797
} finally {
9898
// Unmount
99-
await codifySpawn(`hdiutil detach "${mountedDir}"`)
99+
await $.spawnSafe(`hdiutil detach "${mountedDir}"`)
100100
}
101101

102102
} finally {
103103
// Delete the tmp directory
104-
await codifySpawn(`rm -r ${temporaryDir}`)
104+
await fs.rm(temporaryDir, { recursive: true, force: true });
105105
}
106106
}
107107

108108
override async destroy(): Promise<void> {
109-
await codifySpawn('rm -r "/Applications/Android Studio.app"', { requiresRoot: true })
109+
await fs.rm('/Applications/Android Studio.app', { force: true, recursive: true });
110110
}
111111

112112
private async fetchAllAndroidStudioVersions(): Promise<AndroidStudioVersionData[]> {
@@ -121,7 +121,7 @@ export class AndroidStudioResource extends Resource<AndroidStudioConfig> {
121121

122122
private async addPlistData(location: string): Promise<{ location: string, plist: AndroidStudioPlist } | null> {
123123
try {
124-
const file = fs.readFileSync(path.join(location, '/Contents/Info.plist'), 'utf8');
124+
const file = await fs.readFile(path.join(location, '/Contents/Info.plist'), 'utf8');
125125
const plistData = plist.parse(file) as unknown as AndroidStudioPlist;
126126

127127
return { location, plist: plistData };

src/resources/aws-cli/cli/aws-cli.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { getPty, Resource, ResourceSettings } from 'codify-plugin-lib';
2-
import { StringIndexedObject } from 'codify-schemas';
1+
import { Resource, ResourceSettings, getPty, SpawnStatus } from 'codify-plugin-lib';
2+
import { OS, StringIndexedObject } from 'codify-schemas';
3+
import fs from 'node:fs/promises';
34

4-
import { SpawnStatus, codifySpawn } from '../../../utils/codify-spawn.js';
55
import { Utils } from '../../../utils/index.js';
66
import Schema from './aws-cli-schema.json';
77

@@ -16,6 +16,7 @@ export class AwsCliResource extends Resource<AwsCliConfig> {
1616
getSettings(): ResourceSettings<AwsCliConfig> {
1717
return {
1818
schema: Schema,
19+
operatingSystems: [OS.Darwin],
1920
id: 'aws-cli',
2021
};
2122
}
@@ -25,6 +26,8 @@ export class AwsCliResource extends Resource<AwsCliConfig> {
2526
const $ = getPty();
2627

2728
const awsCliInfo = await $.spawnSafe('which aws');
29+
console.log('Spawn result', awsCliInfo);
30+
2831
if (awsCliInfo.status === SpawnStatus.ERROR) {
2932
return null;
3033
}
@@ -33,6 +36,8 @@ export class AwsCliResource extends Resource<AwsCliConfig> {
3336
}
3437

3538
override async create(): Promise<void> {
39+
const $ = getPty();
40+
3641
// Amazon has not released a standalone way to install arm aws-cli. See: https://github.com/aws/aws-cli/issues/7252
3742
// Prefer the homebrew version on M1
3843
const isArmArch = await Utils.isArmArch();
@@ -41,13 +46,13 @@ export class AwsCliResource extends Resource<AwsCliConfig> {
4146

4247
if (isArmArch && isHomebrewInstalled) {
4348
console.log('Resource: \'aws-cli\'. Detected that mac is aarch64. Installing AWS-CLI via homebrew')
44-
await codifySpawn('brew install awscli')
49+
await $.spawn('HOMEBREW_NO_AUTO_UPDATE=1 brew install awscli', { interactive: true })
4550

4651
} else if (!isArmArch || isRosettaInstalled) {
4752
console.log('Resource: \'aws-cli\'. Detected that mac is not ARM or Rosetta is installed. Installing AWS-CLI standalone version')
48-
await codifySpawn('curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"');
49-
await codifySpawn('installer -pkg ./AWSCLIV2.pkg -target /', { requiresRoot: true })
50-
await codifySpawn('rm -rf ./AWSCLIV2.pkg')
53+
await $.spawn('curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"');
54+
await $.spawn('installer -pkg ./AWSCLIV2.pkg -target /', { requiresRoot: true })
55+
await fs.rm('./AWSCLIV2.pkg', { recursive: true, force: true });
5156

5257
} else {
5358
// This covers arm arch + Homebrew is not installed
@@ -67,24 +72,26 @@ softwareupdate --install-rosetta
6772
}
6873

6974
override async destroy(): Promise<void> {
75+
const $ = getPty();
76+
7077
const installLocation = await this.findInstallLocation();
7178
if (!installLocation) {
7279
return;
7380
}
7481

7582
if (installLocation.includes('homebrew')) {
76-
await codifySpawn('brew uninstall awscli');
83+
await $.spawn('brew uninstall awscli', { interactive: true, env: { HOMEBREW_NO_AUTO_UPDATE: 1 } });
7784
return;
7885
}
7986

80-
await codifySpawn(`rm ${installLocation}`, { requiresRoot: true });
81-
await codifySpawn(`rm ${installLocation}_completer`, { requiresRoot: true });
82-
await codifySpawn('rm -rf /usr/local/aws-cli', { requiresRoot: true });
83-
await codifySpawn('rm -rf $HOME/.aws/', { requiresRoot: true });
87+
await $.spawn(`rm ${installLocation}`, { requiresRoot: true });
88+
await $.spawn(`rm ${installLocation}_completer`, { requiresRoot: true });
89+
await $.spawn('rm -rf $HOME/.aws/');
8490
}
8591

8692
private async findInstallLocation(): Promise<null | string> {
87-
const query = await codifySpawn('which aws', { throws: false });
93+
const $ = getPty();
94+
const query = await $.spawnSafe('which aws', { interactive: true });
8895
if (query.status === SpawnStatus.ERROR) {
8996
return null;
9097
}

src/resources/aws-cli/profile/aws-profile.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import {
22
CreatePlan,
33
DestroyPlan,
4-
getPty,
54
ModifyPlan,
65
ParameterChange,
76
Resource,
8-
ResourceSettings
7+
ResourceSettings,
8+
SpawnStatus,
9+
getPty
910
} from 'codify-plugin-lib';
10-
import { StringIndexedObject } from 'codify-schemas';
11+
import { OS, StringIndexedObject } from 'codify-schemas';
1112
import * as fs from 'node:fs/promises';
1213
import os from 'node:os';
1314
import path from 'node:path';
1415

15-
import { SpawnStatus, codifySpawn } from '../../../utils/codify-spawn.js';
1616
import Schema from './aws-profile-schema.json'
1717
import { CSVCredentialsTransformation } from './csv-credentials-transformation.js';
1818

@@ -32,6 +32,7 @@ export class AwsProfileResource extends Resource<AwsProfileConfig> {
3232
getSettings(): ResourceSettings<AwsProfileConfig> {
3333
return {
3434
id: 'aws-profile',
35+
operatingSystems: [OS.Darwin, OS.Linux],
3536
dependencies: ['aws-cli'],
3637
schema: Schema,
3738
parameterSettings: {
@@ -127,8 +128,10 @@ export class AwsProfileResource extends Resource<AwsProfileConfig> {
127128
}
128129

129130
override async create(plan: CreatePlan<AwsProfileConfig>): Promise<void> {
131+
const $ = getPty();
132+
130133
// Assert that aws-cli is installed
131-
await codifySpawn('which aws')
134+
await $.spawn('which aws', { interactive: true })
132135

133136
const {
134137
awsAccessKeyId,
@@ -190,7 +193,7 @@ export class AwsProfileResource extends Resource<AwsProfileConfig> {
190193
private async getAwsConfigureValueOrNull(key: string, profile: string): Promise<string | undefined> {
191194
const $ = getPty();
192195

193-
const { data, status } = await $.spawnSafe(`aws configure get ${key} --profile ${profile}`);
196+
const { data, status } = await $.spawnSafe(`aws configure get ${key} --profile ${profile}`, { interactive: true });
194197
if (status === SpawnStatus.ERROR) {
195198
return undefined;
196199
}
@@ -199,6 +202,7 @@ export class AwsProfileResource extends Resource<AwsProfileConfig> {
199202
}
200203

201204
private async setAwsConfigureValue(key: string, value: number | string, profile: string): Promise<void> {
202-
await codifySpawn(`aws configure set ${key} ${value} --profile ${profile}`);
205+
const $ = getPty();
206+
await $.spawn(`aws configure set ${key} ${value} --profile ${profile}`, { interactive: true });
203207
}
204208
}

src/resources/aws-cli/profile/csv-credentials-transformation.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { type InputTransformation } from 'codify-plugin-lib';
1+
import { type InputTransformation, untildify } from 'codify-plugin-lib';
22
import * as fsSync from 'node:fs';
33
import * as fs from 'node:fs/promises';
44
import path from 'node:path';
55

6-
import { untildify } from '../../../utils/untildify.js';
76
import { AwsProfileConfig } from './aws-profile.js';
87

98
export const CSVCredentialsTransformation: InputTransformation = {

0 commit comments

Comments
 (0)