Skip to content

Commit

Permalink
support generic platform keys with YML
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettCleary committed Mar 11, 2024
1 parent 18968a9 commit e25dea8
Show file tree
Hide file tree
Showing 12 changed files with 254 additions and 99 deletions.
10 changes: 0 additions & 10 deletions hyperplay.yml

This file was deleted.

93 changes: 33 additions & 60 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"dependencies": {
"@oclif/core": "^1.8.0",
"@oclif/plugin-help": "^5",
"@valist/sdk": "^2.9.3",
"@valist/sdk": "file:../../valist-io/valist-js/packages/valist-sdk",
"archiver": "^7.0.0",
"axios": "^1.6.7",
"axios-cookiejar-support": "^5.0.0",
Expand Down
41 changes: 15 additions & 26 deletions src/commands/publish.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Command, CliUx } from '@oclif/core';
import { ethers } from 'ethers';
import { create, ReleaseConfig, SupportedPlatform } from '@valist/sdk';
import YAML from 'yaml';
import * as fs from 'node:fs';
import { create } from '@valist/sdk';
import * as flags from '../flags';
import { select } from '../keys';
import { CookieJar } from 'tough-cookie';
import axios from 'axios';
import { wrapper } from 'axios-cookiejar-support';
import { loginAndPublish } from '../api';
import { uploadRelease } from '../releases';
import { parseYml } from '../yml';
import { FlagOutput } from '@oclif/core/lib/interfaces';

export default class Publish extends Command {
static provider?: ethers.Signer;
Expand All @@ -31,7 +31,9 @@ export default class Publish extends Command {
'darwin_arm64': flags.darwin_arm64,
'windows_amd64': flags.windows_amd64,
'skip_hyperplay_publish': flags.skip_hyperplay_publish,
'channel': flags.channel
'channel': flags.channel,
'useYml': flags.useYml,
'ymlPath': flags.ymlPath
}

static args = [
Expand Down Expand Up @@ -59,39 +61,26 @@ export default class Publish extends Command {
return new ethers.Wallet(privateKey, provider);
}

async parseConfig(){
// ts having issues passing these as args so duplicating the parse here
const { args, flags } = await this.parse(Publish);

let config: ReleaseConfig;
if (args.account && args.project && args.release) {
config = new ReleaseConfig(args.account, args.project, args.release);
const platformFlags: SupportedPlatform[] = ["web", "darwin_amd64", "darwin_arm64", "linux_amd64", "linux_arm64", "windows_amd64", "windows_arm64", "android_arm64"]
for (const platform of platformFlags){
if (flags[platform])
config.platforms[platform] = flags[platform]
}

} else if(fs.existsSync('hyperplay.yml')){
const data = fs.readFileSync('hyperplay.yml', 'utf8');
config = YAML.parse(data);
}
else {
/* eslint-disable-next-line */
async parseConfig(args: {[name: string]: any;}, flags: FlagOutput){
const parsed = parseYml(args, flags)
if (parsed === undefined){
this.error('Account, project, and release were not supplied and hyperplay.yml does not exist')
}

const {config, yamlConfig} = parsed;
if (!config.account) this.error('invalid account name');
if (!config.project) this.error('invalid project name');
if (!config.release) this.error('invalid release name');
if (!config.platforms) this.error('no platforms configured');

return config
return {config, yamlConfig}
}

// if no args are passed, use the yml
public async run(): Promise<void> {
const { flags } = await this.parse(Publish);
const config = await this.parseConfig()
const { args, flags } = await this.parse(Publish);
const {config, yamlConfig} = await this.parseConfig(args, flags)

const fullReleaseName = `${config.account}/${config.project}/${config.release}`;
console.log('Publishing', { platforms: config.platforms }, `as ${fullReleaseName}`);
Expand Down Expand Up @@ -125,7 +114,7 @@ export default class Publish extends Command {
}

CliUx.ux.action.start('uploading files');
const release = await uploadRelease(valist, config);
const release = await uploadRelease(valist, config, yamlConfig);
CliUx.ux.action.stop();
CliUx.ux.log(`successfully uploaded files to IPFS: ${release.external_url}`);

Expand Down
12 changes: 12 additions & 0 deletions src/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,15 @@ export const channel = Flags.string({
default: 'main',
env: 'HYPERPLAY_TARGET_CHANNEL'
});

export const useYml = Flags.boolean({
description: 'Use hyperplay.yml to get platform config',
default: false,
env: 'HYPERPLAY_USE_YML'
})

export const ymlPath = Flags.string({
description: 'Path to yml file containing publish args',
default: '',
env: 'HYPERPLAY_YML_PATH'
})
6 changes: 5 additions & 1 deletion src/releases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ import { PlatformsMetaInterface } from '@valist/sdk/dist/typesShared';
import fs from 'fs';
import path from 'path';
import { zipDirectory } from './zip';
import { YamlConfig } from './types';

export async function uploadRelease(valist: Client, config: ReleaseConfig) {
export async function uploadRelease(valist: Client, config: ReleaseConfig, yamlConfig?: YamlConfig) {
/* eslint-disable-next-line */
const platformEntries = Object.entries(config.platforms).filter(([_key, value]) => value !== "");

const updatedPlatformEntries = await Promise.all(platformEntries.map(async ([platform, filePath]) => {
if (yamlConfig && yamlConfig.platforms[platform] && !yamlConfig.platforms[platform].zip) {
return [platform, filePath]
}
const zipPath = `./${path.basename(filePath)}.zip`;
await zipDirectory(filePath, zipPath);
return [platform, zipPath] as [string, string];
Expand Down
11 changes: 11 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface PlatformYamlConfig {
path: string,
zip: boolean
}

export interface YamlConfig {
account: string,
project: string,
release: string,
platforms: Record<string, PlatformYamlConfig>
}
51 changes: 51 additions & 0 deletions src/yml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { ReleaseConfig, SupportedPlatform } from "@valist/sdk";
import { YamlConfig } from "./types";
import fs from 'fs';
import YAML from 'yaml';
import { FlagOutput } from "@oclif/core/lib/interfaces";

/* eslint-disable-next-line */
export function parseYml(args: {[name: string]: any;}, flags: FlagOutput): {config: ReleaseConfig, yamlConfig: YamlConfig | undefined} | undefined{
let config: ReleaseConfig;
let yamlConfig: YamlConfig | undefined = undefined;
const flagPath = flags['ymlPath']
const ymlPath = flagPath ? flagPath : 'hyperplay.yml'
// cli args and flags
if (args.account && args.project && args.release && !flags['useYml']) {
config = new ReleaseConfig(args.account, args.project, args.release);
const platformFlags: SupportedPlatform[] = ["web", "darwin_amd64", "darwin_arm64", "linux_amd64", "linux_arm64", "windows_amd64", "windows_arm64", "android_arm64"]
for (const platform of platformFlags){
if (flags[platform])
config.platforms[platform] = flags[platform]
}

// using hyperplay.yml
} else if(fs.existsSync(ymlPath)){
const data = fs.readFileSync(ymlPath, 'utf8');
yamlConfig = YAML.parse(data);

const configPlatforms: Record<string, string> = {}
for (const [key, value] of Object.entries(yamlConfig!.platforms)){
configPlatforms[key] = value.path
}
if (yamlConfig === undefined){
return undefined
}
config = {...yamlConfig, platforms: configPlatforms}

// override yaml if cli args are passed for acct, project, or release
if (args.account) {
config.account = args.account
}
if (args.project) {
config.project = args.project
}
if (args.release) {
config.release = args.release
}
}
else {
return undefined
}
return {config, yamlConfig}
}
3 changes: 2 additions & 1 deletion test/commands/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ describe('publish CLI command', () => {
it('should create a release with the publish command and the hyperplay.yml file', async function () {
const publishArgs = [
'--private-key=4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d',
'--no-meta-tx'
'--no-meta-tx',
'--ymlPath=./test/mock_data/hyperplay.yml'
]
await runPublishCommandWithMockData('v0.0.2', publishArgs)
});
Expand Down
19 changes: 19 additions & 0 deletions test/mock_data/hyperplay.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This is just used for testing
account: valist
project: cli
release: v0.0.2

platforms:
darwin_amd64:
path: ./mock_data/mac_x64
zip: true
darwin_arm64:
path: ./mock_data/mac_arm64
zip: true
windows_amd64:
path: ./mock_data/windows_amd64
zip: true
web:
path: ./mock_data/web
zip: true

Loading

0 comments on commit e25dea8

Please sign in to comment.