Skip to content

Commit

Permalink
Add source repository args to docc
Browse files Browse the repository at this point in the history
  • Loading branch information
ffried committed Sep 4, 2024
1 parent df6831b commit 66a096f
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/actions/generate-action-code/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ runs:
with:
node-version: 20
check-latest: true
cache: 'npm'
cache: npm
- name: Generate action code
shell: bash
run: |
Expand Down
34 changes: 13 additions & 21 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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`

Expand Down
14 changes: 13 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
34 changes: 32 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,18 +49,27 @@ 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);
args.push(...options.otherArgs);
return args;
}

async function generateDocsUsingSPM(packagePath: string, targets: string[], options: IDocCOptions): Promise<string> {
async function generateDocsUsingSPM(
packagePath: string,
targets: string[],
options: IDocCOptions
): Promise<string> {
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);
}
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 66a096f

Please sign in to comment.