-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (84 loc) · 3.03 KB
/
import-api-spec.yaml
File metadata and controls
92 lines (84 loc) · 3.03 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
name: Import API spec
on:
workflow_dispatch:
jobs:
create-files:
runs-on: ubuntu-latest
outputs:
filename: ${{ steps.makefile.outputs.filename }}
steps:
- name: Validate secrets
env:
APIDOG_API_KEY: ${{ secrets.APIDOG_API_KEY }}
EDGEGAP_V2_PROJECT_ID: ${{ secrets.EDGEGAP_V2_PROJECT_ID }}
run: |
if [ -z "$APIDOG_API_KEY" ] || [ -z "$EDGEGAP_V2_PROJECT_ID" ]; then
echo "❌ APIDOG_API_KEY and EDGEGAP_V2_PROJECT_ID must be set as secrets."
exit 1
fi
- id: export-openapi
env:
APIDOG_API_KEY: ${{ secrets.APIDOG_API_KEY }}
EDGEGAP_V2_PROJECT_ID: ${{ secrets.EDGEGAP_V2_PROJECT_ID }}
run: |
set -e
response_file="edgegap-v2-openapi.yaml"
status_file="curl_status.txt"
curl --location -g --request POST "https://api.apidog.com/v1/projects/${EDGEGAP_V2_PROJECT_ID}/export-openapi?locale=en-US" \
--header "X-Apidog-Api-Version: 2024-03-28" \
--header "Authorization: Bearer ${APIDOG_API_KEY}" \
--header "Content-Type: application/json" \
--data-raw '{
"scope": {
"type": "ALL"
},
"options": {
"includeApidogExtensionProperties": false
},
"oasVersion": "3.1",
"exportFormat": "YAML"
}' \
-w '%{http_code}' -o "$response_file" > "$status_file"
status=$(cat "$status_file")
if [ "$status" != "200" ]; then
echo "❌ API call failed with status $status"
cat "$response_file"
exit 1
fi
if jq -e '.success == false' "$response_file" >/dev/null 2>&1; then
echo "❌ API call returned success: false"
cat "$response_file"
exit 1
fi
echo "filename=$response_file" >> $GITHUB_OUTPUT
- uses: actions/upload-artifact@v4
with:
name: output-file
path: edgegap-v2-openapi.yaml
update-branch:
needs: create-files
runs-on: ubuntu-latest
steps:
- name: Verify branch context
run: |
echo "Triggered from ref: ${{ github.ref }}"
echo "Branch name: ${{ github.ref_name }}"
if [[ "${{ github.ref_type }}" != "branch" ]]; then
echo "❌ This workflow must be triggered on a branch."
exit 1
fi
- name: Checkout current branch
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: output-file
- name: Commit and push changes
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git add edgegap-v2-openapi.yaml
git commit -m "Update current branch with updated OpenAPI spec" || echo "No changes"
git push origin HEAD:${{ github.ref_name }}