Skip to content

Merge pull request #241 from aimlapi:stelyatko/feat-update-video-desc #110

Merge pull request #241 from aimlapi:stelyatko/feat-update-video-desc

Merge pull request #241 from aimlapi:stelyatko/feat-update-video-desc #110

name: Deploy Openapi Assets
on:
push:
branches: [main, feat-openapi-package]
paths:
- "packages/openapi/**"
jobs:
pack:
runs-on: ubuntu-latest
environment: production
permissions:
contents: read
outputs:
version: ${{ steps.set-outputs.outputs.version }}
packfile_name: ${{ steps.set-outputs.outputs.packfile_name }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- id: set-outputs
name: Pack @docs/openapi and upload artifacts
run: |
set -euo pipefail
cd packages/openapi
echo "Working dir: $(pwd)"
cat package.json
npm ci
# npm pack prints the filename; grab the last non-empty line
PACKFILE=$(npm pack | sed -n '/./p' | tail -n1)
echo "Packed file: $PACKFILE"
# create stable 'latest' name
LATEST_NAME="openapi-latest.tgz"
cp -f "$PACKFILE" "$LATEST_NAME"
# ensure files exist
ls -la
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "packfile_name=$PACKFILE" >> "$GITHUB_OUTPUT"
- name: Upload tarballs as artifact
uses: actions/upload-artifact@v4
with:
name: openapi-tarballs
path: |
packages/openapi/${{ steps.set-outputs.outputs.packfile_name }}
packages/openapi/openapi-latest.tgz
release-openapi-packages:
runs-on: ubuntu-latest
needs: pack
environment: production
permissions:
contents: write
steps:
- name: Checkout (needed for workspace)
uses: actions/checkout@v4
- name: Download packed artifacts
uses: actions/download-artifact@v4
with:
name: openapi-tarballs
path: artifacts
- name: Show artifacts (debug)
run: ls -la artifacts || true
- name: Resolve artifact paths
id: find
run: |
set -euo pipefail
PACKFILE="${{ needs.pack.outputs.packfile_name }}"
PACK_PATH=$(find artifacts -type f -name "$PACKFILE" -print -quit || true)
LATEST_PATH=$(find artifacts -type f -name "openapi-latest.tgz" -print -quit || true)
echo "Found pack path: $PACK_PATH"
echo "Found latest path: $LATEST_PATH"
if [ -z "$PACK_PATH" ] || [ -z "$LATEST_PATH" ]; then
echo "::error::Missing artifact(s). Debug listing:"
ls -Rla artifacts || true
exit 1
fi
echo "pack_path=$PACK_PATH" >> "$GITHUB_OUTPUT"
echo "latest_path=$LATEST_PATH" >> "$GITHUB_OUTPUT"
- name: Ensure GH CLI available
run: gh --version || (echo "gh not installed" && exit 1)
- name: Upload versioned asset (replace if exists)
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG="openapi-v${{ needs.pack.outputs.version }}"
ASSET="artifacts/${{ needs.pack.outputs.packfile_name }}"
# create release if missing
if ! gh release view "$TAG" >/dev/null 2>&1; then
gh release create "$TAG" --title "OpenAPI v${{ needs.pack.outputs.version }}" --notes "Automated release"
fi
# upload and overwrite existing asset with same name
gh release upload "$TAG" "$ASSET" --clobber
- name: Upload latest asset (replace if exists)
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
LATEST_TAG="openapi-latest"
LATEST_ASSET="artifacts/openapi-latest.tgz"
if ! gh release view "$LATEST_TAG" >/dev/null 2>&1; then
gh release create "$LATEST_TAG" --title "OpenAPI (latest)" --notes "Automated latest release"
fi
gh release upload "$LATEST_TAG" "$LATEST_ASSET" --clobber
rebuild-schema:
runs-on: ubuntu-latest
environment: production
needs:
- release-openapi-packages
steps:
- name: Trigger autoupdate swagger
env:
GH_ORG_ACCESS_TOKEN: ${{ secrets.GH_ORG_ACCESS_TOKEN }}
OPENAPI_REPO: ${{ secrets.OPENAPI_REPO }}
run: |
curl -X POST \
-H "Authorization: Bearer $GH_ORG_ACCESS_TOKEN" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/$OPENAPI_REPO/dispatches \
-d '{"event_type":"api-docs-release"}'