-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathgenerate-api-docs-contracts.yml
More file actions
166 lines (137 loc) Β· 5.94 KB
/
generate-api-docs-contracts.yml
File metadata and controls
166 lines (137 loc) Β· 5.94 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
158
159
160
161
162
163
164
165
166
# Docs Repository Receiver - Versioned Paths
# Receives trigger from openzeppelin-contracts and generates API docs
name: Generate API Docs - Contracts
on:
workflow_dispatch:
inputs:
tag_name:
description: 'Tag name or commit SHA to generate docs from'
required: true
type: string
default: 'v5.6.1'
trigger_type:
description: 'Trigger type (tag or commit)'
required: false
type: string
default: 'tag'
permissions:
contents: write
pull-requests: write
env:
SOURCE_REPO: 'OpenZeppelin/openzeppelin-contracts'
SOURCE_REPO_URL: 'https://github.com/OpenZeppelin/openzeppelin-contracts.git'
BASE_OUTPUT_PATH: 'content/contracts'
USE_VERSIONED_PATHS: 'true'
jobs:
generate-docs:
runs-on: ubuntu-latest
steps:
- name: Log trigger information
run: |
echo "π API Documentation Generation Triggered"
echo "π¦ Repository: ${{ env.SOURCE_REPO }}"
echo "π·οΈ Tag/Ref: ${{ inputs.tag_name }}"
echo "π Trigger type: ${{ inputs.trigger_type }}"
- name: Checkout docs repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.17.1
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Determine output directory
id: config
run: |
TAG_NAME="${{ inputs.tag_name }}"
TRIGGER_TYPE="${{ inputs.trigger_type }}"
BASE_PATH="${{ env.BASE_OUTPUT_PATH }}"
USE_VERSIONED="${{ env.USE_VERSIONED_PATHS }}"
if [[ "$USE_VERSIONED" == "false" ]]; then
OUTPUT_DIR="${BASE_PATH}/api"
echo "π Using non-versioned path"
elif [[ "$TRIGGER_TYPE" == "commit" ]]; then
OUTPUT_DIR="${BASE_PATH}/latest/api"
echo "π Using latest path for commit-based trigger"
else
# Extract major version from tag (v5.6.1 -> 5, v5.6.0 -> 5)
if [[ "$TAG_NAME" =~ v([0-9]+) ]]; then
MAJOR_VERSION="${BASH_REMATCH[1]}"
OUTPUT_DIR="${BASE_PATH}/${MAJOR_VERSION}.x/api"
echo "π Detected version: ${MAJOR_VERSION}.x"
else
OUTPUT_DIR="${BASE_PATH}/latest/api"
echo "β οΈ Non-standard tag format, using latest"
fi
fi
echo "π Output directory: $OUTPUT_DIR"
echo "output-dir=$OUTPUT_DIR" >> $GITHUB_OUTPUT
- name: Generate API Documentation
run: |
echo "π Generating API documentation..."
node scripts/generate-api-docs.js \
--repo "${{ env.SOURCE_REPO_URL }}" \
--branch "${{ inputs.tag_name }}" \
--api-output "${{ steps.config.outputs.output-dir }}"
- name: Validate generated documentation
run: |
pnpm run postinstall
pnpm run lint:links
- name: Create Pull Request for documentation changes
id: create_pr
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --local user.email "docs-automation@openzeppelin.com"
git config --local user.name "OpenZeppelin Docs Bot"
if [ -n "$(git status --porcelain)" ]; then
echo "π Creating branch and committing documentation changes..."
BRANCH_NAME="docs/api-update-${{ env.SOURCE_REPO }}-${{ inputs.tag_name }}"
BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/\//-/g' | sed 's/OpenZeppelin-//g')
git checkout -b "$BRANCH_NAME"
git add .
git commit -m "Update API docs for ${{ env.SOURCE_REPO }} ${{ inputs.tag_name }}
- Repository: ${{ env.SOURCE_REPO }}
- Ref: ${{ inputs.tag_name }}
- Trigger: ${{ inputs.trigger_type }}
- Output: ${{ steps.config.outputs.output-dir }}
- Timestamp: $(date -u '+%Y-%m-%d %H:%M:%S UTC')
Auto-generated via workflow_dispatch"
git push origin "$BRANCH_NAME"
gh pr create --title "[CI] Update API docs for ${{ env.SOURCE_REPO }} ${{ inputs.tag_name }}" \
--body "## API Documentation Update
This Pull Request updates the API documentation.
### Source Information
- **Repository:** ${{ env.SOURCE_REPO }}
- **Reference:** ${{ inputs.tag_name }}
- **Trigger Type:** ${{ inputs.trigger_type }}
- **Output Directory:** ${{ steps.config.outputs.output-dir }}
- **Timestamp:** $(date -u '+%Y-%m-%d %H:%M:%S UTC')
Auto-generated via workflow_dispatch" \
--base main \
--head "$BRANCH_NAME" || echo "β οΈ Pull Request creation failed"
echo "β
Pull Request created successfully"
echo "pr-created=true" >> $GITHUB_OUTPUT
else
echo "βΉοΈ No changes detected - documentation is up to date"
echo "pr-created=false" >> $GITHUB_OUTPUT
fi
- name: Create job summary
run: |
echo "## π API Documentation Generation Complete" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Source Information" >> $GITHUB_STEP_SUMMARY
echo "- **Repository:** ${{ env.SOURCE_REPO }}" >> $GITHUB_STEP_SUMMARY
echo "- **Reference:** ${{ inputs.tag_name }}" >> $GITHUB_STEP_SUMMARY
echo "- **Trigger Type:** ${{ inputs.trigger_type }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Output" >> $GITHUB_STEP_SUMMARY
echo "- **Directory:** ${{ steps.config.outputs.output-dir }}" >> $GITHUB_STEP_SUMMARY
echo "- **Status:** β
Complete" >> $GITHUB_STEP_SUMMARY