19
19
name : Process Raw CSV Files
20
20
runs-on : self-hosted
21
21
outputs :
22
- sub : ${{ steps.set_vars.outputs.sub }}
23
- task : ${{ steps.set_vars.outputs.task }}
24
- version : ${{ steps.set_vars.outputs.version }}
25
- run_part : ${{ steps.set_vars.outputs.run_part }}
22
+ data : ${{ steps.set_vars.outputs.json }}
26
23
27
24
steps :
28
25
- name : Checkout Code
@@ -47,14 +44,13 @@ jobs:
47
44
echo "Changed CSV files in the last 24 hours:"
48
45
echo "$formatted_data"
49
46
50
-
51
- - name : Install Python Dependencies
52
- run : |
53
- python -m pip install --upgrade pip
54
-
55
47
- name : Parse Raw CSV Files
56
48
id : set_vars
57
49
run : |
50
+ # Initialize an empty JSON array
51
+ json_array="["
52
+ first_item=true
53
+
58
54
# Loop through each CSV file in $data
59
55
for file in $data; do
60
56
# Extract the directory and filename
@@ -68,11 +64,22 @@ jobs:
68
64
IFS='_' read -r sub task version <<< "$filename"
69
65
version="${version%.csv}" # Remove the .csv extension from version
70
66
71
- # Set outputs
72
- echo "::set-output name=run_part::$run_part"
73
- echo "::set-output name=sub::$sub"
74
- echo "::set-output name=task::$task"
75
- echo "::set-output name=version::$version"
67
+ # Escape variables for JSON
68
+ sub_escaped=$(printf '%s' "$sub" | sed 's/"/\\"/g')
69
+ task_escaped=$(printf '%s' "$task" | sed 's/"/\\"/g')
70
+ version_escaped=$(printf '%s' "$version" | sed 's/"/\\"/g')
71
+ run_part_escaped=$(printf '%s' "$run_part" | sed 's/"/\\"/g')
72
+
73
+ # Build JSON object
74
+ json_object="{\"sub\":\"$sub_escaped\",\"task\":\"$task_escaped\",\"version\":\"$version_escaped\",\"run_part\":\"$run_part_escaped\"}"
75
+
76
+ # Append to JSON array
77
+ if [ "$first_item" = true ]; then
78
+ json_array="$json_array$json_object"
79
+ first_item=false
80
+ else
81
+ json_array="$json_array,$json_object"
82
+ fi
76
83
77
84
# Print the extracted values
78
85
echo "Run Part: $run_part"
@@ -81,21 +88,29 @@ jobs:
81
88
echo "Version: $version"
82
89
done
83
90
91
+ json_array="$json_array]"
92
+
93
+ # Output the JSON array
94
+ echo "json=$json_array" >> $GITHUB_OUTPUT
95
+
84
96
run_qc :
85
97
name : Run Quality Control
86
98
runs-on : self-hosted
87
99
needs : process_raw
100
+ strategy :
101
+ matrix :
102
+ config : ${{ fromJson(needs.process_raw.outputs.data) }}
88
103
89
104
steps :
90
105
- name : Checkout Code
91
106
uses : actions/checkout@v3
92
107
93
108
- name : Debug Environment Variables
94
109
run : |
95
- echo "Subject: ${{ needs.process_raw.outputs .sub }}"
96
- echo "Task: ${{ needs.process_raw.outputs .task }}"
97
- echo "Version: ${{ needs.process_raw.outputs .version }}"
98
- echo "Run Part: ${{ needs.process_raw.outputs .run_part }}"
110
+ echo "Subject: ${{ matrix.config .sub }}"
111
+ echo "Task: ${{ matrix.config .task }}"
112
+ echo "Version: ${{ matrix.config .version }}"
113
+ echo "Run Part: ${{ matrix.config .run_part }}"
99
114
100
115
- name : Install Python Dependencies
101
116
run : |
@@ -105,39 +120,73 @@ jobs:
105
120
env :
106
121
TEASE : ${{ secrets.TEASE }}
107
122
run : |
108
- sub=${{ needs.process_raw.outputs.sub }}
109
- task=${{ needs.process_raw.outputs.task }}
110
- vers=${{ needs.process_raw.outputs.version }}
111
- run_part=${{ needs.process_raw.outputs.run_part }}
123
+ sub=${{ matrix.config.sub }}
124
+ task=${{ matrix.config.task }}
125
+ vers=${{ matrix.config.version }}
126
+ run_part=${{ matrix.config.run_part }}
127
+
128
+ echo "Processing subject: $sub"
129
+ echo "Processing task: $task"
130
+ echo "Processing version: $vers"
131
+ csv_file="./data/${sub}/processed/${run_part}/${sub}_${task}_${vers}.csv"
132
+ mkdir -p "./data/${sub}/${run_part}"
133
+ log_file="./data/${sub}/${run_part}/qc_${task}_${vers}.log"
134
+ echo "CSV file: $csv_file"
135
+ echo "Log file: $log_file"
136
+ if [ -f "$csv_file" ]; then
137
+ python ./code/PCqC.py -s "$csv_file" -o "./data/${sub}/${run_part}" -sub "$sub" | tee "$log_file"
138
+ echo "QC for ${sub}_${task}_${vers} completed"
139
+ else
140
+ echo "CSV file $csv_file does not exist"
141
+ fi
112
142
113
- for sub in ${sub}; do
114
- echo "Processing subject: $sub"
115
- for task in ${task}; do
116
- echo "Processing task: $task"
117
- for vers in ${vers}; do
118
- echo "Processing version: $vers"
119
- csv_file="./data/${sub}/processed/${run_part}/${sub}_${task}_${vers}.csv"
120
- mkdir -p "./data/${sub}/${run_part}"
121
- log_file="./data/${sub}/${run_part}/qc_${task}_${vers}.log"
122
- echo "CSV file: $csv_file"
123
- echo "Log file: $log_file"
124
- if [ -f "$csv_file" ]; then
125
- python ./code/PCqC.py -s "$csv_file" -o "./data/${sub}/${run_part}" -sub "$sub" | tee "$log_file"
126
- echo "QC for ${sub}_${task}_${vers} completed"
127
- else
128
- echo "CSV file $csv_file does not exist"
129
- fi
130
- done
131
- done
132
- done
143
+ - name : Upload QC Results
144
+ uses : actions/upload-artifact@v3
145
+ with :
146
+ name : qc-results-${{ matrix.config.sub }}-${{ matrix.config.task }}-${{ matrix.config.version }}-${{ matrix.config.run_part }}
147
+ path : |
148
+ ./data/${{ matrix.config.sub }}/${{ matrix.config.run_part }}/*.png
149
+ ./data/${{ matrix.config.sub }}/${{ matrix.config.run_part }}/*.log
133
150
134
151
152
+ commit_results :
153
+ name : Commit and Push QC Results
154
+ runs-on : self-hosted
155
+ needs : run_qc
156
+
157
+ steps :
158
+ - name : Checkout Code
159
+ uses : actions/checkout@v3
160
+
161
+ - name : Download all artifacts
162
+ uses : actions/download-artifact@v3
163
+ with :
164
+ path : ./
165
+
166
+ - name : Move QC Results
167
+ run : |
168
+ echo "Moving QC results to data directory..."
169
+ for dir in qc-results-*; do
170
+ echo "Processing artifact directory: $dir"
171
+ # Extract sub, task, version, and run_part from the directory name
172
+ IFS='-' read -r _ _ sub task version run_part <<< "$dir"
173
+ echo "Subject: $sub, Task: $task, Version: $version, Run Part: $run_part"
174
+ # Define the target directories
175
+ run_part_dir="./data/${sub}/${run_part}"
176
+ # Create the target directories if they don't exist
177
+ mkdir -p "$run_part_dir"
178
+ # Move .png files to the processed directory
179
+ mv "$dir"/*.png "$run_part_dir/" 2>/dev/null || :
180
+ # Move .log files to the run_part directory
181
+ mv "$dir"/*.log "$run_part_dir/" 2>/dev/null || :
182
+ done
183
+
135
184
- name : Commit and Push QC Results
136
185
run : |
137
186
git config --global user.name "miloswrath"
138
187
git config --global user.email "[email protected] "
139
188
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
140
- git add ./data/*/*/*.png
189
+ git add ./data/*/*/*.png ./data/*/*/*.log
141
190
git commit -m "Add QC results for subjects $(date +%Y-%m-%d)"
142
191
git push origin main
143
192
@@ -147,12 +196,10 @@ jobs:
147
196
find ./data -type d
148
197
find ./data -type f
149
198
150
-
151
-
152
199
add :
153
200
name : Generate Jekyll Posts and Deploy
154
201
runs-on : ubuntu-latest
155
- needs : [process_raw, run_qc]
202
+ needs : [process_raw, run_qc, commit_results ]
156
203
157
204
steps :
158
205
# 1. Checkout the Repository
0 commit comments