Skip to content
This repository has been archived by the owner on Jul 14, 2020. It is now read-only.

[WIP] Update to use {automation-client,sdm,sdm-core} 2.0 branches #32

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions lib/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@
* limitations under the License.
*/

import { doWithRetry } from "@atomist/automation-client";
import {
CacheConfiguration,
GoalInvocation,
} from "@atomist/sdm";
import { GoalCacheArchiveStore } from "@atomist/sdm-core";
import {doWithRetry} from "@atomist/automation-client/lib/util/retry";
import {GoalCacheArchiveStore} from "@atomist/sdm-core/lib/goal/cache/CompressingGoalCache";
import {GoalInvocation} from "@atomist/sdm/lib/api/goal/GoalInvocation";
import {CacheConfiguration} from "@atomist/sdm/lib/api/machine/SoftwareDeliveryMachineOptions";
import * as AWS from "aws-sdk";
import * as fs from "fs-extra";

export interface S3CacheConfiguration extends CacheConfiguration {
cache?: {
/**
* AWS S3 bucket to perist cache entries to. If
* AWS S3 bucket to persist cache entries to. If
* not provided, it defaults to
* "sdm-WORKSPACE_ID-SDM_NAME-goal-cache", with "WORKSPACE_ID"
* replaced with your Atomist workspace ID and "SDM_NAME"
Expand Down
2 changes: 1 addition & 1 deletion lib/deleteS3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { ProgressLog } from "@atomist/sdm";
import {ProgressLog} from "@atomist/sdm/lib/spi/log/ProgressLog";
import { S3 } from "aws-sdk";
import { PublishToS3Options } from "./options";

Expand Down
2 changes: 1 addition & 1 deletion lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { GoalInvocation } from "@atomist/sdm";
import {GoalInvocation} from "@atomist/sdm/lib/api/goal/GoalInvocation";
import { GlobPatterns } from "./publishToS3";

/**
Expand Down
28 changes: 11 additions & 17 deletions lib/publishToS3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,16 @@
* limitations under the License.
*/

import {
HandlerContext,
logger,
RepoRef,
} from "@atomist/automation-client";
import {
doWithProject,
ExecuteGoal,
ExecuteGoalResult,
GoalWithFulfillment,
LogSuppressor,
PredicatedGoalDefinition,
ProjectAwareGoalInvocation,
slackWarningMessage,
SoftwareDeliveryMachine,
} from "@atomist/sdm";
import {HandlerContext} from "@atomist/automation-client/lib/HandlerContext";
import {RepoRef} from "@atomist/automation-client/lib/operations/common/RepoId";
import {logger} from "@atomist/automation-client/lib/util/logger";
import {LogSuppressor} from "@atomist/sdm/lib/api-helper/log/logInterpreters";
import {slackWarningMessage} from "@atomist/sdm/lib/api-helper/misc/slack/messages";
import {doWithProject, ProjectAwareGoalInvocation} from "@atomist/sdm/lib/api-helper/project/withProject";
import {ExecuteGoalResult} from "@atomist/sdm/lib/api/goal/ExecuteGoalResult";
import {ExecuteGoal} from "@atomist/sdm/lib/api/goal/GoalInvocation";
import {GoalWithFulfillment, PredicatedGoalDefinition} from "@atomist/sdm/lib/api/goal/GoalWithFulfillment";
import {SoftwareDeliveryMachine} from "@atomist/sdm/lib/api/machine/SoftwareDeliveryMachine";
import { SlackMessage } from "@atomist/slack-messages";
import * as AWS from "aws-sdk";
import * as proxy from "proxy-agent";
Expand All @@ -41,7 +35,7 @@ import { PublishToS3Options } from "./options";
import { putFiles } from "./putS3";

/**
* An array of fileglobs to paths within the project
* An array of file-globs to paths within the project
*/
export type GlobPatterns = string[];

Expand Down
30 changes: 15 additions & 15 deletions lib/putS3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,16 @@
* limitations under the License.
*/

import {
logger,
Project,
ProjectFile,
} from "@atomist/automation-client";
import { doWithFiles } from "@atomist/automation-client/lib/project/util/projectUtils";
import {
GoalInvocation,
ProgressLog,
} from "@atomist/sdm";
import { S3 } from "aws-sdk";
import {File} from "@atomist/automation-client/lib/project/File";
import {Project} from "@atomist/automation-client/lib/project/Project";
import {doWithFiles} from "@atomist/automation-client/lib/project/util/projectUtils";
import {logger} from "@atomist/automation-client/lib/util/logger";
import {GoalInvocation} from "@atomist/sdm/lib/api/goal/GoalInvocation";
import {ProgressLog} from "@atomist/sdm/lib/spi/log/ProgressLog";
import {S3} from "aws-sdk";
import * as mime from "mime-types";
import * as path from "path";
import { PublishToS3Options } from "./options";
import {PublishToS3Options} from "./options";

type FilesAttempted = number;
type SuccessfullyPushedKey = string;
Expand All @@ -38,12 +34,13 @@ export async function putFiles(
inv: GoalInvocation,
s3: S3,
params: PublishToS3Options): Promise<[FilesAttempted, SuccessfullyPushedKey[], Warning[]]> {
const { bucketName, filesToPublish, pathTranslation } = params;
const {bucketName, filesToPublish, pathTranslation} = params;
let fileCount = 0;
const log = inv.progressLog;
const keys: SuccessfullyPushedKey[] = [];
const warnings: Warning[] = [];
await doWithFiles(project, filesToPublish, async file => {

await doWithFiles(project, [...filesToPublish, "!**/.*", "!**/.*/**/*"], async file => {
const key = pathTranslation(file.path, inv);
const contentType = mime.lookup(file.path) || "text/plain";
const content = await file.getContentBuffer();
Expand Down Expand Up @@ -77,15 +74,18 @@ export async function putFiles(

async function gatherParamsFromCompanionFile(project: Project,
log: ProgressLog,
file: ProjectFile,
file: File,
companionFileExtension: string): Promise<[Partial<S3.Types.PutObjectRequest>, string[]]> {
const companionFilePrefix = ".";
// presume this is a normal file, and look to see if a special `.${file.name}${companionFileExtension}` file exists.
const paramsPath = path.dirname(file.path) + path.sep +
`${companionFilePrefix}${file.name}${companionFileExtension}`;
const paramsFile = await project.getFile(paramsPath);
// if no such file exists, return no extra params
if (!paramsFile) {
return [{}, []];
}
// otherwise merge params
try {
const fileParams = JSON.parse(await paramsFile.getContent());
log.write(`Merging in S3 parameters from '${paramsPath}': ${JSON.stringify(fileParams)}`);
Expand Down
Loading