Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
207 changes: 207 additions & 0 deletions .github/workflows/sync-docs-dispatcher.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
<!-- header:start -->

# GitHub Reusable Workflow: Sync Documentation Dispatcher

<div align="center">
<img src="../logo.svg" width="60px" align="center" alt="Sync Documentation Dispatcher" />
</div>

---

<!-- header:end -->

<!-- badges:start -->

[![Release](https://img.shields.io/github/v/release/hoverkraft-tech/ci-github-publish)](https://github.com/hoverkraft-tech/ci-github-publish/releases)
[![License](https://img.shields.io/github/license/hoverkraft-tech/ci-github-publish)](http://choosealicense.com/licenses/mit/)
[![Stars](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-publish?style=social)](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-publish?style=social)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/hoverkraft-tech/ci-github-publish/blob/main/CONTRIBUTING.md)

<!-- badges:end -->

<!--
// jscpd:ignore-start
-->

<!-- overview:start -->

## Overview

Reusable workflow: Sync documentation to public-docs repository

Purpose:

- Download the uploaded documentation artifact
- Generate a GitHub App token with appropriate permissions
- Dispatch a repository event to hoverkraft-tech/public-docs
- Pass artifact information to the receiver workflow

Prerequisites:

- GitHub App with `repo` and artifact access permissions configured
- Documentation artifact uploaded by prepare-docs action

### Permissions

- **`contents`**: `read`

<!-- overview:end -->

<!-- usage:start -->

## Usage

```yaml
name: Sync Documentation Dispatcher
on:
push:
branches:
- main
permissions:
contents: read
jobs:
sync-docs-dispatcher:
uses: hoverkraft-tech/ci-github-publish/.github/workflows/sync-docs-dispatcher.yml@b2a6d08d60e0adff6736caf6fdaa5fd3bcdd473a # 0.13.0
secrets:
# GitHub App private key to generate GitHub token in place of github-token.
# See https://github.com/actions/create-github-app-token.
github-app-key: ""
with:
# GitHub App ID to generate GitHub token in place of github-token.
# See https://github.com/actions/create-github-app-token.
github-app-id: ""

# ID of the uploaded documentation artifact.
#
# This input is required.
artifact-id: ""
```

<!-- usage:end -->

<!-- inputs:start -->

## Inputs

### Workflow Call Inputs

| **Input** | **Description** | **Required** | **Type** | **Default** |
| ------------------- | ---------------------------------------------------------------- | ------------ | ---------- | ----------- |
| **`github-app-id`** | GitHub App ID to generate GitHub token in place of github-token. | **false** | **string** | - |
| | See <https://github.com/actions/create-github-app-token>. | | | |
| **`artifact-id`** | ID of the uploaded documentation artifact. | **true** | **string** | - |

<!-- inputs:end -->

<!-- secrets:start -->

## Secrets

| **Secret** | **Description** | **Required** |
| -------------------- | ------------------------------------------------------------------------- | ------------ |
| **`github-app-key`** | GitHub App private key to generate GitHub token in place of github-token. | **false** |
| | See <https://github.com/actions/create-github-app-token>. | |

<!-- secrets:end -->

<!-- outputs:start -->
<!-- outputs:end -->

<!-- examples:start -->

## Examples

### Complete Integration

```yaml
name: Main CI

on:
push:
branches: [main]
pull_request:

permissions:
contents: read

jobs:
ci:
name: Run CI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run tests
run: npm test

prepare-docs:
name: Prepare Documentation
needs: ci
if: github.event_name != 'schedule' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
artifact-id: ${{ steps.prepare-docs.outputs.artifact-id }}
steps:
- uses: actions/checkout@v4

- name: Prepare documentation
id: prepare-docs
uses: hoverkraft-tech/public-docs/.github/actions/prepare-docs@18facec04f2945f4d66d510e8a06568497b73c54 # 0.1.0
with:
paths: |
README.md
docs/**/*.md
.github/workflows/*.md

sync-docs:
name: Sync Documentation
needs: prepare-docs
permissions:
contents: read
uses: hoverkraft-tech/ci-github-publish/.github/workflows/sync-docs-dispatcher.yml@b2a6d08d60e0adff6736caf6fdaa5fd3bcdd473a # 0.13.0
with:
github-app-id: ${{ vars.PUBLIC_DOCS_APP_ID }}
artifact-id: ${{ needs.prepare-docs.outputs.artifact-id }}
secrets:
github-app-key: ${{ secrets.PUBLIC_DOCS_APP_PRIVATE_KEY }}
```

<!-- examples:end -->

<!-- contributing:start -->

## Contributing

Contributions are welcome! Please see the [contributing guidelines](https://github.com/hoverkraft-tech/ci-github-publish/blob/main/CONTRIBUTING.md) for more details.

<!-- contributing:end -->

<!-- security:start -->
<!-- security:end -->

<!-- license:start -->

## License

This project is licensed under the MIT License.

SPDX-License-Identifier: MIT

Copyright © 2025 hoverkraft-tech

For more details, see the [license](http://choosealicense.com/licenses/mit/).

<!-- license:end -->

<!-- generated:start -->

---

This documentation was automatically generated by [CI Dokumentor](https://github.com/hoverkraft-tech/ci-dokumentor).

<!-- generated:end -->

<!--
// jscpd:ignore-end
-->
102 changes: 102 additions & 0 deletions .github/workflows/sync-docs-dispatcher.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Reusable workflow: Sync documentation to public-docs repository
#
# Purpose:
#
# - Download the uploaded documentation artifact
# - Generate a GitHub App token with appropriate permissions
# - Dispatch a repository event to hoverkraft-tech/public-docs
# - Pass artifact information to the receiver workflow
#
# Prerequisites:
#
# - GitHub App with `repo` and artifact access permissions configured
# - Documentation artifact uploaded by prepare-docs action

name: Sync Documentation Dispatcher

on:
workflow_call:
inputs:
github-app-id:
description: |
GitHub App ID to generate GitHub token in place of github-token.
See https://github.com/actions/create-github-app-token.
required: false
type: string
artifact-id:
description: |
ID of the uploaded documentation artifact.
required: true
type: string
secrets:
github-app-key:
description: |
GitHub App private key to generate GitHub token in place of github-token.
See https://github.com/actions/create-github-app-token.
required: false

permissions:
contents: read

jobs:
sync-docs:
name: Dispatch Documentation Sync
runs-on: ubuntu-latest
steps:
# jscpd:ignore-start

- uses: actions/create-github-app-token@67018539274d69449ef7c02e8e71183d1719ab42 # v2.1.4
if: inputs.github-app-id
id: generate-token
with:
app-id: ${{ inputs.github-app-id }}
private-key: ${{ secrets.github-app-key }}
owner: hoverkraft-tech
repositories: public-docs

# jscpd:ignore-end

- id: dispatch
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
ARTIFACT_ID: ${{ inputs.artifact-id }}
SOURCE_REPO: ${{ github.repository }}
SOURCE_RUN_ID: ${{ github.run_id }}
SOURCE_SHA: ${{ github.sha }}
with:
github-token: ${{ steps.generate-token.outputs.token || github.token }}
script: |
const artifactId = process.env.ARTIFACT_ID;
const sourceRepo = process.env.SOURCE_REPO;
const sourceRunId = process.env.SOURCE_RUN_ID;
const sourceSha = process.env.SOURCE_SHA;

if (!artifactId) {
return core.setFailed('artifact-id is required');
}

core.info('Dispatching documentation sync event...');

await github.rest.repos.createDispatchEvent({
owner: 'hoverkraft-tech',
repo: 'public-docs',
event_type: 'sync-docs',
client_payload: {
artifact_id: artifactId,
source_repo: sourceRepo,
source_run_id: sourceRunId,
source_sha: sourceSha,
}
});

core.summary.addHeading('Documentation Dispatch Summary', 2);
core.summary.addTable([
[{data: 'Property', header: true}, {data: 'Value', header: true}],
['Artifact ID', artifactId],
['Source Repository', sourceRepo],
['Run ID', sourceRunId],
['Commit SHA', sourceSha],
]);
await core.summary.write();

core.info('✅ Documentation sync event dispatched successfully');
6 changes: 6 additions & 0 deletions README.md

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert those changes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted README.md changes. Commit: 8072cdf

Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ _Reusable workflows for managing release process._

### - [Release actions](.github/workflows/release-actions.md)

### Documentation

_Reusable workflows for documentation synchronization._

### - [Sync docs dispatcher](.github/workflows/sync-docs-dispatcher.md)

## Contributing

Contributions are welcome! Please see the [contributing guidelines](https://github.com/hoverkraft-tech/ci-github-publish/blob/main/CONTRIBUTING.md) for more details.
Expand Down