Skip to content

Update OpenAPI specs #745

Update OpenAPI specs

Update OpenAPI specs #745

Workflow file for this run

name: Transform OpenAPI Specs
on:
push:
branches:
- main
paths:
- 'source_specs/**'
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
permissions:
contents: write
jobs:
transform:
runs-on: ubuntu-latest
steps:
- name: Generate App Token
id: app-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
- name: Set up mise
uses: jdx/mise-action@v2
with:
cache: true
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Install dependencies
run: pnpm install --frozen-lockfile --ignore-scripts
- name: Transform OpenAPI spec paths
run: pnpm run transform:source_specs
env:
GITHUB_SHA: ${{ github.sha }}
- name: Generate OpenAPI specs
run: speakeasy run -s glean-api-specs
env:
SPEAKEASY_API_KEY: ${{ secrets.SPEAKEASY_API_KEY }}
# We intentionally skip uploading the spec to the Speakeasy registry since
# we're only using them for code sample generation.
- name: Generate Client API specs for code sample generation
run: speakeasy run -s glean-client-api-specs --skip-upload-spec
env:
SPEAKEASY_API_KEY: ${{ secrets.SPEAKEASY_API_KEY }}
# We intentionally skip uploading the spec to the Speakeasy registry since
# we're only using them for code sample generation.
- name: Generate Indexing API specs for code sample generation
run: speakeasy run -s glean-indexing-api-specs --skip-upload-spec
env:
SPEAKEASY_API_KEY: ${{ secrets.SPEAKEASY_API_KEY }}
- name: Run post-transformation smoke tests
run: pnpm exec vitest run tests/post_transform_smoke.test.js
- name: Check if changes are only SHA updates
id: check_changes
run: |
# Check if there are any changes at all
STATUS=$(git status --porcelain generated_specs/ overlayed_specs/ 2>/dev/null)
if [ -z "$STATUS" ]; then
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No changes to commit"
exit 0
fi
echo "::group::Changed files"
echo "$STATUS"
echo "::endgroup::"
# Check for new/untracked files (lines starting with ??)
NEW_FILES=$(echo "$STATUS" | grep "^??" | wc -l)
if [ "$NEW_FILES" -gt 0 ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "New files detected, will commit"
exit 0
fi
# Get the diff and check if only SHA lines changed (for modified files)
DIFF=$(git diff --unified=0 generated_specs/ overlayed_specs/)
echo "::group::Git diff"
echo "$DIFF"
echo "::endgroup::"
# Extract only the actual content changes (lines starting with + or -)
# Exclude file markers (+++/---), hunk headers (@@), and get only content
CHANGED_LINES=$(echo "$DIFF" | grep -E "^[\+\-]" | grep -v "^[\+\-][\+\-][\+\-]" | grep -v "^@@" || true)
if [ -z "$CHANGED_LINES" ]; then
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No actual content changes detected"
exit 0
fi
# Check if all changes are SHA-related
NON_SHA_CHANGES=$(echo "$CHANGED_LINES" | grep -v "x-source-commit-sha" | grep -v "x-open-api-commit-sha" || true)
echo "::group::Non-SHA changes"
echo "$NON_SHA_CHANGES"
echo "::endgroup::"
if [ -z "$NON_SHA_CHANGES" ]; then
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "Only SHA fields changed, skipping commit"
else
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "Non-SHA changes detected, will commit"
fi
# NOTE: The commit body contains "Generated-by: .github/workflows/transform.yml" which is used by
# trigger-client-generation.yml to detect whether meaningful changes were committed.
# If you change this identifier, update trigger-client-generation.yml accordingly.
- name: Commit changes
if: steps.check_changes.outputs.has_changes == 'true'
uses: ./.github/actions/git-commit
with:
commit_message: |
Update \`generated_specs\` and \`overlayed_specs\`
Generated-by: .github/workflows/transform.yml
file_patterns: 'generated_specs/* .speakeasy/* overlayed_specs/*'
github_token: ${{ steps.app-token.outputs.token }}