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 yaml
|
||||
|
||||
# Get the filters input
|
||||
filters_yaml = os.environ['FILTERS']
|
||||
|
||||
try:
|
||||
# Parse YAML properly using the yaml library
|
||||
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:
|
||||
raise ValueError("No valid filters found")
|
||||
|
||||
# We only need the filter names (keys), not the actual path arrays
|
||||
filter_names = {name: [] for name in filters_dict.keys()}
|
||||
if not isinstance(filters_dict, dict):
|
||||
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(filters_json)
|
||||
print(f"Filter names: {filter_names}")
|
||||
|
||||
# Set GitHub Actions output
|
||||
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:
|
||||
print(f"Error converting filters: {e}")
|
||||
@ -81,7 +75,7 @@ runs:
|
||||
force-branches: ${{ inputs.force-branches }}
|
||||
exclude-branches: ${{ inputs.exclude-branches }}
|
||||
skip-force-logic: ${{ inputs.skip-force-logic }}
|
||||
filters-json: ${{ steps.convert-filters.outputs.filters_json }}
|
||||
filters-json: ${{ steps.convert-filters.outputs.filter_names }}
|
||||
script: |
|
||||
const script = require('./.github/actions/pre-job/check-conditions.js')
|
||||
script({ core, context })
|
||||
@ -160,7 +154,7 @@ runs:
|
||||
id: generate-outputs
|
||||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
|
||||
with:
|
||||
filters-json: ${{ steps.convert-filters.outputs.filters_json }}
|
||||
filters-json: ${{ steps.convert-filters.outputs.filter_names }}
|
||||
skip-force-logic: ${{ inputs.skip-force-logic }}
|
||||
force-triggered: ${{ steps.check-conditions.outputs.force_triggered }}
|
||||
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 filtersJson = core.getInput('filters-json');
|
||||
|
||||
// Parse JSON filters (much more reliable than YAML parsing)
|
||||
// Parse filter names from comma-separated string
|
||||
let filterNames = [];
|
||||
try {
|
||||
const filters = JSON.parse(filtersJson);
|
||||
filterNames = Object.keys(filters);
|
||||
if (!filtersJson || !filtersJson.trim()) {
|
||||
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) {
|
||||
core.setFailed(`Failed to parse filters JSON: ${error.message}`);
|
||||
core.setFailed(`Failed to parse filter names: ${error.message}`);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -52,17 +62,6 @@ module.exports = ({ core, context }) => {
|
||||
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)
|
||||
const shouldSkip = excludeBranches.some(
|
||||
(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);
|
||||
}
|
||||
|
||||
// Parse JSON filters (much more reliable than YAML parsing)
|
||||
// Parse filter names from comma-separated string
|
||||
let filterNames = [];
|
||||
try {
|
||||
const filters = JSON.parse(filtersJson);
|
||||
filterNames = Object.keys(filters);
|
||||
if (!filtersJson || !filtersJson.trim()) {
|
||||
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) {
|
||||
core.setFailed(`Failed to parse filters JSON: ${error.message}`);
|
||||
core.setFailed(`Failed to parse filter names: ${error.message}`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user