Skip to content

Commit bfc96cc

Browse files
committed
feat: adds the github action files
1 parent 5dfd1fa commit bfc96cc

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed

Dockerfile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM alpine:latest
2+
3+
RUN apk add --no-cache bash grep git
4+
5+
COPY entrypoint.sh /entrypoint.sh
6+
7+
RUN chmod +x /entrypoint.sh
8+
9+
ENTRYPOINT ["/entrypoint.sh"]

README.md

+47-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,47 @@
1-
# find-openAPI-Specifications
1+
# OpenAPI Spec Finder GitHub Action
2+
3+
This action searches a GitHub repository for OpenAPI (also known as Swagger) specification files. It supports both OpenAPI 3.x.x and Swagger 2.0 specifications found in JSON and YAML formats.
4+
5+
The action will recursively search through all directories of the provided repository by default. However, a specific directory within the repository can be provided to narrow the search.
6+
7+
## Inputs
8+
9+
### `repository`
10+
11+
**Required** The URL of the GitHub repository to search.
12+
13+
### `search-dir`
14+
15+
Optional. The directory within the repository to search. If not provided, the action will search the entire repository.
16+
17+
## Usage
18+
19+
To use this action in a workflow, first set up the workflow to run on a specific event (like `push`), and then define the steps the workflow should take. One of those steps should be using this action.
20+
21+
Here is an example workflow that uses this action:
22+
23+
```yaml
24+
name: OpenAPI Spec Finder
25+
26+
on:
27+
push:
28+
branches:
29+
- main
30+
31+
jobs:
32+
find-specs:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Checkout repository
36+
uses: actions/checkout@v2
37+
38+
- name: Run OpenAPI Spec Finder
39+
uses: ./.github/actions/openapi-spec-finder
40+
with:
41+
repository: 'https://github.com/your-repo'
42+
search-dir: '/path/to/search' # Optional
43+
```
44+
45+
Replace 'https://github.com/your-repo' with the URL of the repository you want to search, and '/path/to/search' with the directory you want to search within the repository. If you want to search the entire repository, you can omit the search-dir input.
46+
47+
This action will output the paths of any OpenAPI spec files it finds to the console.

action.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: 'OpenAPI Spec Finder'
2+
description: 'Find OpenAPI Specifications in the repository'
3+
inputs:
4+
repository:
5+
description: 'GitHub repository URL'
6+
required: true
7+
search-dir:
8+
description: 'Directory to search'
9+
required: false
10+
runs:
11+
using: 'docker'
12+
image: 'Dockerfile'
13+
args:
14+
- ${{ inputs.repository }}
15+
- ${{ inputs.search-dir }}

entrypoint.sh

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
repository=$1
4+
search_dir=$2
5+
6+
if [ -z "$repository" ]; then
7+
echo "Please provide a repository URL."
8+
exit 1
9+
fi
10+
11+
# Clone the repository
12+
git clone $repository /tmp/repo
13+
14+
# Go to the repository root or the specified directory
15+
if [ -z "$search_dir" ]; then
16+
cd /tmp/repo
17+
else
18+
cd /tmp/repo/$search_dir
19+
fi
20+
21+
# Search for OpenAPI 3.x.x specifications
22+
spec_files=$(find . -type f \( -name "*.yaml" -o -name "*.yml" -o -name "*.json" \) -print0 | xargs -0 grep -l "openapi: 3")
23+
24+
# Search for Swagger 2.0 specifications
25+
spec_files+=$(find . -type f \( -name "*.yaml" -o -name "*.yml" -o -name "*.json" \) -print0 | xargs -0 grep -l "swagger: \"2.0\"")
26+
27+
echo $spec_files

0 commit comments

Comments
 (0)