feat: add a script for generate a DocC documentation #9
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test Action | |
| on: | |
| pull_request: | |
| branches: [main] | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| jobs: | |
| test-single-scheme: | |
| name: Test Single Scheme | |
| runs-on: macos-latest | |
| steps: | |
| - name: Checkout action repo | |
| uses: actions/checkout@v4 | |
| with: | |
| path: docc-action | |
| - name: Create test Swift project | |
| run: | | |
| swift package init --type library --name TestLib | |
| cat > Sources/TestLib/TestLib.swift << 'EOF' | |
| /// A test library for DocC generation | |
| /// | |
| /// This library demonstrates DocC documentation generation. | |
| public struct TestLib { | |
| /// Creates a new instance | |
| public init() {} | |
| /// A test function | |
| /// - Returns: A greeting string | |
| public func greet() -> String { | |
| return "Hello, DocC!" | |
| } | |
| } | |
| EOF | |
| - name: Build Documentation | |
| uses: ./docc-action | |
| with: | |
| schemes: '["TestLib"]' | |
| version: 'v1.0.0' | |
| keep-old-versions: 'false' | |
| - name: Verify Output | |
| run: | | |
| echo "📋 Checking documentation structure..." | |
| if [ ! -d "docs/v1.0.0/TestLib" ]; then | |
| echo "❌ Documentation directory not found" | |
| exit 1 | |
| fi | |
| if [ ! -f "docs/v1.0.0/TestLib/index.html" ]; then | |
| echo "❌ index.html not found" | |
| exit 1 | |
| fi | |
| if [ ! -d "docs/v1.0.0/TestLib/documentation" ]; then | |
| echo "❌ documentation directory not found" | |
| exit 1 | |
| fi | |
| echo "✅ Single scheme test passed" | |
| echo "📁 Generated structure:" | |
| tree -L 4 docs/ || find docs/ -type f | head -20 | |
| test-version-preservation: | |
| name: Test Version Preservation | |
| runs-on: macos-latest | |
| steps: | |
| - name: Checkout action repo | |
| uses: actions/checkout@v4 | |
| with: | |
| path: action | |
| - name: Create test project | |
| run: | | |
| swift package init --type library --name VersionTest | |
| cat > Sources/VersionTest/VersionTest.swift << 'EOF' | |
| /// Version test library | |
| public struct VersionTest { | |
| public init() {} | |
| public func version() -> String { return "1.0" } | |
| } | |
| EOF | |
| - name: Build v1.0.0 Documentation | |
| uses: ./action | |
| with: | |
| schemes: '["VersionTest"]' | |
| version: 'v1.0.0' | |
| keep-old-versions: 'false' | |
| - name: Verify v1.0.0 | |
| run: | | |
| if [ ! -d "docs/v1.0.0/VersionTest" ]; then | |
| echo "❌ v1.0.0 not found" | |
| exit 1 | |
| fi | |
| echo "✅ v1.0.0 created" | |
| - name: Update source code | |
| run: | | |
| cat > Sources/VersionTest/VersionTest.swift << 'EOF' | |
| /// Version test library (updated) | |
| public struct VersionTest { | |
| public init() {} | |
| public func version() -> String { return "2.0" } | |
| /// New feature in v2 | |
| public func newFeature() -> String { return "New!" } | |
| } | |
| EOF | |
| - name: Build v2.0.0 Documentation | |
| uses: ./action | |
| with: | |
| schemes: '["VersionTest"]' | |
| version: 'v2.0.0' | |
| keep-old-versions: 'true' | |
| - name: Verify Both Versions Exist | |
| run: | | |
| echo "📋 Checking version preservation..." | |
| if [ ! -d "docs/v1.0.0/VersionTest" ]; then | |
| echo "❌ v1.0.0 was deleted!" | |
| exit 1 | |
| fi | |
| echo "✅ v1.0.0 preserved" | |
| if [ ! -d "docs/v2.0.0/VersionTest" ]; then | |
| echo "❌ v2.0.0 not created" | |
| exit 1 | |
| fi | |
| echo "✅ v2.0.0 created" | |
| echo "📁 Version structure:" | |
| ls -la docs/ | |
| echo "✅ Version preservation test passed" | |
| test-no-version-preservation: | |
| name: Test Without Version Preservation | |
| runs-on: macos-latest | |
| steps: | |
| - name: Checkout action repo | |
| uses: actions/checkout@v4 | |
| with: | |
| path: action | |
| - name: Create test project | |
| run: | | |
| swift package init --type library --name NoPreserve | |
| - name: Create fake old docs | |
| run: | | |
| mkdir -p docs/v0.9.0/NoPreserve | |
| echo "old version" > docs/v0.9.0/NoPreserve/index.html | |
| - name: Build new version WITHOUT preservation | |
| uses: ./action | |
| with: | |
| schemes: '["NoPreserve"]' | |
| version: 'v1.0.0' | |
| keep-old-versions: 'false' | |
| - name: Verify old version is gone | |
| run: | | |
| if [ -d "docs/v0.9.0" ]; then | |
| echo "❌ Old version should be deleted when keep-old-versions=false" | |
| exit 1 | |
| fi | |
| if [ ! -d "docs/v1.0.0/NoPreserve" ]; then | |
| echo "❌ New version not created" | |
| exit 1 | |
| fi | |
| echo "✅ Correctly deleted old versions" | |
| test-summary: | |
| name: Test Summary | |
| needs: [test-single-scheme, test-version-preservation, test-no-version-preservation] | |
| runs-on: ubuntu-latest | |
| if: always() | |
| steps: | |
| - name: Generate Summary | |
| run: | | |
| echo "# 📊 Test Results" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "| Test | Status |" >> $GITHUB_STEP_SUMMARY | |
| echo "|------|--------|" >> $GITHUB_STEP_SUMMARY | |
| echo "| Single Scheme | ${{ needs.test-single-scheme.result }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Version Preservation | ${{ needs.test-version-preservation.result }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| No Preservation | ${{ needs.test-no-version-preservation.result }} |" >> $GITHUB_STEP_SUMMARY | |
| # Проверяем, все ли тесты прошли | |
| if [ "${{ needs.test-single-scheme.result }}" == "success" ] && \ | |
| [ "${{ needs.test-version-preservation.result }}" == "success" ] && \ | |
| [ "${{ needs.test-no-version-preservation.result }}" == "success" ]; then | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "## ✅ All tests passed!" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "## ❌ Some tests failed" >> $GITHUB_STEP_SUMMARY | |
| exit 1 | |
| fi |