|
| 1 | +name: Build Changed Packages |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: |
| 8 | + - 'binaries/**/*.yaml' |
| 9 | + - 'packages/**/*.yaml' |
| 10 | + pull_request: |
| 11 | + types: [closed] |
| 12 | + branches: |
| 13 | + - main |
| 14 | + workflow_dispatch: |
| 15 | + inputs: |
| 16 | + recipe_path: |
| 17 | + description: 'Specific recipe path to build (e.g., binaries/hello/static.yaml)' |
| 18 | + type: string |
| 19 | + default: '' |
| 20 | + force_rebuild: |
| 21 | + description: 'Force rebuild even if hash unchanged' |
| 22 | + type: boolean |
| 23 | + default: true |
| 24 | + |
| 25 | +concurrency: |
| 26 | + group: build-${{ github.ref }} |
| 27 | + cancel-in-progress: false |
| 28 | + |
| 29 | +jobs: |
| 30 | + detect-changes: |
| 31 | + if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true) |
| 32 | + runs-on: ubuntu-latest |
| 33 | + outputs: |
| 34 | + changed_recipes: ${{ steps.detect.outputs.changed_recipes }} |
| 35 | + has_changes: ${{ steps.detect.outputs.has_changes }} |
| 36 | + steps: |
| 37 | + - name: Checkout repository |
| 38 | + uses: actions/checkout@v4 |
| 39 | + with: |
| 40 | + fetch-depth: 2 |
| 41 | + |
| 42 | + - name: Detect changed recipes |
| 43 | + id: detect |
| 44 | + run: | |
| 45 | + mkdir -p /tmp/changes |
| 46 | + CHANGED_RECIPES="[]" |
| 47 | +
|
| 48 | + if [ -n "${{ inputs.recipe_path }}" ]; then |
| 49 | + # Manual trigger with specific recipe |
| 50 | + if [ -f "${{ inputs.recipe_path }}" ]; then |
| 51 | + RECIPE="${{ inputs.recipe_path }}" |
| 52 | + CHANGED_RECIPES=$(jq -n --arg path "$RECIPE" '[{"path": $path}]') |
| 53 | + else |
| 54 | + echo "::error::Recipe not found: ${{ inputs.recipe_path }}" |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | + else |
| 58 | + # Detect changes from git diff |
| 59 | + if [ "${{ github.event_name }}" == "push" ]; then |
| 60 | + CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD -- 'binaries/**/*.yaml' 'packages/**/*.yaml' 2>/dev/null || true) |
| 61 | + elif [ "${{ github.event_name }}" == "pull_request" ]; then |
| 62 | + CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- 'binaries/**/*.yaml' 'packages/**/*.yaml' 2>/dev/null || true) |
| 63 | + else |
| 64 | + CHANGED_FILES="" |
| 65 | + fi |
| 66 | +
|
| 67 | + echo "Changed files:" |
| 68 | + echo "$CHANGED_FILES" |
| 69 | +
|
| 70 | + # Build JSON array of changed recipes |
| 71 | + for file in $CHANGED_FILES; do |
| 72 | + if [ -f "$file" ]; then |
| 73 | + CHANGED_RECIPES=$(echo "$CHANGED_RECIPES" | jq --arg path "$file" '. + [{"path": $path}]') |
| 74 | + fi |
| 75 | + done |
| 76 | + fi |
| 77 | +
|
| 78 | + # Output results |
| 79 | + RECIPE_COUNT=$(echo "$CHANGED_RECIPES" | jq 'length') |
| 80 | + echo "Found $RECIPE_COUNT recipes to build" |
| 81 | + echo "$CHANGED_RECIPES" | jq . |
| 82 | +
|
| 83 | + # Save to outputs |
| 84 | + echo "changed_recipes=$(echo "$CHANGED_RECIPES" | jq -c .)" >> $GITHUB_OUTPUT |
| 85 | +
|
| 86 | + if [ "$RECIPE_COUNT" -gt 0 ]; then |
| 87 | + echo "has_changes=true" >> $GITHUB_OUTPUT |
| 88 | + else |
| 89 | + echo "has_changes=false" >> $GITHUB_OUTPUT |
| 90 | + fi |
| 91 | +
|
| 92 | + build: |
| 93 | + needs: detect-changes |
| 94 | + if: needs.detect-changes.outputs.has_changes == 'true' |
| 95 | + strategy: |
| 96 | + fail-fast: false |
| 97 | + max-parallel: 4 |
| 98 | + matrix: |
| 99 | + recipe: ${{ fromJson(needs.detect-changes.outputs.changed_recipes) }} |
| 100 | + uses: ./.github/workflows/matrix_builds.yaml |
| 101 | + with: |
| 102 | + sbuild-url: "https://raw.githubusercontent.com/${{ github.repository }}/refs/heads/main/${{ matrix.recipe.path }}" |
| 103 | + ghcr-url: ${{ contains(matrix.recipe.path, 'packages/') && 'ghcr.io/pkgforge/pkgcache-test' || 'ghcr.io/pkgforge/bincache-test' }} |
| 104 | + pkg-family: ${{ github.event.repository.name }} |
| 105 | + rebuild: true |
| 106 | + logs: true |
| 107 | + secrets: inherit |
0 commit comments