Skip to content

Commit 2cd354b

Browse files
authored
Merge pull request #81 from stacks-network/feat/upgrade-redocly-action
feat: upgrade redocly action
2 parents 7392028 + 42c4d40 commit 2cd354b

File tree

2 files changed

+101
-12
lines changed

2 files changed

+101
-12
lines changed

openapi/README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ Generates an HTML artifact of a provided openapi.yml file using `redoc`, checks
66

77
### Inputs
88

9-
| Input | Description | Required | Default |
10-
| ------------------------------- | ----------------------------------------------------- | ------------------------- | ------------------------- |
11-
| `input` | OpenAPI input file to use | true | null |
12-
| `output` | OpenAPI artifact filename | false | `./open-api-docs.html` |
9+
| Input | Description | Required | Default |
10+
| ----------------- | ----------------------------------------------------- | -------- | ---------------------- |
11+
| `input` | Input file to use to generate openAPI docs | `true` | `(none)` |
12+
| `output` | The path for the generated openAPI output file | `false` | `./open-api-docs.html` |
13+
| `validate` | Validate OpenAPI spec before generating docs | `false` | `true` |
14+
| `redocly-version` | The version of Redocly CLI to use (e.g. 1.34) | `false` | `latest` |
15+
| `config` | Path to the Redocly config file for linting | `false` | `(none)` |
16+
| `node-version` | Node.js version to use | `false` | `22` |
17+
| `retention-days` | Number of days to retain the artifact | `false` | `90` |
1318

1419
## Usage
1520

openapi/action.yml

Lines changed: 92 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
name: "Generate and upload openAPI docs"
2-
description: "Generate and upload openAPI docs"
2+
description: "Generate and upload openAPI docs using Redocly CLI"
33
branding:
44
icon: "globe"
55
color: "gray-dark"
6-
76
inputs:
87
output:
98
description: "openAPI output file"
@@ -13,34 +12,119 @@ inputs:
1312
description: "Input file to use to generate openAPI docs"
1413
required: true
1514
default: ""
15+
validate:
16+
description: "Validate OpenAPI spec before generating docs"
17+
required: false
18+
default: "true"
19+
redocly-version:
20+
description: "Version of Redocly CLI to use"
21+
required: false
22+
default: "latest"
23+
config:
24+
description: "Path to the Redocly config file for linting"
25+
required: false
26+
node-version:
27+
description: "Node.js version to use"
28+
required: false
29+
default: "22"
30+
retention-days:
31+
description: "Number of days to retain the artifact"
32+
required: false
33+
default: "90"
1634

1735
runs:
1836
using: "composite"
1937
steps:
20-
## checkout the code
2138
- name: Checkout the latest code
2239
id: git_checkout
2340
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2441

25-
## Use redoc to generate HTML of openapi.yml
26-
- name: Redoc
42+
- name: Detect OpenAPI spec version
43+
id: detect_spec
44+
shell: bash
45+
run: |
46+
echo "Detecting if new Redocly-based spec exists..."
47+
if [ -f ./docs/rpc/redocly.yaml ]; then
48+
echo "use_redocly_cli=true" >> "$GITHUB_OUTPUT"
49+
echo "✅ Detected new Redocly spec"
50+
else
51+
echo "use_redocly_cli=false" >> "$GITHUB_OUTPUT"
52+
echo "ℹ️ Falling back to legacy Redoc flow"
53+
fi
54+
55+
- name: Setup Node.js
56+
if: steps.detect_spec.outputs.use_redocly_cli == 'true'
57+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
58+
with:
59+
node-version: "${{ inputs.node-version }}"
60+
61+
- name: Install Redocly CLI
62+
if: steps.detect_spec.outputs.use_redocly_cli == 'true'
63+
id: install_redocly
64+
shell: bash
65+
run: |
66+
npm install -g @redocly/cli@${{ inputs.redocly-version }}
67+
echo "✅ Redocly CLI version: $(redocly --version)"
68+
69+
- name: Validate OpenAPI spec
70+
if: inputs.validate == 'true' && steps.detect_spec.outputs.use_redocly_cli == 'true'
71+
id: validate_spec
72+
shell: bash
73+
run: |
74+
echo "Validating OpenAPI specification..."
75+
CONFIG_ARG=""
76+
if [ -n "${{ inputs.config }}" ]; then
77+
CONFIG_ARG="--config ${{ inputs.config }}"
78+
fi
79+
redocly lint ${{ inputs.input }} $CONFIG_ARG
80+
echo "✅ OpenAPI specification is valid"
81+
82+
- name: Generate OpenAPI docs
83+
if: steps.detect_spec.outputs.use_redocly_cli == 'true'
84+
id: generate_docs
85+
shell: bash
86+
run: |
87+
echo "Generating OpenAPI documentation..."
88+
CONFIG_ARG=""
89+
if [ -n "${{ inputs.config }}" ]; then
90+
CONFIG_ARG="--config ${{ inputs.config }}"
91+
fi
92+
redocly build-docs ${{ inputs.input }} --output ${{ inputs.output }} $CONFIG_ARG
93+
echo "✅ Documentation generated successfully"
94+
95+
- name: Check result
96+
if: steps.detect_spec.outputs.use_redocly_cli == 'true'
97+
id: check_result
98+
shell: bash
99+
run: |
100+
echo "Checking if documentation file exists..."
101+
if [ ! -f ${{ inputs.output }} ]; then
102+
echo "❌ Missing ${{ inputs.output }} from previous step."
103+
exit 1
104+
fi
105+
echo "✅ Generated documentation file is valid"
106+
echo "📄 File size: $(du -h ${{ inputs.output }} | cut -f1)"
107+
108+
- name: Redoc (legacy)
27109
id: run_redoc
110+
if: steps.detect_spec.outputs.use_redocly_cli == 'false'
28111
uses: seeebiii/redoc-cli-github-action@c9649b33918da5eb290b81cd03a943caea091540 # v10
29112
with:
30113
args: "bundle -o ${{ inputs.output }} ${{ inputs.input }}"
31114

32-
## Test the resultant html
33-
- name: check result
115+
- name: Check result (legacy)
34116
id: check_redoc
117+
if: steps.detect_spec.outputs.use_redocly_cli == 'false'
35118
shell: bash
36119
run: |
37120
test -f ${{ inputs.output }} || (echo "Missing ${{ inputs.output }} from previous step." && exit 1)
38121
39122
## Upload the html file artifact
40123
- name: Upload bundled html
41124
id: upload_html_artifact
42-
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
125+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
43126
with:
44127
name: open-api-bundle
45128
path: |
46129
${{ inputs.output }}
130+
retention-days: ${{ inputs.retention-days }}

0 commit comments

Comments
 (0)