From 455a7cf6babff4dff6288d749c0d41124a88b98c Mon Sep 17 00:00:00 2001 From: Nara Kasbergen Date: Tue, 12 Dec 2023 20:39:57 +0100 Subject: [PATCH] feat: publish a top-level README in Go repositories --- src/index.ts | 28 +++++++++++++++++++---- test/__snapshots__/index.test.ts.snap | 33 +++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 72feddef..66b69a27 100644 --- a/src/index.ts +++ b/src/index.ts @@ -112,6 +112,10 @@ export class CdktfProviderProject extends cdk.JsiiProject { const mavenName = `com.${mavenOrg}.${namespace}.providers.${getMavenName( providerName )}`; + const repositoryUrl = `github.com/${githubNamespace}/${namespace}-provider-${providerName.replace( + /-/g, + "" + )}`; const packageInfo: PackageInfo = { npm: { @@ -138,10 +142,7 @@ export class CdktfProviderProject extends cdk.JsiiProject { mavenEndpoint, }, publishToGo: { - moduleName: `github.com/${githubNamespace}/${namespace}-provider-${providerName.replace( - /-/g, - "" - )}-go`, + moduleName: `${repositoryUrl}-go`, gitUserEmail: "github-team-tf-cdk@hashicorp.com", gitUserName: "CDK for Terraform Team", packageName: providerName.replace(/-/g, ""), @@ -176,6 +177,25 @@ export class CdktfProviderProject extends cdk.JsiiProject { name: "Remove copywrite hcl file", run: "rm -f .repo/dist/go/.copywrite.hcl", }, + { + name: "Move the README file up a directory", + run: "mv .repo/dist/go/*/README.md .repo/dist/go/README.md", + continueOnError: true, // can be removed later once confirmed this works + }, + { + name: "Remove some text from the README that doesn't apply to Go", + run: [ + "sed -i 's/# CDKTF prebuilt bindings for/# CDKTF Go bindings for/' .repo/dist/go/README.md", + // @see https://stackoverflow.com/a/49511949 + "sed -i -e '/## Available Packages/,/### Go/!b' -e '/### Go/!d;p; s/### Go/## Go Package/' -e 'd' .repo/dist/go/README.md", + // sed -e is black magic and for whatever reason the string replace doesn't work so let's try it again: + "sed -i 's/### Go/## Go Package/' .repo/dist/go/README.md", + // Just straight up delete these full lines and everything in between them: + "sed -i -e '/API.typescript.md/,/You can also visit a hosted version/!b' -e 'd' dist/go/README.md", + `sed -i 's|Find auto-generated docs for this provider here:|Find auto-generated docs for this provider [here](https://${repositoryUrl}/blob/main/docs/API.go.md).|' .repo/dist/go/README.md`, + ].join("\n"), + continueOnError: true, // can be removed later once confirmed this works + }, { name: "Collect go Artifact", run: "mv .repo/dist dist", diff --git a/test/__snapshots__/index.test.ts.snap b/test/__snapshots__/index.test.ts.snap index 2ab937af..fa31ad64 100644 --- a/test/__snapshots__/index.test.ts.snap +++ b/test/__snapshots__/index.test.ts.snap @@ -1042,6 +1042,17 @@ jobs: run: cd .repo/dist/go && copywrite headers - name: Remove copywrite hcl file run: rm -f .repo/dist/go/.copywrite.hcl + - name: Move the README file up a directory + run: mv .repo/dist/go/*/README.md .repo/dist/go/README.md + continue-on-error: true + - name: Remove some text from the README that doesn't apply to Go + run: |- + sed -i 's/# CDKTF prebuilt bindings for/# CDKTF Go bindings for/' .repo/dist/go/README.md + sed -i -e '/## Available Packages/,/### Go/!b' -e '/### Go/!d;p; s/### Go/## Go Package/' -e 'd' .repo/dist/go/README.md + sed -i 's/### Go/## Go Package/' .repo/dist/go/README.md + sed -i -e '/API.typescript.md/,/You can also visit a hosted version/!b' -e 'd' dist/go/README.md + sed -i 's|Find auto-generated docs for this provider here:|Find auto-generated docs for this provider [here](https://github.com/cdktf/cdktf-provider-random/blob/main/docs/API.go.md).|' .repo/dist/go/README.md + continue-on-error: true - name: Collect go Artifact run: mv .repo/dist dist - name: Release @@ -3768,6 +3779,17 @@ jobs: run: cd .repo/dist/go && copywrite headers - name: Remove copywrite hcl file run: rm -f .repo/dist/go/.copywrite.hcl + - name: Move the README file up a directory + run: mv .repo/dist/go/*/README.md .repo/dist/go/README.md + continue-on-error: true + - name: Remove some text from the README that doesn't apply to Go + run: |- + sed -i 's/# CDKTF prebuilt bindings for/# CDKTF Go bindings for/' .repo/dist/go/README.md + sed -i -e '/## Available Packages/,/### Go/!b' -e '/### Go/!d;p; s/### Go/## Go Package/' -e 'd' .repo/dist/go/README.md + sed -i 's/### Go/## Go Package/' .repo/dist/go/README.md + sed -i -e '/API.typescript.md/,/You can also visit a hosted version/!b' -e 'd' dist/go/README.md + sed -i 's|Find auto-generated docs for this provider here:|Find auto-generated docs for this provider [here](https://github.com/cdktf/cdktf-provider-random/blob/main/docs/API.go.md).|' .repo/dist/go/README.md + continue-on-error: true - name: Collect go Artifact run: mv .repo/dist dist - name: Release @@ -6443,6 +6465,17 @@ jobs: run: cd .repo/dist/go && copywrite headers - name: Remove copywrite hcl file run: rm -f .repo/dist/go/.copywrite.hcl + - name: Move the README file up a directory + run: mv .repo/dist/go/*/README.md .repo/dist/go/README.md + continue-on-error: true + - name: Remove some text from the README that doesn't apply to Go + run: |- + sed -i 's/# CDKTF prebuilt bindings for/# CDKTF Go bindings for/' .repo/dist/go/README.md + sed -i -e '/## Available Packages/,/### Go/!b' -e '/### Go/!d;p; s/### Go/## Go Package/' -e 'd' .repo/dist/go/README.md + sed -i 's/### Go/## Go Package/' .repo/dist/go/README.md + sed -i -e '/API.typescript.md/,/You can also visit a hosted version/!b' -e 'd' dist/go/README.md + sed -i 's|Find auto-generated docs for this provider here:|Find auto-generated docs for this provider [here](https://github.com/cdktf/cdktf-provider-random/blob/main/docs/API.go.md).|' .repo/dist/go/README.md + continue-on-error: true - name: Collect go Artifact run: mv .repo/dist dist - name: Release