Skip to content

Commit c3a9cdd

Browse files
committed
hotfix action
1 parent f66b7dc commit c3a9cdd

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

.github/actions/determine-packages/action.yml

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,27 @@ outputs:
3333
runs:
3434
using: "composite"
3535
steps:
36-
# 0. Setup - Install dependencies (yq)
37-
- name: Install yq
36+
# 0. Setup - Install dependencies (yq & jq)
37+
- name: Install yq and jq
3838
shell: bash
3939
run: |
40-
echo "::group::Install yq"
41-
if ! command -v yq &> /dev/null
42-
then
40+
echo "::group::Install yq & jq"
41+
# Install yq
42+
if ! command -v yq &> /dev/null; then
4343
echo "yq not found. Installing..."
4444
sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq && sudo chmod +x /usr/bin/yq
4545
echo "yq installed successfully to $(command -v yq)"
4646
else
4747
echo "yq already installed at $(command -v yq)"
4848
fi
49+
# Install jq
50+
if ! command -v jq &> /dev/null; then
51+
echo "jq not found. Installing..."
52+
sudo apt-get update && sudo apt-get install -y jq
53+
echo "jq installed successfully to $(command -v jq)"
54+
else
55+
echo "jq already installed at $(command -v jq)"
56+
fi
4957
echo "::endgroup::"
5058
5159
# 1. Handle workflow_dispatch trigger
@@ -132,35 +140,49 @@ runs:
132140
with:
133141
filters: ${{ steps.generate-filter.outputs.filters }}
134142

143+
# 4. Handle push trigger - Set Matrix (Modified)
135144
- name: Set Matrix based on Changes (Push Only)
136145
id: set-matrix-push
137146
if: inputs.event_name == 'push'
138147
shell: bash
148+
# Added env context to pass outputs object as JSON
149+
env:
150+
CHANGES_OUTPUTS: ${{ toJSON(steps.changes.outputs) }}
151+
PACKAGES_CONFIG: ${{ inputs.packages_config }}
139152
run: |
140-
packages_config_yaml='${{ inputs.packages_config }}'
153+
packages_config_yaml="$PACKAGES_CONFIG" # Use env var
154+
changes_outputs_json="$CHANGES_OUTPUTS" # Use env var
141155
declare -a packages
142156
# Extract package names
143157
package_names=$(echo "$packages_config_yaml" | yq '[.packages | keys] | .[]')
144158
159+
echo "Checking for changes in packages: $package_names"
160+
echo "Paths filter outputs: $changes_outputs_json"
161+
145162
for pkg in $package_names; do
146-
# Check the output of the paths-filter step for this package
147-
# Simplified check using direct context access
148-
if [[ "${{ steps.changes.outputs.${pkg} }}" == "true" ]]; then
163+
# Use jq to query the JSON outputs using the shell variable 'pkg' as the key
164+
filter_output=$(echo "$changes_outputs_json" | jq -r --arg key "$pkg" '.[$key]')
165+
166+
echo "Checking package: $pkg -> Filter output: $filter_output"
167+
# Compare the extracted value
168+
if [[ "$filter_output" == "true" ]]; then
169+
echo " -> Adding $pkg to matrix"
149170
packages+=("\"$pkg\"") # Add package name with quotes
150171
fi
151172
done
152173
153174
# Join array elements with comma, wrap in brackets for JSON
154-
# Works even if array is empty (produces '[]')
155-
packages_json=$(printf ',%s' "${packages[@]}")
175+
packages_json=$(printf ",%s" "${packages[@]}")
156176
packages_json="[${packages_json:1}]"
177+
# Ensure output is '[]' if no packages matched
178+
if [[ "${#packages[@]}" -eq 0 ]]; then
179+
packages_json="[]"
180+
fi
157181
182+
echo "Final packages_json: $packages_json"
158183
echo "packages_json=${packages_json}" >> $GITHUB_OUTPUT
159-
# Install yq for YAML parsing (needs to be done only once if runner reused)
160-
# echo "::add-matcher::${{ runner.tool_cache }}/yq.json"
161-
# sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq && sudo chmod +x /usr/bin/yq
162184
163-
# 3. Finalize Matrix Output
185+
# 5. Finalize Matrix Output
164186
- name: Finalize Matrix Output
165187
id: set-matrix # This step sets the final action output
166188
shell: bash

0 commit comments

Comments
 (0)