Skip to content

Commit a7ca559

Browse files
author
Maxime Boisvert
committed
update: workflow
1 parent 68feb65 commit a7ca559

1 file changed

Lines changed: 61 additions & 14 deletions

File tree

.github/workflows/import-api-spec.yaml

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,92 @@ name: Import API spec
22

33
on:
44
workflow_dispatch:
5-
inputs:
6-
target_branch:
7-
description: 'Branch to update'
8-
required: true
5+
96

107
jobs:
118
create-files:
129
runs-on: ubuntu-latest
1310
outputs:
1411
filename: ${{ steps.makefile.outputs.filename }}
1512
steps:
16-
- id: makefile
13+
- name: Validate secrets
14+
env:
15+
APIDOG_API_KEY: ${{ secrets.APIDOG_API_KEY }}
16+
EDGEGAP_V2_PROJECT_ID: ${{ secrets.EDGEGAP_V2_PROJECT_ID }}
17+
run: |
18+
if [ -z "$APIDOG_API_KEY" ] || [ -z "$EDGEGAP_V2_PROJECT_ID" ]; then
19+
echo "❌ APIDOG_API_KEY and EDGEGAP_V2_PROJECT_ID must be set as secrets."
20+
exit 1
21+
fi
22+
23+
- id: export-openapi
24+
env:
25+
APIDOG_API_KEY: ${{ secrets.APIDOG_API_KEY }}
26+
EDGEGAP_V2_PROJECT_ID: ${{ secrets.EDGEGAP_V2_PROJECT_ID }}
1727
run: |
18-
echo "my-data" > output.txt
19-
echo "filename=output.txt" >> $GITHUB_OUTPUT
28+
set -e
29+
response_file="edgegap-v2-openapi.yaml"
30+
status_file="curl_status.txt"
31+
curl --location -g --request POST "https://api.apidog.com/v1/projects/${EDGEGAP_V2_PROJECT_ID}/export-openapi?locale=en-US" \
32+
--header "X-Apidog-Api-Version: 2024-03-28" \
33+
--header "Authorization: Bearer ${APIDOG_API_KEY}" \
34+
--header "Content-Type: application/json" \
35+
--data-raw '{
36+
"scope": {
37+
"type": "ALL"
38+
},
39+
"options": {
40+
"includeApidogExtensionProperties": false
41+
},
42+
"oasVersion": "3.1",
43+
"exportFormat": "YAML"
44+
}' \
45+
-w '%{{http_code}}' -o "$response_file" > "$status_file"
46+
status=$(cat "$status_file")
47+
if [ "$status" != "200" ]; then
48+
echo "❌ API call failed with status $status"
49+
cat "$response_file"
50+
exit 1
51+
fi
52+
if jq -e '.success == false' "$response_file" >/dev/null 2>&1; then
53+
echo "❌ API call returned success: false"
54+
cat "$response_file"
55+
exit 1
56+
fi
57+
echo "filename=$response_file" >> $GITHUB_OUTPUT
2058
2159
- uses: actions/upload-artifact@v4
2260
with:
2361
name: output-file
24-
path: output.txt
62+
path: edgegap-v2-openapi.yaml
2563

2664
update-branch:
2765
needs: create-files
2866
runs-on: ubuntu-latest
2967
steps:
30-
- name: Checkout target branch
68+
- name: Verify branch context
69+
run: |
70+
echo "Triggered from ref: ${{ github.ref }}"
71+
echo "Branch name: ${{ github.ref_name }}"
72+
if [[ "${{ github.ref_type }}" != "branch" ]]; then
73+
echo "❌ This workflow must be triggered on a branch."
74+
exit 1
75+
fi
76+
77+
- name: Checkout current branch
3178
uses: actions/checkout@v4
3279
with:
33-
ref: ${{ github.event.inputs.target_branch }}
80+
ref: ${{ github.ref_name }}
3481

3582
- name: Download artifact
3683
uses: actions/download-artifact@v4
3784
with:
3885
name: output-file
3986

40-
- name: Commit changes
87+
- name: Commit and push changes
4188
run: |
4289
git config user.name "github-actions"
4390
git config user.email "github-actions@github.com"
44-
git add output.txt
45-
git commit -m "Update branch with generated file" || echo "No changes"
46-
git push origin HEAD:${{ github.event.inputs.target_branch }}
91+
git add edgegap-v2-openapi.yaml
92+
git commit -m "Update current branch with updated OpenAPI spec" || echo "No changes"
93+
git push origin HEAD:${{ github.ref_name }}

0 commit comments

Comments
 (0)