Refactor Aspose.OCR #196
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: Build All Projects | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| branches: [ main, develop ] | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '0 6 * * *' # daily at 6 AM UTC | |
| env: | |
| DOTNET_VERSION: '9.0.x' | |
| DOTNET_NOLOGO: true | |
| DOTNET_CLI_TELEMETRY_OPTOUT: true | |
| jobs: | |
| check-ivy-version: | |
| name: Check Ivy Version | |
| runs-on: ubuntu-latest | |
| outputs: | |
| should-build: ${{ steps.version-check.outputs.should-build }} | |
| current-version: ${{ steps.version-check.outputs.current-version }} | |
| latest-version: ${{ steps.version-check.outputs.latest-version }} | |
| version-changed: ${{ steps.version-check.outputs.version-changed }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ github.repository }} | |
| ref: ${{ github.ref }} | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Check Ivy version | |
| id: version-check | |
| run: | | |
| echo "🔍 Checking latest Ivy version on NuGet..." | |
| latest_version=$(curl -s "https://api.nuget.org/v3-flatcontainer/ivy/index.json" | jq -r '.versions | last') | |
| echo "Latest Ivy version: $latest_version" | |
| current_version="wildcard" | |
| version_changed="false" | |
| should_build="false" | |
| if [ "${{ github.event_name }}" == "schedule" ]; then | |
| last_known_version_file=".github/last-ivy-version.txt" | |
| last_known_version="" | |
| if [ -f "$last_known_version_file" ]; then | |
| last_known_version=$(cat "$last_known_version_file") | |
| echo "Last known Ivy version: $last_known_version" | |
| else | |
| echo "No previous version record found" | |
| fi | |
| if [ -z "$last_known_version" ] || [ "$last_known_version" != "$latest_version" ]; then | |
| echo "🆕 New Ivy version detected!" | |
| should_build="true" | |
| version_changed="true" | |
| echo "$latest_version" > "$last_known_version_file" | |
| else | |
| echo "✅ No new Ivy version since last check" | |
| fi | |
| fi | |
| if [ "${{ github.event_name }}" == "push" ] || [ "${{ github.event_name }}" == "pull_request" ] || [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
| should_build="true" | |
| echo "🔄 Code change detected - will build" | |
| echo "$latest_version" > ".github/last-ivy-version.txt" | |
| fi | |
| echo "should-build=$should_build" >> $GITHUB_OUTPUT | |
| echo "current-version=$current_version" >> $GITHUB_OUTPUT | |
| echo "latest-version=$latest_version" >> $GITHUB_OUTPUT | |
| echo "version-changed=$version_changed" >> $GITHUB_OUTPUT | |
| discover-projects: | |
| name: Discover Projects | |
| runs-on: ubuntu-latest | |
| needs: check-ivy-version | |
| if: needs.check-ivy-version.outputs.should-build == 'true' | |
| outputs: | |
| projects: ${{ steps.find-projects.outputs.projects }} | |
| project-count: ${{ steps.find-projects.outputs.project-count }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }} | |
| ref: ${{ github.head_ref || github.ref_name }} | |
| - name: Find all .NET projects | |
| id: find-projects | |
| run: | | |
| projects=$(find . -name "*.csproj" -not -path "*/bin/*" -not -path "*/obj/*" | sort) | |
| project_array="[" | |
| first=true | |
| while IFS= read -r project; do | |
| if [ "$first" = true ]; then | |
| first=false | |
| else | |
| project_array="$project_array," | |
| fi | |
| dir_name=$(dirname "$project" | xargs basename) | |
| project_array="$project_array{\"path\":\"$project\",\"name\":\"$dir_name\"}" | |
| done <<< "$projects" | |
| project_array="$project_array]" | |
| project_count=$(echo "$projects" | wc -l) | |
| echo "projects=$project_array" >> $GITHUB_OUTPUT | |
| echo "project-count=$project_count" >> $GITHUB_OUTPUT | |
| build-projects: | |
| name: Build | |
| runs-on: ubuntu-latest | |
| needs: [check-ivy-version, discover-projects] | |
| if: needs.check-ivy-version.outputs.should-build == 'true' && needs.discover-projects.outputs.project-count > 0 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| project: ${{ fromJson(needs.discover-projects.outputs.projects) }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }} | |
| ref: ${{ github.head_ref || github.ref_name }} | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Display .NET info | |
| run: dotnet --info | |
| - name: Cache NuGet packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.nuget/packages | |
| key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} | |
| restore-keys: | | |
| ${{ runner.os }}-nuget- | |
| - name: Restore dependencies | |
| run: dotnet restore "${{ matrix.project.path }}" | |
| - name: Build project | |
| run: | | |
| echo "🔨 Building: ${{ matrix.project.name }}" | |
| dotnet build "${{ matrix.project.path }}" \ | |
| --configuration Release \ | |
| --no-restore \ | |
| --verbosity normal | |
| - name: Upload build artifacts (on failure) | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: build-logs-${{ matrix.project.name }} | |
| path: | | |
| **/bin/**/*.log | |
| **/obj/**/*.log | |
| retention-days: 7 | |
| detect-resolved-version: | |
| name: Detect Resolved Ivy Version | |
| runs-on: ubuntu-latest | |
| needs: [check-ivy-version, build-projects] | |
| if: needs.check-ivy-version.outputs.should-build == 'true' && (success() || failure()) | |
| outputs: | |
| resolved-version: ${{ steps.get-version.outputs.resolved-version }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }} | |
| ref: ${{ github.head_ref || github.ref_name }} | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Get resolved Ivy version | |
| id: get-version | |
| run: | | |
| echo "🔍 Determining resolved Ivy version from packages..." | |
| project_file=$(find . -name "*.csproj" -not -path "*/bin/*" -not -path "*/obj/*" | head -1) | |
| if [ -n "$project_file" ]; then | |
| dotnet restore "$project_file" --verbosity quiet | |
| project_dir=$(dirname "$project_file") | |
| assets_file="$project_dir/obj/project.assets.json" | |
| if [ -f "$assets_file" ]; then | |
| # Extract Ivy version from project.assets.json | |
| # 1. Look at .libraries | |
| # 2. Filter entries where key starts with "Ivy/" | |
| # 3. Split key on "/" and take version part | |
| resolved_version=$(jq -r '.libraries | to_entries[] | select(.key | startswith("Ivy/")) | .key | split("/")[1]' "$assets_file" | head -1) | |
| if [ -n "$resolved_version" ] && [ "$resolved_version" != "null" ]; then | |
| echo "resolved-version=$resolved_version" >> $GITHUB_OUTPUT | |
| else | |
| echo "resolved-version=${{ needs.check-ivy-version.outputs.latest-version }}" >> $GITHUB_OUTPUT | |
| fi | |
| else | |
| echo "resolved-version=${{ needs.check-ivy-version.outputs.latest-version }}" >> $GITHUB_OUTPUT | |
| fi | |
| else | |
| echo "resolved-version=unknown" >> $GITHUB_OUTPUT | |
| fi | |
| build-summary: | |
| name: Build Summary | |
| runs-on: ubuntu-latest | |
| needs: [check-ivy-version, discover-projects, build-projects, detect-resolved-version] | |
| if: always() && needs.check-ivy-version.outputs.should-build == 'true' | |
| steps: | |
| - name: Generate build summary | |
| run: | | |
| echo "# 🚀 Ivy-Examples Build Summary" >> $GITHUB_STEP_SUMMARY | |
| resolved_version="${{ needs.detect-resolved-version.outputs.resolved-version }}" | |
| latest_version="${{ needs.check-ivy-version.outputs.latest-version }}" | |
| echo "## 📦 Ivy Version Information" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Resolved Version:** $resolved_version" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Latest Available:** $latest_version" >> $GITHUB_STEP_SUMMARY | |
| echo "**Total Projects:** ${{ needs.discover-projects.outputs.project-count }}" >> $GITHUB_STEP_SUMMARY | |
| - name: Set workflow status | |
| run: | | |
| if [ "${{ needs.build-projects.result }}" != "success" ]; then | |
| echo "❌ Build workflow failed" | |
| exit 1 | |
| else | |
| echo "✅ Build workflow succeeded" | |
| fi | |
| create-badge: | |
| name: Update Build Badge | |
| runs-on: ubuntu-latest | |
| needs: [check-ivy-version, build-summary, detect-resolved-version] | |
| if: github.ref == 'refs/heads/main' && always() && needs.check-ivy-version.outputs.should-build == 'true' | |
| steps: | |
| - name: Create build status badge | |
| run: | | |
| if [ "${{ needs.build-summary.result }}" == "success" ]; then | |
| echo "Build passing" | |
| else | |
| echo "Build failing" | |
| fi |