-
Notifications
You must be signed in to change notification settings - Fork 0
147 lines (132 loc) · 4.73 KB
/
Copy pathgenerate-api-reference.yml
File metadata and controls
147 lines (132 loc) · 4.73 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
# SPDX-License-Identifier: Apache-2.0
name: Generate API Reference
on:
workflow_call:
inputs:
actions-repo:
type: string
default: 'nubificus/vaccel'
actions-ref:
type: string
default: 'main'
deploy:
type: boolean
default: false
target-repo-owner:
type: string
default: 'nubificus'
target-repo-name:
type: string
default: 'vaccel-docs'
target-workflow:
type: string
default: 'dispatch-update-external-repo.yml'
secrets:
VACCEL_BOT_PRIVATE_KEY:
required: true
permissions: read-all
jobs:
generate-reference:
name: Generate API Reference
runs-on: base-dind-2204-amd64
steps:
- name: Parse repository names
id: parse-repos
env:
ACTIONS_REPO: ${{ inputs.actions-repo }}
run: |
{
echo "repo-name=$(basename "$GITHUB_REPOSITORY")"
echo "actions-repo-name=$(basename "$ACTIONS_REPO")"
} >> "$GITHUB_OUTPUT"
shell: bash
- name: Generate initialization vaccel-bot token
id: generate-init-token
uses: actions/create-github-app-token@v3
with:
client-id: ${{ vars.VACCEL_BOT_CLIENT_ID }}
private-key: ${{ secrets.VACCEL_BOT_PRIVATE_KEY }}
repositories: |
${{ steps.parse-repos.outputs.repo-name }}
${{ steps.parse-repos.outputs.actions-repo-name }}
permission-contents: read
- name: Checkout .github directory
uses: actions/checkout@v6
with:
sparse-checkout: .github
repository: ${{ inputs.actions-repo }}
ref: ${{ inputs.actions-ref }}
token: ${{ steps.generate-init-token.outputs.token }}
- name: Initialize workspace
id: initialize-workspace
uses: ./.github/actions/initialize-workspace
with:
remote-actions-repo: ${{ inputs.actions-repo }}
fetch-depth: 0
submodules: 'false'
token: ${{ steps.generate-init-token.outputs.token }}
- name: Determine SHA and branch
id: get-revision
uses: ./.github/actions/get-revision-info
- name: Generate trigger vaccel-bot token
id: generate-trigger-token
uses: actions/create-github-app-token@v3
with:
client-id: ${{ vars.VACCEL_BOT_CLIENT_ID }}
private-key: ${{ secrets.VACCEL_BOT_PRIVATE_KEY }}
owner: ${{ inputs.target-repo-owner }}
repositories: ${{ inputs.target-repo-name }}
permission-contents: read
permission-checks: read
permission-actions: write
- name: Create docs PR
timeout-minutes: 30
env:
GH_TOKEN: ${{ steps.generate-trigger-token.outputs.token }}
TARGET_WORKFLOW: ${{ inputs.target-workflow }}
REPO: >-
${{ format('{0}/{1}',
inputs.target-repo-owner, inputs.target-repo-name) }}
TRIGGER_ID: ${{ github.run_id }}
REF: ${{ steps.get-revision.outputs.sha }}
BRANCH: ${{ steps.get-revision.outputs.branch }}
DEPLOY: ${{ inputs.deploy }}
WATCH_INTERVAL_SEC: 20
run: |
run_url=$(gh workflow run "$TARGET_WORKFLOW" \
--repo "$REPO" \
-f trigger-id="$TRIGGER_ID" \
-f ref="$REF" \
-f branch="$BRANCH" \
-f repository="$GITHUB_REPOSITORY" \
-f deploy="$DEPLOY")
run_id="${run_url##*/}"
echo "Triggered workflow run: ${run_url}"
{
echo "## Create docs PR summary"
echo "- Triggered **${REPO}** run [#${run_id}](${run_url})"
} >> "$GITHUB_STEP_SUMMARY"
echo "Waiting for run to complete..."
gh run watch "$run_id" \
--repo "$REPO" \
--interval "$WATCH_INTERVAL_SEC" \
--compact \
--exit-status
echo "Run completed successfully"
[[ "$DEPLOY" == 'true' ]] || exit 0
run_log=$(gh run view "$run_id" --repo "$REPO" --log)
read -r pr_number pr_operation pr_url < <(echo "$run_log" | awk '
/Pull request number:/ { number = $NF }
/Pull request operation:/ { operation = $NF }
/Pull request URL:/ { url = $NF }
END { print number, operation, url }
')
if [[ -n "$pr_operation" ]]; then
echo "${pr_operation^} PR: ${pr_url}"
echo "- ${pr_operation^} PR [${REPO}#${pr_number}](${pr_url})" \
>> "$GITHUB_STEP_SUMMARY"
else
echo "No PR was created or updated"
echo "- No PR was created or updated" >> "$GITHUB_STEP_SUMMARY"
fi
shell: bash