-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOP-4248: Create action that uploads directory content to S3 #79
Conversation
@@ -2,9 +2,8 @@ | |||
"$schema": "https://json.schemastore.org/tsconfig", | |||
"compilerOptions": { | |||
"target": "ES2022", | |||
"module": "NodeNext", | |||
"module": "CommonJS", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was changed in order to work with this mime package for node
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. I just put annoying comments 🤭
src/publish-build/index.ts
Outdated
core.error(errMsg); | ||
throw new Error(errMsg); | ||
} | ||
res[requiredVar] = process.env[requiredVar] ?? ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I wonder if this nullish coalescer is necessary because it would have thrown an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a way that this can be done without running into TS errors. There are a few more moving parts, but this should make TypeScript happy. I added some explanations, but if I can clarify something more let me know!!
const REQUIRED_ENV_VARS = [
'AWS_BUCKET',
'PROJECT',
'SOURCE_DIR',
'DESTINATION_DIR',
'COMMIT_HASH',
'GITHUB_WORKSPACE',
] as const;
// translates the array of values in REQUIRED_ENV_VARS into a literal type i.e. RequiredVar = 'AWS_BUCKET' | 'PROJECT' ....
type RequiredVar = (typeof REQUIRED_ENV_VARS)[number];
// We can then use this literal type to create an object definition. Have to use a type here instead of an interface
// as interfaces don't support mapped types very well :/
// This boils down to the same intreface, but with the added benefit of being able to assign these string values to the object in
// the getEnvVars function. If this is not done, TypeScript sees a string versus a key within the `envParams` type. Because of this,
// an error will occur if you try assigning a value to the envParams object.
type envParams = {
[V in RequiredVar]: string;
};
function getEnvVars(): envParams {
const res: Partial<envParams> = {};
for (const requiredVar of REQUIRED_ENV_VARS) {
const envVar = process.env[requiredVar];
if (!envVar) {
const errMsg = `Required env variable missing: ${requiredVar}`;
core.error(errMsg);
throw new Error(errMsg);
}
res[requiredVar] = envVar;
}
return res as envParams;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
omg grosssss typescript!! 😭 @branberry you right, you always right!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lol, I wish I was always right... I've just had to do this so many times already hahaha. I've been wallowing in the murky TypeScript underbelly for far too long...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this part was throwing an error so i updated it to be a type Record<RequiredVar, string>;
type envParams = {
[var in RequiredVar]: string;
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, the issue is that var
is a JavaScript keyword.. If you use something like V
instead of var
the error goes away.
But, I prefer the Record
as that is more readable
src/publish-build/index.ts
Outdated
} | ||
|
||
function getEnvVars(): envParams { | ||
const res: { [key: string]: string } = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this type be Partial<envParams>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
src/publish-build/index.ts
Outdated
'GITHUB_WORKSPACE', | ||
]; | ||
|
||
interface envParams { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit of nits: I believe the convention is to capitalize interface names
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
This PR exposes a github action that uploads a directory (and its contents) to a specified AWS S3 bucket (and path).
Front end workflow that uses this action is found here
Test Deploy of this action