From 66a096f09ddf296a1e9205229d446f4da6c3bd96 Mon Sep 17 00:00:00 2001 From: Florian Friedrich Date: Wed, 4 Sep 2024 09:03:16 +0200 Subject: [PATCH] Add source repository args to docc --- .../actions/generate-action-code/action.yml | 2 +- .github/dependabot.yml | 34 +++++++------------ README.md | 13 +++++++ action.yml | 14 +++++++- src/main.ts | 34 +++++++++++++++++-- 5 files changed, 72 insertions(+), 25 deletions(-) diff --git a/.github/actions/generate-action-code/action.yml b/.github/actions/generate-action-code/action.yml index c50a1ca..8f301b5 100644 --- a/.github/actions/generate-action-code/action.yml +++ b/.github/actions/generate-action-code/action.yml @@ -8,7 +8,7 @@ runs: with: node-version: 20 check-latest: true - cache: 'npm' + cache: npm - name: Generate action code shell: bash run: | diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 568990c..49aeaa7 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,35 +1,27 @@ version: 2 updates: - - package-ecosystem: "github-actions" - directory: "/" + - package-ecosystem: github-actions + directories: + - / + - .github/actions/generate-action-code open-pull-requests-limit: 10 schedule: - interval: "daily" - time: "07:00" - timezone: "Europe/Berlin" + interval: daily + time: '07:00' + timezone: Europe/Berlin assignees: - ffried reviewers: - ffried - - package-ecosystem: "github-actions" - directory: ".github/actions/generate-action-code" - open-pull-requests-limit: 10 - schedule: - interval: "daily" - time: "07:00" - timezone: "Europe/Berlin" - assignees: - - ffried - reviewers: - - ffried - - package-ecosystem: "npm" - directory: "/" + + - package-ecosystem: npm + directory: / open-pull-requests-limit: 10 schedule: - interval: "daily" - time: "07:00" - timezone: "Europe/Berlin" + interval: daily + time: '07:00' + timezone: Europe/Berlin assignees: - ffried reviewers: diff --git a/README.md b/README.md index 004b464..cc86f1e 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,18 @@ Whether to enable inherited docs. Defaults to `false`. Enable index building. Defaults to `false`. +### `checkout-path` + +The path to check out the package to. Defaults to the workspace (`${{ github.workspace }}`). + +### `repository-service` + +The service to use for the repository. Must be supported by `docc` (see `xcrun docc convert --help`). Defaults to `github`. + +### `repository-base-url` + +The base URL of the repository. Defaults to the current repository (`${{ github.server_url }}/${{ github.repository }}`). + ### `transform-for-static-hosting` Enables the static hosting transformation. Defaults to `false`. @@ -64,6 +76,7 @@ _Note:_ This parameter is only evaluated when running on macOS. ### `other-xcodebuild-arguments` Further (newline-separated) `xcodebuild` arguments. +_Note:_ This parameter is only evaluated when running on macOS. ### `output` diff --git a/action.yml b/action.yml index 66b1cfe..e78f049 100644 --- a/action.yml +++ b/action.yml @@ -5,7 +5,7 @@ inputs: package-path: description: The path to the package. required: true - default: ${{github.workspace}} + default: ${{ github.workspace }} package-version: description: The version to use for this package. required: false @@ -17,6 +17,18 @@ inputs: description: Enables index building. required: true default: 'false' + checkout-path: + description: The path to check out the package to. Defaults to the workspace. + required: false + default: ${{ github.workspace }} + repository-service: + description: The service to use for the repository. Must be supported by docc. Defaults to GitHub. + required: false + default: 'github' + repository-base-url: + description: The base URL of the repository. Defaults to the current repository. + required: false + default: ${{ github.server_url }}/${{ github.repository }} transform-for-static-hosting: description: Enables the static hosting transformation. required: true diff --git a/src/main.ts b/src/main.ts index 6204adf..cc53016 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,10 +6,21 @@ interface ILengthProviding { length: number; } +interface IDocCSourceRepositoryService { + type: 'github' | 'gitlab' | 'bitbucket' | string; + baseUrl: string; +} + +interface IDocCSourceRepositoryOptions { + checkoutPath: string | null; + service: IDocCSourceRepositoryService | null; +} + interface IDocCOptions { enableIndexBuilding: boolean; transformForStaticHosting: boolean; enableInheritedDocs: boolean; + sourceRepository: IDocCSourceRepositoryOptions | null; bundleVersion: string | null; hostingBasePath: string | null; outputPath: string | null; @@ -38,6 +49,11 @@ function docCFlags(options: IDocCOptions, useSPMPlugin: boolean): string[] { else if (options.enableIndexBuilding && !useSPMPlugin) args.push('--index'); if (options.transformForStaticHosting) args.push('--transform-for-static-hosting'); if (options.enableInheritedDocs) args.push('--enable-inherited-docs'); + if (options.sourceRepository?.checkoutPath) args.push('--checkout-path', options.sourceRepository.checkoutPath); + if (options.sourceRepository?.service) { + args.push('--source-service', options.sourceRepository.service.type); + args.push('--source-service-base-url', options.sourceRepository.service.baseUrl); + } if (options.bundleVersion) args.push('--bundle-version', options.bundleVersion); if (options.hostingBasePath) args.push('--hosting-base-path', options.hostingBasePath); if (options.outputPath) args.push('--output-path', options.outputPath); @@ -45,11 +61,15 @@ function docCFlags(options: IDocCOptions, useSPMPlugin: boolean): string[] { return args; } -async function generateDocsUsingSPM(packagePath: string, targets: string[], options: IDocCOptions): Promise { +async function generateDocsUsingSPM( + packagePath: string, + targets: string[], + options: IDocCOptions +): Promise { let args = ['package']; if (options.outputPath) args.push('--allow-writing-to-directory', options.outputPath); args.push('generate-documentation'); - if (targets.length > 0) args.push(...targets.flatMap(t => ['--target', t])); + if (targets.length > 0) args.push(...targets.flatMap(t => ['--target', t])); args.push(...docCFlags(options, true)); return await runCmd('swift', args, packagePath); } @@ -82,6 +102,9 @@ async function main() { const packageVersion = core.getInput('package-version'); const enableIndexBuilding = core.getBooleanInput('enable-index-building', { required: true }); const enableInheritedDocs = core.getBooleanInput('enable-inherited-docs', { required: true }); + const checkoutPath = core.getInput('checkout-path'); + const repoService = core.getInput('repository-service'); + const repoBaseUrl = core.getInput('repository-base-url'); const transformForStaticHosting = core.getBooleanInput('transform-for-static-hosting', { required: true }); const hostingBasePath = core.getInput('hosting-base-path'); const outputDir = core.getInput('output'); @@ -109,6 +132,13 @@ async function main() { enableIndexBuilding: enableIndexBuilding, transformForStaticHosting: transformForStaticHosting, enableInheritedDocs: enableInheritedDocs, + sourceRepository: checkoutPath || repoService || repoBaseUrl ? { + checkoutPath: nonEmpty(checkoutPath), + service: repoService && repoBaseUrl ? { + type: repoService, + baseUrl: repoBaseUrl, + } : null, + } : null, bundleVersion: nonEmpty(packageVersion), hostingBasePath: nonEmpty(hostingBasePath), outputPath: mapNonNull(nonEmpty(outputDir), path.resolve),