Skip to content

Repo sync #519

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

Closed
wants to merge 9 commits into from
Closed
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
139 changes: 66 additions & 73 deletions .github/actions/copy-cloud-docs-for-tfe/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ export async function main(

//Read version metadata and get the latest version of terraform-enterprise
const versionMetadataPath = path.resolve(
'./release/app/api/versionMetadata.json',
path.join(sourcePath, 'app/api/versionMetadata.json'),
)

const versionMetadata = JSON.parse(
fs.readFileSync(versionMetadataPath, 'utf8'),
)
Expand Down Expand Up @@ -151,7 +152,7 @@ export async function main(
fs.mkdirSync(newTFEVersionDir, { recursive: true })

const prevTFEVersionDir = path.join(
targetPath,
sourcePath,
'content/terraform-enterprise',
currentTfeRelease,
)
Expand All @@ -171,74 +172,6 @@ export async function main(
items = items.concat(docItems)
}

// process each mdx file
for (const item of items) {
// ignore some files
if (
IGNORE_LIST.some((ignore: string) => {
return item.path.endsWith(ignore)
})
) {
continue
}

// extract mdx content; ignore frontmatter
const fullContent = fs.readFileSync(item.path, 'utf8')

// eslint-disable-next-line prefer-const
let { content, data } = matter(fullContent)

data = transformObject(data, [
// inject `source` frontmatter property
function injectSource(d: { [key: string]: any }) {
d.source = path.basename(HCPsourceDir)
return d
},
// replace cloud instances with enterprise
function replaceCloudWithEnterprise(d: { [key: string]: any }) {
// Some docs do not have all frontmatter properties. Make sure
// we do not assign `undefined` (which is invalid) in YAML
if (d.page_title) {
d.page_title = d.page_title.replace(
'Terraform Cloud',
'Terraform Enterprise',
)
d.page_title = d.page_title.replace(
'HCP Terraform',
'Terraform Enterprise',
)
}

if (d.description) {
d.description = d.description.replace(
'Terraform Cloud',
'Terraform Enterprise',
)
d.description = d.description.replace(
'HCP Terraform',
'Terraform Enterprise',
)
}
return d
},
])

const vfile = await remark()
.use(remarkMdx)
// @ts-expect-error remark is being passed in through the pipeline
.use(remarkGetImages, HCPsourceDir, imageSrcSet)
// @ts-expect-error remark is being passed in through the pipeline
.use(remarkTransformCloudDocsLinks)
.process(content)

// replace \-> with ->
const stringOutput = vfile.toString().replaceAll('\\->', '->')

// overwrite original file with transformed content
const contents = matter.stringify('\n' + stringOutput, data)
fs.writeFileSync(item.path, contents)
}

// Copy an entire directory
// ---------------------------------------------
// /{source}/cloud-docs/dir/some-doc.mdx
Expand All @@ -264,9 +197,69 @@ export async function main(
continue
}

const destAbsolutePath = item.path.replace(src, dest)
fs.mkdirSync(path.dirname(destAbsolutePath), { recursive: true })
fs.copyFileSync(item.path, destAbsolutePath)
// extract mdx content; ignore frontmatter
const fullContent = fs.readFileSync(item.path, 'utf8')

// eslint-disable-next-line prefer-const
let { content, data } = matter(fullContent)

data = transformObject(data, [
// inject `source` frontmatter property
function injectSource(d: { [key: string]: any }) {
d.source = path.basename(HCPsourceDir)
return d
},
// replace cloud instances with enterprise
function replaceCloudWithEnterprise(d: { [key: string]: any }) {
// Some docs do not have all frontmatter properties. Make sure
// we do not assign `undefined` (which is invalid) in YAML
if (d.page_title) {
d.page_title = d.page_title.replace(
'Terraform Cloud',
'Terraform Enterprise',
)
d.page_title = d.page_title.replace(
'HCP Terraform',
'Terraform Enterprise',
)
}

if (d.description) {
d.description = d.description.replace(
'Terraform Cloud',
'Terraform Enterprise',
)
d.description = d.description.replace(
'HCP Terraform',
'Terraform Enterprise',
)
}
return d
},
])

const vfile = await remark()
.use(remarkMdx)
// @ts-expect-error remark is being passed in through the pipeline
.use(remarkGetImages, HCPsourceDir, imageSrcSet)
// @ts-expect-error remark is being passed in through the pipeline
.use(remarkTransformCloudDocsLinks)
.process(content)

// replace \-> with ->
const stringOutput = vfile.toString().replaceAll('\\->', '->')

// overwrite original file with transformed content
const contents = matter.stringify('\n' + stringOutput, data)

// Get the relative path after "terraform-docs-common/docs/cloud-docs"
const relPath = path.relative(
path.join(HCPContentDir, 'cloud-docs'),
item.path,
)

const destAbsolutePath = path.join(dest, relPath)
fs.writeFileSync(destAbsolutePath, contents)
}
}

Expand Down
130 changes: 60 additions & 70 deletions .github/actions/copy-cloud-docs-for-tfe/out/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130465,7 +130465,7 @@ Please specify the "importAttributesKeyword" generator option, whose value can b
const prType = newTFEVersion ? PR_TYPE.NewVersion : PR_TYPE.Diff
//Read version metadata and get the latest version of terraform-enterprise
const versionMetadataPath = external_path_.resolve(
'./release/app/api/versionMetadata.json',
external_path_.join(sourcePath, 'app/api/versionMetadata.json'),
)
const versionMetadata = JSON.parse(
external_fs_.readFileSync(versionMetadataPath, 'utf8'),
Expand Down Expand Up @@ -130510,7 +130510,7 @@ Please specify the "importAttributesKeyword" generator option, whose value can b
core.info(`Creating new version directory: ${newTFEVersionDir}`)
external_fs_.mkdirSync(newTFEVersionDir, { recursive: true })
const prevTFEVersionDir = external_path_.join(
targetPath,
sourcePath,
'content/terraform-enterprise',
currentTfeRelease,
)
Expand All @@ -130528,69 +130528,6 @@ Please specify the "importAttributesKeyword" generator option, whose value can b
})
items = items.concat(docItems)
}
// process each mdx file
for (const item of items) {
// ignore some files
if (
IGNORE_LIST.some((ignore) => {
return item.path.endsWith(ignore)
})
) {
continue
}
// extract mdx content; ignore frontmatter
const fullContent = external_fs_.readFileSync(item.path, 'utf8')
// eslint-disable-next-line prefer-const
let { content, data } = gray_matter_default()(fullContent)
data = transformObject(data, [
// inject `source` frontmatter property
function injectSource(d) {
d.source = external_path_.basename(HCPsourceDir)
return d
},
// replace cloud instances with enterprise
function replaceCloudWithEnterprise(d) {
// Some docs do not have all frontmatter properties. Make sure
// we do not assign `undefined` (which is invalid) in YAML
if (d.page_title) {
d.page_title = d.page_title.replace(
'Terraform Cloud',
'Terraform Enterprise',
)
d.page_title = d.page_title.replace(
'HCP Terraform',
'Terraform Enterprise',
)
}
if (d.description) {
d.description = d.description.replace(
'Terraform Cloud',
'Terraform Enterprise',
)
d.description = d.description.replace(
'HCP Terraform',
'Terraform Enterprise',
)
}
return d
},
])
const vfile = await remark_default()()
.use(remark_mdx_default())
// @ts-expect-error remark is being passed in through the pipeline
.use(remarkGetImages, HCPsourceDir, imageSrcSet)
// @ts-expect-error remark is being passed in through the pipeline
.use(remarkTransformCloudDocsLinks)
.process(content)
// replace \-> with ->
const stringOutput = vfile.toString().replaceAll('\\->', '->')
// overwrite original file with transformed content
const contents = gray_matter_default().stringify(
'\n' + stringOutput,
data,
)
external_fs_.writeFileSync(item.path, contents)
}
// Copy an entire directory
// ---------------------------------------------
// /{source}/cloud-docs/dir/some-doc.mdx
Expand All @@ -130613,11 +130550,64 @@ Please specify the "importAttributesKeyword" generator option, whose value can b
) {
continue
}
const destAbsolutePath = item.path.replace(src, dest)
external_fs_.mkdirSync(external_path_.dirname(destAbsolutePath), {
recursive: true,
})
external_fs_.copyFileSync(item.path, destAbsolutePath)
// extract mdx content; ignore frontmatter
const fullContent = external_fs_.readFileSync(item.path, 'utf8')
// eslint-disable-next-line prefer-const
let { content, data } = gray_matter_default()(fullContent)
data = transformObject(data, [
// inject `source` frontmatter property
function injectSource(d) {
d.source = external_path_.basename(HCPsourceDir)
return d
},
// replace cloud instances with enterprise
function replaceCloudWithEnterprise(d) {
// Some docs do not have all frontmatter properties. Make sure
// we do not assign `undefined` (which is invalid) in YAML
if (d.page_title) {
d.page_title = d.page_title.replace(
'Terraform Cloud',
'Terraform Enterprise',
)
d.page_title = d.page_title.replace(
'HCP Terraform',
'Terraform Enterprise',
)
}
if (d.description) {
d.description = d.description.replace(
'Terraform Cloud',
'Terraform Enterprise',
)
d.description = d.description.replace(
'HCP Terraform',
'Terraform Enterprise',
)
}
return d
},
])
const vfile = await remark_default()()
.use(remark_mdx_default())
// @ts-expect-error remark is being passed in through the pipeline
.use(remarkGetImages, HCPsourceDir, imageSrcSet)
// @ts-expect-error remark is being passed in through the pipeline
.use(remarkTransformCloudDocsLinks)
.process(content)
// replace \-> with ->
const stringOutput = vfile.toString().replaceAll('\\->', '->')
// overwrite original file with transformed content
const contents = gray_matter_default().stringify(
'\n' + stringOutput,
data,
)
// Get the relative path after "terraform-docs-common/docs/cloud-docs"
const relPath = external_path_.relative(
external_path_.join(HCPContentDir, 'cloud-docs'),
item.path,
)
const destAbsolutePath = external_path_.join(dest, relPath)
external_fs_.writeFileSync(destAbsolutePath, contents)
}
}
// Copy images
Expand Down
Loading
Loading