Repository navigation
107 lines (94 loc) · 4.11 KB
/
Copy pathdocs-sync.yml
File metadata and controls
107 lines (94 loc) · 4.11 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
# Publishes the CLI's generated command reference into flexprice/flexprice-docs
# as a reviewable PR whenever a CLI release is published.
#
# Deliberately a separate workflow rather than a `needs: release` job inside
# release.yml: `release: published` cannot fire before the release exists, so
# the ordering is guaranteed by the event itself — and keeping it separate
# means workflow_dispatch can test this in isolation without re-running
# goreleaser and risking an accidental real release.
#
# Actions are SHA-pinned: this workflow carries a cross-repo write token.
name: Sync CLI docs to flexprice-docs
on:
release:
types: [published]
workflow_dispatch:
inputs:
ref:
description: 'Git ref to generate docs from'
required: false
default: 'main'
permissions:
contents: read
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
ref: ${{ github.event.inputs.ref || github.ref }}
- uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5
with:
go-version-file: go.mod
- name: Generate command reference
run: go run ./tools/gendocs
- name: Checkout flexprice-docs
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
repository: flexprice/flexprice-docs
token: ${{ secrets.FLEXPRICE_DOCS_DEPLOY_TOKEN }}
path: target
# Clean before copying so commands that were renamed or removed do not
# leave stale pages behind in the published docs.
- name: Sync command reference into target
run: |
mkdir -p target/docs/cli-reference
find target/docs/cli-reference -maxdepth 1 -name '*.md' -delete
cp docs/*.md target/docs/cli-reference/
- name: Open sync PR
uses: peter-evans/create-pull-request@22a9089034f40e5a961c8808d113e2c98fb63676 # v7
with:
path: target
token: ${{ secrets.FLEXPRICE_DOCS_DEPLOY_TOKEN }}
branch: sync/cli-command-reference
commit-message: "chore: sync CLI command reference for ${{ github.event.release.tag_name || github.event.inputs.ref }}"
title: "Sync CLI command reference for ${{ github.event.release.tag_name || github.event.inputs.ref }}"
body: |
Auto-generated by flexprice/cli's `docs-sync.yml`.
Source: flexprice/cli @ ${{ github.event.release.html_url || github.event.inputs.ref }}
Note: adding a navigation entry for `docs/cli-reference/` in
`docs.json` is a manual editorial step and is not automated.
notify-on-failure:
needs: sync
if: failure()
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
with:
script: |
const title = 'CLI docs sync to flexprice-docs failed';
const body = `Workflow run failed: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const { owner, repo } = context.repo;
// Search by title, not by label: if the label is ever deleted, a
// label-filtered query returns nothing and we would open a
// duplicate issue on every single failure.
const existing = await github.rest.issues.listForRepo({
owner, repo, state: 'open', per_page: 100,
});
const match = existing.data.find(i => i.title === title);
if (match) {
await github.rest.issues.createComment({
owner, repo, issue_number: match.number, body,
});
} else {
try {
await github.rest.issues.create({
owner, repo, title, body, labels: ['automation-failure'],
});
} catch (e) {
core.warning(`Labelled issue creation failed (${e.message}); retrying without label.`);
await github.rest.issues.create({ owner, repo, title, body });
}
}