Skip to content

Merge pull request #7 from CrackingShells/schema-updates #10

Merge pull request #7 from CrackingShells/schema-updates

Merge pull request #7 from CrackingShells/schema-updates #10

name: Schema Deployment
# This workflow handles the deployment of schemas.
# Schema validation occurs in a separate workflow (schema-validation.yml) that runs on pull requests.
# This ensures schemas are already validated before they reach this deployment workflow.
on:
push:
branches:
- main
paths:
- 'package/v*/**'
- 'registry/v*/**'
- '.github/workflows/schema-deployment.yml'
workflow_dispatch: # Allows manual triggering of the workflow
inputs:
force:
description: 'Force deployment even if no changes detected'
type: boolean
required: true
default: false
pkg_schema_version:
description: 'Package schema version'
type: string
required: false
default: 'v1'
registry_schema_version:
description: 'Registry schema version'
type: string
required: false
default: 'v1'
permissions:
contents: write # For GitHub Releases
pages: write # For GitHub Pages deployment
id-token: write # Required for Pages deployment
# Ensure we can deploy to GitHub Pages
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
detect-versions:
runs-on: ubuntu-latest
outputs:
pkg_versions: ${{ steps.get-versions.outputs.pkg_versions }}
registry_versions: ${{ steps.get-versions.outputs.registry_versions }}
highest_pkg_version: ${{ steps.get-versions.outputs.highest_pkg_version }}
highest_registry_version: ${{ steps.get-versions.outputs.highest_registry_version }}
no-changes: ${{ steps.changed-files.outputs.all_changed_files == '' && (github.event_name != 'workflow_dispatch' || (github.event_name == 'workflow_dispatch' && github.event.inputs.force != 'true')) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v35
with:
files: |
package/v*/**
registry/v*/**
- name: Stop if no changes detected
if: steps.changed-files.outputs.all_changed_files == '' && (github.event_name != 'workflow_dispatch' || (github.event_name == 'workflow_dispatch' && github.event.inputs.force != 'true'))
run: |
echo "No changes detected in package or registry schemas and force is not enabled. Exiting..."
exit 0
- name: Detect versions from changed files
id: get-versions
run: |
# Make scripts executable
chmod +x ./scripts/detect_versions.sh
# Use the script to detect versions from changed files
echo "Running version detection..."
if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ github.event.inputs.force }}" == "true" ]]; then
echo "Force deployment enabled. Using provided versions."
PKG_VERSION="${{ github.event.inputs.pkg_schema_version }}"
REG_VERSION="${{ github.event.inputs.registry_schema_version }}"
# Create JSON arrays for each schema type
echo "pkg_versions=[\"$PKG_VERSION\"]" >> $GITHUB_OUTPUT
echo "registry_versions=[\"$REG_VERSION\"]" >> $GITHUB_OUTPUT
echo "highest_pkg_version=$PKG_VERSION" >> $GITHUB_OUTPUT
echo "highest_registry_version=$REG_VERSION" >> $GITHUB_OUTPUT
else
# Process changed files to detect versions
./scripts/detect_versions.sh ${{ steps.changed-files.outputs.all_changed_files }}
fi
build-deploy:
if: needs.detect-versions.outputs.no-changes == 'false'
needs: [detect-versions]
runs-on: ubuntu-latest
env:
PKG_VERSIONS: ${{ needs.detect-versions.outputs.pkg_versions }}
REGISTRY_VERSIONS: ${{ needs.detect-versions.outputs.registry_versions }}
HIGHEST_PKG_VERSION: ${{ needs.detect-versions.outputs.highest_pkg_version }}
HIGHEST_REGISTRY_VERSION: ${{ needs.detect-versions.outputs.highest_registry_version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Display version information
run: |
echo "Deploying package versions: $PKG_VERSIONS with highest package version: $HIGHEST_PKG_VERSION"
echo "Deploying registry versions: $REGISTRY_VERSIONS with highest registry version: $HIGHEST_REGISTRY_VERSION"
- name: Package schemas
run: |
# Make scripts executable
chmod +x ./scripts/package_schemas.sh
# Package schemas using the package_schemas.sh script
echo "Packaging schemas for release..."
./scripts/package_schemas.sh ./artifacts "$PKG_VERSIONS" "$REGISTRY_VERSIONS" "${{ github.sha }}"
- name: Create GitHub releases
run: |
# Make scripts executable
chmod +x ./scripts/create_releases.sh
# Create releases using the create_releases.sh script
echo "Creating GitHub releases..."
./scripts/create_releases.sh ./artifacts "$PKG_VERSIONS" "$REGISTRY_VERSIONS"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Configure GitHub Pages deployment
- name: Setup Pages
id: pages
uses: actions/configure-pages@v5
# Update the "latest" pointer in a minimal GitHub Pages site
- name: Prepare GitHub Pages content
run: |
# Make scripts executable
chmod +x ./scripts/generate_gh_pages.sh
# Generate the GitHub Pages content with our script
echo "Generating GitHub Pages content..."
./scripts/generate_gh_pages.sh ./gh-pages-content "$HIGHEST_PKG_VERSION" "$HIGHEST_REGISTRY_VERSION" "${{ github.repository }}"
- name: Upload GitHub Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: gh-pages-content
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
- name: Generate URLs for documentation
run: |
echo "Schema releases created and deployed!"
echo ""
echo "URLs for each version:"
# Get the package versions as an array
PKG_VERSIONS_ARRAY=$(echo $PKG_VERSIONS | jq -r '.[]')
# Report URLs for each package version
for VERSION in $PKG_VERSIONS_ARRAY; do
echo "Package Version $VERSION:"
echo "- Download: https://github.com/${{ github.repository }}/releases/download/schemas-package-$VERSION/schemas-package-$VERSION.zip"
done
# Get the registry versions as an array
REGISTRY_VERSIONS_ARRAY=$(echo $REGISTRY_VERSIONS | jq -r '.[]')
# Report URLs for each registry version
for VERSION in $REGISTRY_VERSIONS_ARRAY; do
echo "Registry Version $VERSION:"
echo "- Download: https://github.com/${{ github.repository }}/releases/download/schemas-registry-$VERSION/schemas-registry-$VERSION.zip"
done
echo ""
echo "Latest version pointers:"
echo "- Web: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/"
echo "- API: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/latest.json"
echo ""
echo "Direct schema URLs (always current):"
echo "- Package: https://raw.githubusercontent.com/${{ github.repository }}/main/package/$HIGHEST_PKG_VERSION/hatch_pkg_metadata_schema.json"
echo "- Registry: https://raw.githubusercontent.com/${{ github.repository }}/main/registry/$HIGHEST_REGISTRY_VERSION/hatch_all_pkg_metadata_schema.json"