mirror of
https://github.com/immich-app/immich.git
synced 2025-08-11 09:16:31 -04:00
fix: filter_names handling
This commit is contained in:
parent
7d22d5c9ed
commit
f7eeafb228
22
.github/actions/pre-job/action.yml
vendored
22
.github/actions/pre-job/action.yml
vendored
@ -44,30 +44,24 @@ runs:
|
|||||||
import os
|
import os
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
# Get the filters input
|
|
||||||
filters_yaml = os.environ['FILTERS']
|
filters_yaml = os.environ['FILTERS']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Parse YAML properly using the yaml library
|
|
||||||
filters_dict = yaml.safe_load(filters_yaml)
|
filters_dict = yaml.safe_load(filters_yaml)
|
||||||
|
|
||||||
if not isinstance(filters_dict, dict):
|
|
||||||
raise ValueError("Filters must be a YAML dictionary")
|
|
||||||
|
|
||||||
if not filters_dict:
|
if not filters_dict:
|
||||||
raise ValueError("No valid filters found")
|
raise ValueError("No valid filters found")
|
||||||
|
|
||||||
# We only need the filter names (keys), not the actual path arrays
|
if not isinstance(filters_dict, dict):
|
||||||
filter_names = {name: [] for name in filters_dict.keys()}
|
raise ValueError("Filters must be a YAML dictionary")
|
||||||
|
|
||||||
filters_json = json.dumps(filter_names)
|
# Just pass the filter names as a comma-separated string
|
||||||
|
filter_names = ','.join(filters_dict.keys())
|
||||||
|
|
||||||
print("Converted filters to JSON:")
|
print(f"Filter names: {filter_names}")
|
||||||
print(filters_json)
|
|
||||||
|
|
||||||
# Set GitHub Actions output
|
|
||||||
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
|
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
|
||||||
f.write(f"filters_json={filters_json}\n")
|
f.write(f"filter_names={filter_names}\n")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error converting filters: {e}")
|
print(f"Error converting filters: {e}")
|
||||||
@ -81,7 +75,7 @@ runs:
|
|||||||
force-branches: ${{ inputs.force-branches }}
|
force-branches: ${{ inputs.force-branches }}
|
||||||
exclude-branches: ${{ inputs.exclude-branches }}
|
exclude-branches: ${{ inputs.exclude-branches }}
|
||||||
skip-force-logic: ${{ inputs.skip-force-logic }}
|
skip-force-logic: ${{ inputs.skip-force-logic }}
|
||||||
filters-json: ${{ steps.convert-filters.outputs.filters_json }}
|
filters-json: ${{ steps.convert-filters.outputs.filter_names }}
|
||||||
script: |
|
script: |
|
||||||
const script = require('./.github/actions/pre-job/check-conditions.js')
|
const script = require('./.github/actions/pre-job/check-conditions.js')
|
||||||
script({ core, context })
|
script({ core, context })
|
||||||
@ -160,7 +154,7 @@ runs:
|
|||||||
id: generate-outputs
|
id: generate-outputs
|
||||||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
|
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
|
||||||
with:
|
with:
|
||||||
filters-json: ${{ steps.convert-filters.outputs.filters_json }}
|
filters-json: ${{ steps.convert-filters.outputs.filter_names }}
|
||||||
skip-force-logic: ${{ inputs.skip-force-logic }}
|
skip-force-logic: ${{ inputs.skip-force-logic }}
|
||||||
force-triggered: ${{ steps.check-conditions.outputs.force_triggered }}
|
force-triggered: ${{ steps.check-conditions.outputs.force_triggered }}
|
||||||
should-skip: ${{ steps.check-conditions.outputs.should_skip }}
|
should-skip: ${{ steps.check-conditions.outputs.should_skip }}
|
||||||
|
29
.github/actions/pre-job/check-conditions.js
vendored
29
.github/actions/pre-job/check-conditions.js
vendored
@ -20,13 +20,23 @@ module.exports = ({ core, context }) => {
|
|||||||
const skipForceLogic = core.getInput('skip-force-logic') === 'true';
|
const skipForceLogic = core.getInput('skip-force-logic') === 'true';
|
||||||
const filtersJson = core.getInput('filters-json');
|
const filtersJson = core.getInput('filters-json');
|
||||||
|
|
||||||
// Parse JSON filters (much more reliable than YAML parsing)
|
// Parse filter names from comma-separated string
|
||||||
let filterNames = [];
|
let filterNames = [];
|
||||||
try {
|
try {
|
||||||
const filters = JSON.parse(filtersJson);
|
if (!filtersJson || !filtersJson.trim()) {
|
||||||
filterNames = Object.keys(filters);
|
throw new Error('filters-json input is required and cannot be empty');
|
||||||
|
}
|
||||||
|
|
||||||
|
filterNames = filtersJson
|
||||||
|
.split(',')
|
||||||
|
.map((s) => s.trim())
|
||||||
|
.filter(Boolean);
|
||||||
|
|
||||||
|
if (filterNames.length === 0) {
|
||||||
|
throw new Error('No valid filter names found');
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(`Failed to parse filters JSON: ${error.message}`);
|
core.setFailed(`Failed to parse filter names: ${error.message}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,17 +62,6 @@ module.exports = ({ core, context }) => {
|
|||||||
skipForceLogic,
|
skipForceLogic,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Validate inputs
|
|
||||||
if (!filtersJson || !filtersJson.trim()) {
|
|
||||||
core.setFailed('filters-json input is required and cannot be empty');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filterNames.length === 0) {
|
|
||||||
core.setFailed('No valid filters found in filters-json input');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 1: Check exclusion conditions (fastest short-circuit)
|
// Step 1: Check exclusion conditions (fastest short-circuit)
|
||||||
const shouldSkip = excludeBranches.some(
|
const shouldSkip = excludeBranches.some(
|
||||||
(branch) => currentHeadRef === branch,
|
(branch) => currentHeadRef === branch,
|
||||||
|
18
.github/actions/pre-job/generate-outputs.js
vendored
18
.github/actions/pre-job/generate-outputs.js
vendored
@ -34,13 +34,23 @@ module.exports = ({ core }) => {
|
|||||||
console.log('No main path results or parse error:', e.message);
|
console.log('No main path results or parse error:', e.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse JSON filters (much more reliable than YAML parsing)
|
// Parse filter names from comma-separated string
|
||||||
let filterNames = [];
|
let filterNames = [];
|
||||||
try {
|
try {
|
||||||
const filters = JSON.parse(filtersJson);
|
if (!filtersJson || !filtersJson.trim()) {
|
||||||
filterNames = Object.keys(filters);
|
throw new Error('filters-json input is required and cannot be empty');
|
||||||
|
}
|
||||||
|
|
||||||
|
filterNames = filtersJson
|
||||||
|
.split(',')
|
||||||
|
.map((s) => s.trim())
|
||||||
|
.filter(Boolean);
|
||||||
|
|
||||||
|
if (filterNames.length === 0) {
|
||||||
|
throw new Error('No valid filter names found');
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(`Failed to parse filters JSON: ${error.message}`);
|
core.setFailed(`Failed to parse filter names: ${error.message}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user