From 661f43f0fd5e929b7fb57d13d2af7652d4353bca Mon Sep 17 00:00:00 2001 From: Aaron Lane Date: Thu, 12 Jun 2025 16:31:05 -0400 Subject: [PATCH 1/7] Simplify copy-cloud-docs-for-tfe to accept a version and always use main as a base --- .github/workflows/copy-cloud-docs-for-tfe.yml | 153 +++++------------- 1 file changed, 44 insertions(+), 109 deletions(-) diff --git a/.github/workflows/copy-cloud-docs-for-tfe.yml b/.github/workflows/copy-cloud-docs-for-tfe.yml index 189c18ff6..21645b904 100644 --- a/.github/workflows/copy-cloud-docs-for-tfe.yml +++ b/.github/workflows/copy-cloud-docs-for-tfe.yml @@ -3,8 +3,9 @@ name: Copy Cloud Docs For TFE on: workflow_dispatch: inputs: - branch: - description: 'Release branch. (Ex: docs-tfe-releases/v123456-1, ptfe-releases/v123456-1)' + version: + description: 'The TFE version for the upcoming TFE release, format is either vYYYYMM-# or MAJOR.MINOR.PATCH (without a "v" prefix).' + type: string required: true env: @@ -15,93 +16,39 @@ jobs: name: Copy Docs runs-on: ubuntu-latest steps: - # TODO: `exit 1` here short circuits the whole workflow, which we want, but results in - # an unnecessary `failure` status, which we don't want. - - name: Validate branch name - # ✅ docs-tfe-releases/v000011-1 - # ✅ ptfe-releases/v000011-1 - # ❌ ptfe-releases/v000011-2 - # ❌ ptfe-releases/v000011- - # ❌ ptfe-releases/v000011 - run: | - if [[ ${{ env.release_branch }} =~ ^(docs-tfe-releases|ptfe-releases)/v[0-9]{6}-1$ ]] - then - echo "::notice::Branch is valid — ${{ env.release_branch }}" - else - echo "::warning::Branch is invalid — ${{ env.release_branch }}" - exit 1 - fi - - - name: Set workspace & ref_name on env - run: | - echo "workspace=$GITHUB_WORKSPACE" >> $GITHUB_ENV - echo "ref_name=$GITHUB_REF_NAME" >> $GITHUB_ENV - - - name: Get series (YYYYMM) number from branch name - run: | - series=$(echo ${{ env.release_branch }} \ - | awk -F '/' '{print $2}' \ - | awk -F '-' '{print $1} {print $2}' \ - | head -n 1) - echo "SERIES=$series" >> $GITHUB_ENV - - name: Get release (X) number from branch name - run: | - release=$(echo ${{ env.release_branch }} \ - | awk -F '/' '{print $2}' \ - | awk -F '-' '{print $1} {print $2}' \ - | tail -n 1) - echo "RELEASE=$release" >> $GITHUB_ENV - - name: Series/Release Summary run: | echo "# Summary" >> $GITHUB_STEP_SUMMARY - echo "**Workflow ref**: ${{env.ref_name}}" >> $GITHUB_STEP_SUMMARY + echo "**Workflow ref**: ${{github.ref_name}}" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY echo "Triggered by branch creation (or manual workflow):" >> $GITHUB_STEP_SUMMARY - echo "- ${{github.server_url}}/hashicorp/${{env.target_repo}}/tree/${{env.release_branch}}" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY - echo "**Series**: ${{env.SERIES}}" >> $GITHUB_STEP_SUMMARY - echo "**Release**: ${{env.RELEASE}}" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY echo "---" >> $GITHUB_STEP_SUMMARY - - name: Checkout new release branch - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 - with: - ref: ${{env.release_branch}} - path: '${{github.workspace}}/release' - - # MAKE THE RELEASE PR + # MAKE THE DOCS PR - name: Checkout main for new docs version RELEASE PR uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 with: path: '${{github.workspace}}/new-docs-pr' - name: Generate version-metadata for workflow - working-directory: '${{github.workspace}}/release' + working-directory: '${{github.workspace}}/new-docs-pr' run: | npm i npm run prebuild-only-version-metadata - name: Create the new TFE version folder for RELEASE PR run: | - version=$(jq -r '.["terraform-enterprise"][] | select(.isLatest == true) | .version' "${{github.workspace}}/release/app/api/versionMetadata.json") - echo "Latest terraform-enterprise version: ${version}" - echo "LATEST_TFE_VERSION=$version" >> $GITHUB_ENV - - mkdir -p "${{github.workspace}}/new-docs-pr/content/terraform-enterprise/${{env.SERIES}}-${{env.RELEASE}}" - - cp -a "${{github.workspace}}/release/content/terraform-enterprise/${version}/." "${{github.workspace}}/new-docs-pr/content/terraform-enterprise/${{env.SERIES}}-${{env.RELEASE}}" + mkdir -p "${{github.workspace}}/new-docs-pr/content/terraform-enterprise/${{inputs.version}}" - - name: Open new docs version RELEASE PR + - name: Open new version DOCS PR + id: open-docs-pr working-directory: '${{github.workspace}}/new-docs-pr' env: - branch_name: docs/${{env.SERIES}}-${{env.RELEASE}} - pr_body: | - # Automated Docs Release PR for TFE ${{env.SERIES}}-${{env.RELEASE}} - - **TFE Series**: ${{ env.SERIES }} - **TFE Release**: ${{ env.RELEASE }} + docs_branch_name: docs/${{inputs.version}} + docs_pr_body: | + # Automated Docs Release PR for TFE ${{inputs.version}} ...Waiting for the diff PR to be created, before finishing this PR's description... @@ -111,67 +58,62 @@ jobs: git config --global user.email "team-rel-eng@hashicorp.com" git config --global user.name "tfe-release-bot" - if [ "$(git ls-remote --heads origin ${{env.branch_name}})" != "" ]; then - echo "❌ branch name ${{env.branch_name}} already exists, please delete it from remote/origin and try again. (i.e. git push origin --delete ${{env.branch_name}})" + if [ "$(git ls-remote --heads origin ${{env.docs_branch_name}})" != "" ]; then + echo "❌ branch name ${{env.docs_branch_name}} already exists, please delete it from remote/origin and try again. (i.e. git push origin --delete ${{env.docs_branch_name}})" - echo "❌ branch name ${{env.branch_name}} already exists, please delete it from remote/origin and try again. (i.e. git push origin --delete ${{env.branch_name}})" >> $GITHUB_STEP_SUMMARY + echo "❌ branch name ${{env.docs_branch_name}} already exists, please delete it from remote/origin and try again. (i.e. git push origin --delete ${{env.docs_branch_name}})" >> $GITHUB_STEP_SUMMARY exit 1 fi - git checkout -b ${{env.branch_name}} + git checkout -b ${{env.docs_branch_name}} git add . git commit -m "Automated Release Docs PR" --no-verify git push origin HEAD gh pr create \ - --body="${{env.pr_body}}" \ - --title="Automated Docs Release PR for TFE ${{env.SERIES}}-${{env.RELEASE}}" \ + --body="${{env.docs_pr_body}}" \ + --title="Automated Docs Release PR for TFE ${{inputs.version}}" \ --draft \ - --head ${{env.branch_name}} \ + --head ${{env.docs_branch_name}} \ --base main - pr_url=$(gh pr view --json url --jq '.url') - echo "PR_URL=${pr_url}" >> $GITHUB_ENV - echo "**Automated Release PR URL**: ${pr_url}" >> $GITHUB_STEP_SUMMARY + echo "docs_branch_name=${{env.docs_branch_name}}" >> $GITHUB_OUTPUT + docs_pr_url=$(gh pr view --json url --jq '.url') + echo "DOCS_PR_URL=${docs_pr_url}" >> $GITHUB_ENV + echo "**Automated Docs PR URL**: ${docs_pr_url}" >> $GITHUB_STEP_SUMMARY # MAKE THE DIFF PR - name: Checkout main for new docs version DIFF PR uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 with: path: '${{github.workspace}}/new-docs-diff-pr' - ref: docs/${{env.SERIES}}-${{env.RELEASE}} + ref: '${{steps.open-docs-pr.outputs.docs_branch_name}}' - name: Copy files for new docs version DIFF PR uses: ./release/.github/actions/copy-cloud-docs-for-tfe with: - source_path: '${{github.workspace}}/release' + source_path: '${{steps.open-docs-pr.outputs.docs_branch_name}}' target_path: '${{github.workspace}}/new-docs-diff-pr' - new_TFE_version: ${{env.SERIES}}-${{env.RELEASE}} + new_TFE_version: ${{inputs.version}} - name: Open new docs version DIFF PR working-directory: '${{github.workspace}}/new-docs-diff-pr' env: - release_branch_name: docs/${{env.SERIES}}-${{env.RELEASE}} - branch_name: docs-diff/${{env.SERIES}}-${{env.RELEASE}} - pr_body: | - # Automated Docs Diff PR for TFE ${{env.SERIES}}-${{env.RELEASE}} - - **TFE Series**: ${{ env.SERIES }} - **TFE Release**: ${{ env.RELEASE }} + docs_branch_name: ${{steps.open-docs-pr.outputs.docs_branch_name}} + diff_branch_name: docs-diff/${{inputs.version}} + diff_pr_body: | + # Automated Docs Diff PR for TFE ${{inputs.version}} This PR was created via: - ${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}} - Triggered by creation of branch: - - ${{github.server_url}}/${{github.repository}}/tree/${{env.release_branch}} - Copies over `content/terraform-docs-common/docs/cloud-docs` from: - - ${{github.server_url}}/${{github.repository}}/tree/${{env.release_branch}} + - ${{github.server_url}}/${{github.repository}}/tree/main Merges into the docs release branch: - - ${{ env.PR_URL }} + - ${{ env.DOCS_PR_URL }} ### Reviewers - [ ] @hashicorp/ptfe-review @@ -182,26 +124,26 @@ jobs: git config --global user.email "team-rel-eng@hashicorp.com" git config --global user.name "tfe-release-bot" - if [ "$(git ls-remote --heads origin ${{env.branch_name}})" != "" ]; then - echo "❌ branch name ${{env.branch_name}} already exists, please delete it from remote/origin and try again. (i.e. git push origin --delete ${{env.branch_name}})" + if [ "$(git ls-remote --heads origin ${{env.diff_branch_name}})" != "" ]; then + echo "❌ branch name ${{env.diff_branch_name}} already exists, please delete it from remote/origin and try again. (i.e. git push origin --delete ${{env.diff_branch_name}})" - echo "❌ branch name ${{env.branch_name}} already exists, please delete it from remote/origin and try again. (i.e. git push origin --delete ${{env.branch_name}})" >> $GITHUB_STEP_SUMMARY + echo "❌ branch name ${{env.diff_branch_name}} already exists, please delete it from remote/origin and try again. (i.e. git push origin --delete ${{env.diff_branch_name}})" >> $GITHUB_STEP_SUMMARY exit 1 fi - git checkout -b ${{env.branch_name}} + git checkout -b ${{env.diff_branch_name}} git add . git commit -m "Automated Docs Diff PR" --no-verify git push origin HEAD gh pr create \ - --body="${{env.pr_body}}" \ - --title="Automated Docs Diff PR for TFE ${{env.SERIES}}-${{env.RELEASE}}" \ + --body="${{env.diff_pr_body}}" \ + --title="Automated Docs Diff PR for TFE ${{inputs.version}}" \ --draft \ - --head ${{env.branch_name}} \ - --base ${{env.release_branch_name}} + --head ${{env.diff_branch_name}} \ + --base ${{env.docs_branch_name}} diff_pr_url=$(gh pr view --json url --jq '.url') echo "DIFF_PR_URL=${diff_pr_url}" >> $GITHUB_ENV @@ -209,19 +151,12 @@ jobs: - name: Update RELEASE PR with DIFF PR URL env: - branch_name: docs/${{env.SERIES}}-${{env.RELEASE}} - pr_body: | - # Automated Docs Release PR for TFE ${{env.SERIES}}-${{env.RELEASE}} - - **TFE Series**: ${{ env.SERIES }} - **TFE Release**: ${{ env.RELEASE }} + docs_pr_body: | + # Automated Docs Release PR for TFE ${{inputs.version}} This PR was created via: - ${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}} - Triggered by creation of branch: - - ${{github.server_url}}/${{github.repository}}/tree/${{env.release_branch}} - Changes since last release, diff PR: - ${{ env.DIFF_PR_URL }} @@ -233,5 +168,5 @@ jobs: git config --global user.email "team-rel-eng@hashicorp.com" git config --global user.name "tfe-release-bot" - gh pr edit ${{env.PR_URL}} \ - --body="${{env.pr_body}}" \ No newline at end of file + gh pr edit ${{env.docs_pr_body}} \ + --body="${{env.docs_pr_body}}" From 27b43a053f69c12cd2cb10ca1c349822d31e7741 Mon Sep 17 00:00:00 2001 From: Aaron Lane Date: Thu, 12 Jun 2025 16:31:24 -0400 Subject: [PATCH 2/7] Add a workflow call trigger --- .github/workflows/copy-cloud-docs-for-tfe.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/copy-cloud-docs-for-tfe.yml b/.github/workflows/copy-cloud-docs-for-tfe.yml index 21645b904..eb96da89f 100644 --- a/.github/workflows/copy-cloud-docs-for-tfe.yml +++ b/.github/workflows/copy-cloud-docs-for-tfe.yml @@ -5,11 +5,14 @@ on: inputs: version: description: 'The TFE version for the upcoming TFE release, format is either vYYYYMM-# or MAJOR.MINOR.PATCH (without a "v" prefix).' + required: true type: string + workflow_call: + inputs: + version: + description: 'The TFE version for the upcoming TFE release, format is either vYYYYMM-# or MAJOR.MINOR.PATCH (without a "v" prefix).' required: true - -env: - release_branch: ${{ inputs.branch }} + type: string jobs: copy-docs: From b745d0394e2a819e21cca9068886eb21d90d94ff Mon Sep 17 00:00:00 2001 From: Aaron Lane Date: Thu, 12 Jun 2025 16:31:36 -0400 Subject: [PATCH 3/7] Add docs_branch_name output --- .github/workflows/copy-cloud-docs-for-tfe.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/copy-cloud-docs-for-tfe.yml b/.github/workflows/copy-cloud-docs-for-tfe.yml index eb96da89f..6ae8743c2 100644 --- a/.github/workflows/copy-cloud-docs-for-tfe.yml +++ b/.github/workflows/copy-cloud-docs-for-tfe.yml @@ -13,11 +13,17 @@ on: description: 'The TFE version for the upcoming TFE release, format is either vYYYYMM-# or MAJOR.MINOR.PATCH (without a "v" prefix).' required: true type: string + outputs: + docs_branch_name: + description: 'The name of the branch created for the new TFE version docs.' + value: ${{ jobs.copy-docs.outputs.docs_branch_name }} jobs: copy-docs: name: Copy Docs runs-on: ubuntu-latest + outputs: + docs_branch_name: ${{ steps.open-docs-pr.outputs.docs_branch_name }} steps: - name: Series/Release Summary run: | From c8d024b57b9576122b0344b5c6f43f4fcd2de0e2 Mon Sep 17 00:00:00 2001 From: Aaron Lane Date: Thu, 12 Jun 2025 16:31:58 -0400 Subject: [PATCH 4/7] Copy docs before generating release notes --- .../workflows/create-tfe-release-notes.yml | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/.github/workflows/create-tfe-release-notes.yml b/.github/workflows/create-tfe-release-notes.yml index 3688e3f12..1368696d6 100644 --- a/.github/workflows/create-tfe-release-notes.yml +++ b/.github/workflows/create-tfe-release-notes.yml @@ -34,7 +34,13 @@ env: LAST_RELEASE_TAG: ${{ inputs.last-release-tag }} jobs: + copy-docs: + uses: ./.github/workflows/copy-cloud-docs-for-tfe.yml + with: + version: ${{ inputs.version }} + secrets: inherit release-notes: + needs: copy-docs runs-on: ubuntu-latest steps: - name: Only run in hashicorp/web-unified-docs-internal @@ -46,6 +52,8 @@ jobs: - name: Checkout web-unified-docs repository uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 + with: + ref: '${{ needs.copy-docs.outputs.docs_branch_name }}' - name: Install and cache Ruby gems at root uses: ruby/setup-ruby@52753b7da854d5c07df37391a986c76ab4615999 # v1.191.0 @@ -109,17 +117,3 @@ jobs: } ] } - - - name: Trigger Copy Cloud Docs for TFE Workflow - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 - with: - script: | - github.rest.actions.createWorkflowDispatch({ - owner: context.repo.owner, - repo: context.repo.repo, - workflow_id: 'copy-cloud-docs-for-tfe.yml', - ref: 'main', - inputs: { - branch: 'docs-tfe-releases/${{ env.VERSION }}' - }, - }) From 378ea6a0cdaff9279b39a80c59bd8239b74cb463 Mon Sep 17 00:00:00 2001 From: Aaron Lane Date: Thu, 12 Jun 2025 16:36:52 -0400 Subject: [PATCH 5/7] Fix reference to DOCS_PR_URL --- .github/workflows/copy-cloud-docs-for-tfe.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/copy-cloud-docs-for-tfe.yml b/.github/workflows/copy-cloud-docs-for-tfe.yml index 6ae8743c2..307634e2f 100644 --- a/.github/workflows/copy-cloud-docs-for-tfe.yml +++ b/.github/workflows/copy-cloud-docs-for-tfe.yml @@ -158,7 +158,7 @@ jobs: echo "DIFF_PR_URL=${diff_pr_url}" >> $GITHUB_ENV echo "**Automated DIFF PR URL**: ${diff_pr_url}" >> $GITHUB_STEP_SUMMARY - - name: Update RELEASE PR with DIFF PR URL + - name: Update DOCS PR with DIFF PR URL env: docs_pr_body: | # Automated Docs Release PR for TFE ${{inputs.version}} @@ -177,5 +177,5 @@ jobs: git config --global user.email "team-rel-eng@hashicorp.com" git config --global user.name "tfe-release-bot" - gh pr edit ${{env.docs_pr_body}} \ + gh pr edit ${{env.DOCS_PR_URL}} \ --body="${{env.docs_pr_body}}" From 7b5d27d20d9695be7ffdd4fe130f40adb17853a3 Mon Sep 17 00:00:00 2001 From: Aaron Lane Date: Thu, 12 Jun 2025 16:37:55 -0400 Subject: [PATCH 6/7] Fix source path --- .github/workflows/copy-cloud-docs-for-tfe.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/copy-cloud-docs-for-tfe.yml b/.github/workflows/copy-cloud-docs-for-tfe.yml index 307634e2f..f199ad4fd 100644 --- a/.github/workflows/copy-cloud-docs-for-tfe.yml +++ b/.github/workflows/copy-cloud-docs-for-tfe.yml @@ -103,7 +103,7 @@ jobs: - name: Copy files for new docs version DIFF PR uses: ./release/.github/actions/copy-cloud-docs-for-tfe with: - source_path: '${{steps.open-docs-pr.outputs.docs_branch_name}}' + source_path: '${{github.workspace}}/new-docs-pr' target_path: '${{github.workspace}}/new-docs-diff-pr' new_TFE_version: ${{inputs.version}} From f902506d1db7f395207e9d2ce6118c189d419572 Mon Sep 17 00:00:00 2001 From: Ruben Nic Date: Fri, 27 Jun 2025 11:13:02 -0400 Subject: [PATCH 7/7] MDX transforms to the new TFE files not in place --- .../actions/copy-cloud-docs-for-tfe/main.ts | 139 +++++++++--------- .../copy-cloud-docs-for-tfe/out/index.js | 130 ++++++++-------- 2 files changed, 126 insertions(+), 143 deletions(-) diff --git a/.github/actions/copy-cloud-docs-for-tfe/main.ts b/.github/actions/copy-cloud-docs-for-tfe/main.ts index 1acd6767d..4a534834a 100644 --- a/.github/actions/copy-cloud-docs-for-tfe/main.ts +++ b/.github/actions/copy-cloud-docs-for-tfe/main.ts @@ -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'), ) @@ -151,7 +152,7 @@ export async function main( fs.mkdirSync(newTFEVersionDir, { recursive: true }) const prevTFEVersionDir = path.join( - targetPath, + sourcePath, 'content/terraform-enterprise', currentTfeRelease, ) @@ -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 @@ -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) } } diff --git a/.github/actions/copy-cloud-docs-for-tfe/out/index.js b/.github/actions/copy-cloud-docs-for-tfe/out/index.js index 8e076ab91..e948f6c7a 100644 --- a/.github/actions/copy-cloud-docs-for-tfe/out/index.js +++ b/.github/actions/copy-cloud-docs-for-tfe/out/index.js @@ -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'), @@ -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, ) @@ -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 @@ -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