-
Notifications
You must be signed in to change notification settings - Fork 1
164 lines (132 loc) · 5.59 KB
/
fetch-openapi-spec.yml
File metadata and controls
164 lines (132 loc) · 5.59 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
name: Fetch OpenAPI Specification
on:
workflow_dispatch:
inputs:
base_url:
description: 'QueryPie instance base URL'
required: false
default: 'https://internal.dev.querypie.io'
type: string
jobs:
fetch-openapi-spec:
runs-on: ["os:ubuntu", "purpose:ci"]
permissions:
contents: write # to create a branch and push changes
pull-requests: write # to create a PR
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history needed for git status
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Configure base URL
run: |
# Use input base URL if provided, otherwise use default
BASE_URL="${{ inputs.base_url || 'https://internal.dev.querypie.io' }}"
# Remove trailing slash if present
BASE_URL="${BASE_URL%/}"
# Construct full URLs with fixed paths
V09_URL="${BASE_URL}/api/docs/specification/external"
V2_URL="${BASE_URL}/api/docs/specification/external-v2"
echo "Base URL: $BASE_URL"
echo "V0.9 URL: $V09_URL"
echo "V2 URL: $V2_URL"
# Export as environment variables for use in subsequent steps
echo "V09_URL=$V09_URL" >> $GITHUB_ENV
echo "V2_URL=$V2_URL" >> $GITHUB_ENV
- name: Download V0.9 OpenAPI Spec
run: |
set -o errexit -o nounset -o pipefail -o xtrace
npm run fetch-openapi-spec -- "$V09_URL"
- name: Download V2 OpenAPI Spec
run: |
set -o errexit -o nounset -o pipefail -o xtrace
npm run fetch-openapi-spec -- "$V2_URL"
- name: Check for changes
run: |
echo "=== Git Status ==="
git status
echo ""
echo "=== Changed Files ==="
git status --porcelain public/openapi-specification/ || echo "No changes in public/openapi-specification/"
- name: Create Pull Request for OpenAPI Spec changes
env:
GH_TOKEN: ${{ github.token }}
run: |
set -o errexit -o nounset -o pipefail -o xtrace
# Git user configuration
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
# Check for changes in public/openapi-specification/ directory
if ! git status --porcelain public/openapi-specification/ | grep -q "[AM]"; then
echo "No changes in public/openapi-specification/ directory"
exit 0
fi
# Create branch name with timestamp
BRANCH_NAME="openapi/update-spec-$(date +%Y%m%d-%H%M%S)"
# Create and checkout branch
git checkout -b "$BRANCH_NAME"
# Stage only changes in public/openapi-specification/
git add public/openapi-specification/
# Check if there are staged changes
STAGED_FILES=$(git diff --cached --name-only)
if [[ -z "$STAGED_FILES" ]]; then
echo "No staged changes in public/openapi-specification/"
exit 0
fi
# Create temporary files for change information
TEMP_DIR=$(mktemp -d)
VERSION_INFO_FILE="${TEMP_DIR}/version_info.txt"
CHANGES_STATUS_FILE="${TEMP_DIR}/changes_status.txt"
CHANGES_STAT_FILE="${TEMP_DIR}/changes_stat.txt"
COMMIT_MSG_FILE="${TEMP_DIR}/commit_msg.txt"
PR_BODY_FILE="${TEMP_DIR}/pr_body.txt"
# Write version information to file
for file in $(git diff --cached --name-only public/openapi-specification/); do
if [[ "$file" =~ public/openapi-specification/([^/]+)/(v0\.9|v2)\.json ]]; then
VERSION="${BASH_REMATCH[1]}"
API_VERSION="${BASH_REMATCH[2]}"
echo "- ${VERSION}/${API_VERSION}.json" >> "$VERSION_INFO_FILE"
fi
done
# Write change status and statistics to files
git status --short public/openapi-specification/ > "$CHANGES_STATUS_FILE"
git diff --cached --stat HEAD > "$CHANGES_STAT_FILE"
# Write commit message and PR description to file (same content)
{
echo "chore: Update OpenAPI Specification files"
echo ""
echo "Automatically updated OpenAPI Specification files from QueryPie instance."
echo ""
echo "Updated files:"
cat "$VERSION_INFO_FILE"
echo ""
echo "### Change Details"
echo "\`\`\`"
cat "$CHANGES_STATUS_FILE"
echo "\`\`\`"
echo "### Change Statistics"
echo "\`\`\`"
cat "$CHANGES_STAT_FILE"
echo "\`\`\`"
} > "$COMMIT_MSG_FILE"
# Copy to PR body file (same content)
cp "$COMMIT_MSG_FILE" "$PR_BODY_FILE"
# Commit changes
git commit -F "$COMMIT_MSG_FILE"
# Push branch (required before creating PR)
git push -u origin "$BRANCH_NAME"
# Create PR
gh pr create \
--title "chore: Update OpenAPI Specification" \
--body-file "$PR_BODY_FILE" \
--base main \
--head "$BRANCH_NAME"
# Clean up temporary files
rm -rf "$TEMP_DIR"