Skip to content
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

chore: run prettier #256

Merged
merged 1 commit into from
Dec 21, 2023
Merged
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
16 changes: 8 additions & 8 deletions .github/lib/collect-changes.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ module.exports = async ({ core, exec }) => {
const { before, after } = await getBeforeAndAfterFiles(
exec,
providerDirectory,
".projenrc.js"
".projenrc.js",
);
const { before: beforeVersion, after: afterVersion } =
await getBeforeAndAfterFiles(
exec,
providerDirectory,
path.join("src", "version.json"),
true
true,
);
const providerVersions = {
before: before[Object.keys(beforeVersion)[0]],
Expand Down Expand Up @@ -96,11 +96,11 @@ module.exports = async ({ core, exec }) => {
}));

const hasBreakingChanges = [...results, ...providerNameChanged].some(
(res) => res.breaking
(res) => res.breaking,
);

console.log(
hasBreakingChanges ? "Found breaking changes!" : "No breaking changes."
hasBreakingChanges ? "Found breaking changes!" : "No breaking changes.",
);

let prefix = `chore(deps)${hasBreakingChanges ? "!" : ""}: update `;
Expand All @@ -112,7 +112,7 @@ module.exports = async ({ core, exec }) => {
console.log(
`${res.key}: ${res.before} => ${res.after} (${
res.breaking ? "breaking" : "non-breaking"
})`
})`,
);

if (res.before === res.after) {
Expand Down Expand Up @@ -149,13 +149,13 @@ module.exports = async ({ core, exec }) => {

if (providerNameChanged.before !== providerNameChanged.after) {
commitMessageParts.push(
`provider name to \`${providerNameChanged.after}\``
`provider name to \`${providerNameChanged.after}\``,
);
}

if (providerVersions.before !== providerVersions.after) {
commitMessageParts.push(
`provider version to \`${providerVersions.after}\``
`provider version to \`${providerVersions.after}\``,
);
}

Expand All @@ -182,6 +182,6 @@ module.exports = async ({ core, exec }) => {

core.setOutput(
"commit_message",
`${prefix} ${commitMessageParts.join(", ")}`.trim()
`${prefix} ${commitMessageParts.join(", ")}`.trim(),
);
};
6 changes: 3 additions & 3 deletions .github/lib/copy-codeowners-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = () => {
const mainFolder = path.join(process.env.GITHUB_WORKSPACE, "main");
const codeownersFile = fs.readFileSync(
path.join(mainFolder, ".github", "CODEOWNERS"),
"utf-8"
"utf-8",
);

fs.mkdirSync(path.join(process.env.GITHUB_WORKSPACE, "provider", ".github"), {
Expand All @@ -21,8 +21,8 @@ module.exports = () => {
process.env.GITHUB_WORKSPACE,
"provider",
".github",
"CODEOWNERS"
"CODEOWNERS",
),
codeownersFile
codeownersFile,
);
};
11 changes: 5 additions & 6 deletions .github/lib/create-projen-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@ module.exports = ({ providerName }) => {
const mainFolder = path.join(process.env.GITHUB_WORKSPACE, "main");
const provider = require(path.join(mainFolder, "provider.json"));
const providerVersion = provider[providerName];
const providersWithCustomRunners = require(path.join(
mainFolder,
"providersWithCustomRunners.json"
));
const providersWithCustomRunners = require(
path.join(mainFolder, "providersWithCustomRunners.json"),
);
const useCustomGithubRunner =
providersWithCustomRunners.includes(providerName);
const template = fs.readFileSync(
path.join(mainFolder, "projenrc.template.js"),
"utf-8"
"utf-8",
);
const projenrc = template
.replace("__PROVIDER__", providerVersion)
.replace("__CUSTOM_RUNNER__", useCustomGithubRunner);
fs.writeFileSync(
path.join(process.env.GITHUB_WORKSPACE, "provider", ".projenrc.js"),
projenrc
projenrc,
);
};
22 changes: 11 additions & 11 deletions lib/secrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ export class SecretFromVariable extends Construct {

public for(
repository: Repository | DataGithubRepository,
ghProvider: GithubProvider
ghProvider: GithubProvider,
) {
const secret = setOldId(
new ActionsSecret(repository, `secret-${this.name}`, {
plaintextValue: this.variable.value,
secretName: constantCase(this.name),
repository: repository.name,
provider: ghProvider,
})
}),
);

this.secretNames.forEach((name) => {
Expand All @@ -54,7 +54,7 @@ export class SecretFromVariable extends Construct {
secretName: constantCase(name),
repository: repository.name,
provider: ghProvider,
})
}),
);
});

Expand Down Expand Up @@ -98,15 +98,15 @@ export class PublishingSecretSet extends Construct {

public forAllLanguages(
repository: Repository | DataGithubRepository,
ghProvider: GithubProvider
ghProvider: GithubProvider,
) {
this.secrets.forEach((secret) => secret.for(repository, ghProvider));
}

private forPrefixedSecrets(
repository: Repository | DataGithubRepository,
ghProvider: GithubProvider,
prefix: string
prefix: string,
) {
this.secrets
.filter((secret) => secret.name.startsWith(prefix))
Expand All @@ -115,35 +115,35 @@ export class PublishingSecretSet extends Construct {

public forGitHub(
repository: Repository | DataGithubRepository,
ghProvider: GithubProvider
ghProvider: GithubProvider,
) {
this.forPrefixedSecrets(repository, ghProvider, "gh-");
}

public forTypescript(
repository: Repository | DataGithubRepository,
ghProvider: GithubProvider
ghProvider: GithubProvider,
) {
this.forPrefixedSecrets(repository, ghProvider, "npm-");
}

public forPython(
repository: Repository | DataGithubRepository,
ghProvider: GithubProvider
ghProvider: GithubProvider,
) {
this.forPrefixedSecrets(repository, ghProvider, "twine-");
}

public forCsharp(
repository: Repository | DataGithubRepository,
ghProvider: GithubProvider
ghProvider: GithubProvider,
) {
this.forPrefixedSecrets(repository, ghProvider, "nuget-");
}

public forJava(
repository: Repository | DataGithubRepository,
ghProvider: GithubProvider
ghProvider: GithubProvider,
) {
this.forPrefixedSecrets(repository, ghProvider, "maven-");
}
Expand All @@ -152,7 +152,7 @@ export class PublishingSecretSet extends Construct {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_repository: Repository | DataGithubRepository,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_ghProvider: GithubProvider
_ghProvider: GithubProvider,
) {
// No additional go secrets required, this method exists for consistency
}
Expand Down
2 changes: 1 addition & 1 deletion lib/unique-id-override.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function makeUniqueId(components: string[], allowSepChars: boolean) {

if (components.length === 0) {
throw new Error(
"Unable to calculate a unique id for an empty set of components"
"Unable to calculate a unique id for an empty set of components",
);
}

Expand Down
48 changes: 24 additions & 24 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ type StackShards = {
};

const allProviders: Record<string, string> = JSON.parse(
fs.readFileSync(path.join(__dirname, "provider.json"), "utf8")
fs.readFileSync(path.join(__dirname, "provider.json"), "utf8"),
);

const shardedStacks: StackShards = JSON.parse(
fs.readFileSync(path.join(__dirname, "sharded-stacks.json"), "utf8")
fs.readFileSync(path.join(__dirname, "sharded-stacks.json"), "utf8"),
);

interface GitUrls {
Expand All @@ -60,8 +60,8 @@ function getShardedStackProviders(name: string): Record<string, string> {

return Object.fromEntries(
Object.entries(allProviders).filter(([key]) =>
stackProvidersList.includes(key)
)
stackProvidersList.includes(key),
),
);
}

Expand Down Expand Up @@ -100,13 +100,13 @@ class TerraformCdkProviderStack extends TerraformStack {
this.createRepositoryManagerRepo(
slackWebhook,
githubProvider,
githubTeam
githubTeam,
);
this.createProviderProjectRepo(
slackWebhook,
secrets.npmSecret,
githubProvider,
githubTeam
githubTeam,
);
}

Expand Down Expand Up @@ -157,7 +157,7 @@ class TerraformCdkProviderStack extends TerraformStack {
slackWebhook: TerraformVariable,
npmSecret: SecretFromVariable,
githubProvider: GithubProvider,
githubTeam: DataGithubTeam
githubTeam: DataGithubTeam,
) {
const templateRepository = new GithubRepository(
this,
Expand All @@ -166,7 +166,7 @@ class TerraformCdkProviderStack extends TerraformStack {
team: githubTeam,
webhookUrl: slackWebhook.stringValue,
provider: githubProvider,
}
},
);

npmSecret.for(templateRepository.resource, githubProvider);
Expand All @@ -179,7 +179,7 @@ class TerraformCdkProviderStack extends TerraformStack {
private createRepositoryManagerRepo(
slackWebhook: TerraformVariable,
githubProvider: GithubProvider,
githubTeam: DataGithubTeam
githubTeam: DataGithubTeam,
) {
const selfTokens = [
new SecretFromVariable(this, "tf-cloud-token"),
Expand All @@ -202,13 +202,13 @@ class TerraformCdkProviderStack extends TerraformStack {
private validateProviderNames(providers: Record<string, string>) {
// validate that providers contain only valid names (-go suffix is forbidden)
const goSuffixProviders = Object.keys(providers).filter((key) =>
key.endsWith("-go")
key.endsWith("-go"),
);
if (goSuffixProviders.length > 0) {
Annotations.of(this).addError(
`Providers contain a provider key with a suffix -go which is not allowed due to conflicts with go package repositories. Please remove the -go suffix from these provider keys ${goSuffixProviders.join(
", "
)}`
", ",
)}`,
);
}

Expand All @@ -222,13 +222,13 @@ class TerraformCdkProviderStack extends TerraformStack {

const sanitizedProviderName = providerName.replace(/-/g, "");
return key !== sanitizedProviderName;
}
},
);
if (notMatchingProviders.length > 0) {
Annotations.of(this).addError(
`Provider name and provider key do not match for ${notMatchingProviders.join(
", "
)}. This leads to issues when deploying go packages. Please rename the provider key to match the provider name.`
", ",
)}. This leads to issues when deploying go packages. Please rename the provider key to match the provider name.`,
);
}
}
Expand All @@ -242,7 +242,7 @@ class CustomConstructsStack extends TerraformStack {
name: string;
languages: ("typescript" | "python" | "csharp" | "java" | "go")[];
topics?: string[];
}[]
}[],
) {
super(scope, name);
const githubProvider = new GithubProvider(this, "github-provider-cdktf", {
Expand Down Expand Up @@ -275,10 +275,10 @@ class CustomConstructsStack extends TerraformStack {
language === "typescript"
? "js"
: language === "csharp"
? "dotnet"
: language
? "dotnet"
: language
}`;
})
}),
);

const repo = new GithubRepositoryFromExistingRepository(
Expand All @@ -291,7 +291,7 @@ class CustomConstructsStack extends TerraformStack {
provider: githubProvider,
protectMain: true,
protectMainChecks,
}
},
);

secrets.forGitHub(repo.resource, githubProvider);
Expand Down Expand Up @@ -337,10 +337,10 @@ const allProviderNames = Object.keys(allProviders);
const shardProviderSet = new Set(allProvidersInShards);
const allProviderSet = new Set(allProviderNames);
const missingProvidersInShards = new Set(
[...allProviderSet].filter((provider) => !shardProviderSet.has(provider))
[...allProviderSet].filter((provider) => !shardProviderSet.has(provider)),
);
const missingProvidersInAllProviders = new Set(
[...shardProviderSet].filter((provider) => !allProviderSet.has(provider))
[...shardProviderSet].filter((provider) => !allProviderSet.has(provider)),
);

if (shardProviderSet.size < allProvidersInShards.length) {
Expand All @@ -351,15 +351,15 @@ if (missingProvidersInShards.size > 0) {
throw new Error(
`One or more providers present in provider.json are missing in sharded-stacks.json: ${[
...missingProvidersInShards,
]}`
]}`,
);
}

if (missingProvidersInAllProviders.size > 0) {
throw new Error(
`One or more providers present in sharded-stacks.json are missing in provider.json: ${[
...missingProvidersInAllProviders,
]}`
]}`,
);
}

Expand Down
Loading