-
Notifications
You must be signed in to change notification settings - Fork 0
157 lines (133 loc) · 6.3 KB
/
sync-docs-receiver.yml
File metadata and controls
157 lines (133 loc) · 6.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
name: Sync Documentation Receiver
on:
repository_dispatch:
types: [sync-documentation]
permissions: {}
jobs:
sync-documentation:
name: Sync Documentation
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Validate input
id: validate
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const payload = context.payload.client_payload || {};
const required = ['artifact-id', 'repository', 'run-id'];
const missing = required.filter(field => !payload[field]);
if (missing.length) {
return core.setFailed(`Missing required inputs: ${missing.join(', ')}`);
}
if (typeof payload.repository !== 'string' || !payload.repository.includes('/')) {
return core.setFailed(`Invalid repository slug: ${payload.repository}`);
}
core.debug(`Repository: ${payload.repository}`);
core.setOutput('repository', payload.repository);
core.debug(`Run ID: ${payload['run-id']}`);
core.setOutput('run-id', payload['run-id']);
core.debug(`Artifact ID: ${payload['artifact-id']}`);
core.setOutput('artifact-id', payload['artifact-id']);
- name: Resolve documentation target
id: resolve
uses: ./.github/actions/resolve-docs-target
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ steps.validate.outputs.repository }}
- name: Download documentation artifact
id: download-artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
artifact-ids: ${{ steps.validate.outputs.artifact-id }}
path: ${{ runner.temp }}/documentation-download-${{ github.run_id }}
repository: ${{ steps.validate.outputs.repository }}
run-id: ${{ steps.validate.outputs.run-id }}
- name: Prepare documentation content
id: prepare-docs
uses: ./.github/actions/prepare-docs
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
artifact-path: ${{ steps.download-artifact.outputs.download-path }}
source-repository: ${{ steps.validate.outputs.repository }}
run-id: ${{ steps.validate.outputs.run-id }}
docs-path: ${{ steps.resolve.outputs.docs-path }}
static-path: ${{ steps.resolve.outputs.static-path }}
- name: Inject documentation
uses: ./.github/actions/inject-docs
with:
source-repository: ${{ steps.validate.outputs.repository }}
docs-path: ${{ steps.resolve.outputs.docs-path }}
static-path: ${{ steps.resolve.outputs.static-path }}
prepared-dir: ${{ steps.prepare-docs.outputs.output-path }}
- name: Generate Documentation
uses: ./.github/actions/generate-docs
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 # v3.0.0
id: generate_token
with:
app-id: ${{ vars.CI_BOT_APP_ID }}
private-key: ${{ secrets.CI_BOT_APP_PRIVATE_KEY }}
- uses: hoverkraft-tech/ci-github-common/actions/create-and-merge-pull-request@4b53189212d5810f710bed89711002626977215b # 0.30.21
with:
github-token: ${{ steps.generate_token.outputs.token }}
branch: docs/sync-documentation-${{ github.event.client_payload.repository }}
title: "docs(${{ github.event.client_payload.repository }}): update documentation"
body: Update documentation for ${{ github.event.client_payload.repository }}
commit-message: |
docs(${{ github.event.client_payload.repository }}): update documentation
- name: Summary
if: always()
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
STATUS: ${{ job.status }}
SOURCE_REPOSITORY: ${{ steps.validate.outputs.repository }}
ARTIFACT_ID: ${{ steps.validate.outputs.artifact-id }}
DOCS_PATH: ${{ steps.resolve.outputs.docs-path }}
STATIC_PATH: ${{ steps.resolve.outputs.static-path }}
CATEGORY_NAME: ${{ steps.resolve.outputs.category-name }}
CATEGORY_SLUG: ${{ steps.resolve.outputs.category-slug }}
SOURCE_BRANCH: ${{ steps.prepare-docs.outputs.source-branch }}
PROCESSED_FILES: ${{ steps.prepare-docs.outputs.processed-files }}
with:
script: |
const files = process.env.PROCESSED_FILES ? JSON.parse(process.env.PROCESSED_FILES) : [];
const statusText = process.env.STATUS === 'success'
? 'Documentation committed to public-docs'
: 'Error occurred during documentation sync';
const filesSummary = files.length
? `Processed files:\n${files.join('\n')}`
: 'No files were processed.';
const summaryBuilder = core.summary
.addHeading('Documentation Sync Summary', 2)
.addRaw('\n')
.addList([
`Source Repository: ${process.env.SOURCE_REPOSITORY}`,
`Source Branch: ${process.env.SOURCE_BRANCH}`,
`Category: ${process.env.CATEGORY_NAME} (${process.env.CATEGORY_SLUG})`,
`Docs Path: ${process.env.DOCS_PATH}`,
`Static Path: ${process.env.STATIC_PATH}`,
`Processed file(s): ${files.length}`,
`Artifact: ${process.env.ARTIFACT_ID}`,
`Status: ${statusText}`
])
.addRaw('\n');
if (files.length > 0) {
summaryBuilder
.addRaw("Processed files:")
.addList(files);
} else {
summaryBuilder.addRaw("Processed files: no files were processed.");
}
summaryBuilder
.addRaw('\n\n')
.addRaw('Build and deployment will be handled by the push to main workflow.');
await summaryBuilder.write();