php-fpm: guess we're using javascript now, that can't go wrong
This commit is contained in:
91
.github/workflows/php-fpm.yml
vendored
91
.github/workflows/php-fpm.yml
vendored
@@ -29,14 +29,7 @@ jobs:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # Fetch all history for accurate change detection
|
||||
|
||||
- name: Get all PHP lanes
|
||||
id: get-lanes
|
||||
run: |
|
||||
lanes=$(find php-fpm -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | jq -R . | jq -s .)
|
||||
echo "lanes=$lanes" >> $GITHUB_OUTPUT
|
||||
shell: bash
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Get changed files
|
||||
id: changed-files
|
||||
@@ -47,51 +40,61 @@ jobs:
|
||||
shared/php-fpm/**
|
||||
.github/workflows/php-fpm.yml
|
||||
|
||||
- name: Determine lanes to build
|
||||
id: set-matrix
|
||||
shell: bash
|
||||
- name: Get all PHP lanes
|
||||
id: get-lanes
|
||||
run: |
|
||||
all_lanes='${{ steps.get-lanes.outputs.lanes }}'
|
||||
req_lane="${{ github.event.inputs.lane }}"
|
||||
changed_files="${{ steps.changed-files.outputs.all_changed_files }}"
|
||||
echo "lanes=$(find php-fpm -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | jq -R . | jq -s .)" >> $GITHUB_OUTPUT
|
||||
shell: bash
|
||||
|
||||
lanes_to_build="[]"
|
||||
build_all=false
|
||||
- name: Get changed PHP lanes
|
||||
id: changed-lanes
|
||||
run: |
|
||||
changed_lanes=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep '^php-fpm/' | cut -d'/' -f2 | sort -u | jq -R . | jq -s 'if . == [] then [] else . end')
|
||||
echo "lanes=${changed_lanes:-[]}" >> $GITHUB_OUTPUT
|
||||
shell: bash
|
||||
|
||||
# 1. Handle workflow_dispatch input
|
||||
if [[ -n "$req_lane" ]]; then
|
||||
if [[ "$req_lane" == "all" ]]; then
|
||||
build_all=true
|
||||
else
|
||||
lanes_to_build="[\"$req_lane\"]"
|
||||
- name: Check for changes requiring all lanes to be built
|
||||
id: build-all-check
|
||||
run: |
|
||||
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
|
||||
if [[ "$file" == ".github/workflows/php-fpm.yml" || "$file" == shared/php-fpm/* ]]; then
|
||||
echo "build_all=true" >> $GITHUB_OUTPUT
|
||||
exit 0
|
||||
fi
|
||||
else
|
||||
# 2. Check for changes that trigger a full rebuild
|
||||
for file in $changed_files; do
|
||||
if [[ "$file" == ".github/workflows/php-fpm.yml" || "$file" == shared/php-fpm/* ]]; then
|
||||
build_all=true
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
done
|
||||
echo "build_all=false" >> $GITHUB_OUTPUT
|
||||
shell: bash
|
||||
|
||||
# 3. Build matrix based on flags
|
||||
if [[ "$build_all" == true ]]; then
|
||||
lanes_to_build="$all_lanes"
|
||||
elif [[ -n "$changed_files" && "$lanes_to_build" == "[]" ]]; then
|
||||
# 4. If not a full build, determine changed lanes
|
||||
lanes=$(echo "$changed_files" | tr ' ' '\n' | grep '^php-fpm/' | cut -d'/' -f2 | sort -u | jq -R . | jq -s .)
|
||||
if [[ -n "$lanes" && "$lanes" != "[]" ]]; then
|
||||
lanes_to_build="$lanes"
|
||||
fi
|
||||
fi
|
||||
- name: Generate matrix for build job
|
||||
id: set-matrix
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const req_lane = "${{ github.event.inputs.lane }}";
|
||||
const build_all = ${{ steps.build-all-check.outputs.build_all }};
|
||||
const all_lanes = JSON.parse('${{ steps.get-lanes.outputs.lanes }}');
|
||||
const changed_lanes = JSON.parse('${{ steps.changed-lanes.outputs.lanes }}');
|
||||
|
||||
matrix="{\"lane\":$lanes_to_build}"
|
||||
echo "matrix=$matrix" >> $GITHUB_OUTPUT
|
||||
let lanes_to_build = [];
|
||||
|
||||
if (req_lane) {
|
||||
if (req_lane === "all") {
|
||||
lanes_to_build = all_lanes;
|
||||
} else {
|
||||
lanes_to_build = [req_lane];
|
||||
}
|
||||
} else if (build_all) {
|
||||
lanes_to_build = all_lanes;
|
||||
} else {
|
||||
lanes_to_build = changed_lanes;
|
||||
}
|
||||
|
||||
return { lane: lanes_to_build };
|
||||
result-encoding: json
|
||||
|
||||
build:
|
||||
needs: lanes
|
||||
if: ${{ needs.lanes.outputs.matrix != '{"lane":[]}' }}
|
||||
if: ${{ needs.lanes.outputs.matrix.lane[0] }}
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
|
||||
Reference in New Issue
Block a user