|
1 |
| -name: Task1 QC |
| 1 | +# .github/workflows/deploy.yml |
| 2 | + |
| 3 | +name: Task1 QC and Deploy |
| 4 | + |
2 | 5 | on:
|
3 | 6 | push:
|
4 | 7 | branches:
|
5 | 8 | - main
|
6 | 9 |
|
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + packages: write |
| 13 | + issues: write |
| 14 | + id-token: write |
| 15 | + pages: write |
| 16 | + |
7 | 17 | jobs:
|
8 | 18 | process_raw:
|
| 19 | + name: Process Raw CSV Files |
9 | 20 | runs-on: self-hosted
|
10 | 21 | outputs:
|
11 |
| - sub: ${{ steps.set_vars.outputs.sub }} |
12 |
| - task: ${{ steps.set_vars.outputs.task }} |
13 |
| - version: ${{ steps.set_vars.outputs.version }} |
| 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 }} |
14 | 26 |
|
15 | 27 | steps:
|
16 |
| - - name: checkout code and return recently uploaded file in /data |
| 28 | + - name: Checkout Code |
17 | 29 | uses: actions/checkout@v3
|
18 |
| - - name: Get changed files |
| 30 | + |
| 31 | + - name: Get Changed CSV Files |
19 | 32 | run: |
|
20 |
| - #!/bin/bash |
| 33 | + #!/bin/bash |
| 34 | +
|
| 35 | + # Get the list of CSV files changed in the last 24 hours |
| 36 | + data=$(git log --since="24 hours ago" --name-only --pretty=format: -- '*.csv' | sort | uniq) |
21 | 37 |
|
22 |
| - # Get the list of CSV files changed in the last 24 hours |
23 |
| - data=$(git log --since="24 hours ago" --name-only --pretty=format: -- '*.csv' | sort | uniq) |
| 38 | + # Export the data variable to the environment |
| 39 | + echo "data=$data" >> $GITHUB_ENV |
24 | 40 |
|
25 |
| - # Export the data variable to the environment |
26 |
| - echo "data=$data" >> $GITHUB_ENV |
| 41 | + # Print the changed CSV files |
| 42 | + echo "Changed CSV files in the last 24 hours: $data" |
27 | 43 |
|
28 |
| - # Print the changed CSV files |
29 |
| - echo "Changed CSV files in the last 24 hours: $data" |
30 | 44 |
|
31 |
| - - name: set up python |
| 45 | + - name: Install Python Dependencies |
32 | 46 | run: |
|
33 | 47 | python -m pip install --upgrade pip
|
34 | 48 |
|
35 |
| - - name: parse raw |
| 49 | + - name: Parse Raw CSV Files |
36 | 50 | id: set_vars
|
37 | 51 | run: |
|
38 |
| - # Loop through each CSV file in $data |
39 |
| - for file in $data; do |
40 |
| - filename=$(basename "$file") |
41 |
| - IFS='_' read -r sub task version <<< "$filename" |
42 |
| - version="${version%.csv}" # Remove the .csv extension from version |
43 |
| - echo "::set-output name=sub::$sub" |
44 |
| - echo "::set-output name=task::$task" |
45 |
| - echo "::set-output name=version::$version" |
46 |
| - echo "Subject: $sub" |
47 |
| - echo "Task: $task" |
48 |
| - echo "Version: $version" |
49 |
| - done |
| 52 | + # Loop through each CSV file in $data |
| 53 | + for file in $data; do |
| 54 | + # Extract the directory and filename |
| 55 | + dir=$(dirname "$file") |
| 56 | + filename=$(basename "$file") |
| 57 | +
|
| 58 | + # Extract the run-* part from the directory |
| 59 | + run_part=$(basename "$dir") |
| 60 | +
|
| 61 | + # Split the filename into sub, task, and version |
| 62 | + IFS='_' read -r sub task version <<< "$filename" |
| 63 | + version="${version%.csv}" # Remove the .csv extension from version |
| 64 | +
|
| 65 | + # Set outputs |
| 66 | + echo "::set-output name=run_part::$run_part" |
| 67 | + echo "::set-output name=sub::$sub" |
| 68 | + echo "::set-output name=task::$task" |
| 69 | + echo "::set-output name=version::$version" |
| 70 | +
|
| 71 | + # Print the extracted values |
| 72 | + echo "Run Part: $run_part" |
| 73 | + echo "Subject: $sub" |
| 74 | + echo "Task: $task" |
| 75 | + echo "Version: $version" |
| 76 | + done |
50 | 77 |
|
51 | 78 | run_qc:
|
| 79 | + name: Run Quality Control |
52 | 80 | runs-on: self-hosted
|
53 | 81 | needs: process_raw
|
| 82 | + |
54 | 83 | steps:
|
55 |
| - - name: Checkout code |
| 84 | + - name: Checkout Code |
56 | 85 | uses: actions/checkout@v3
|
57 | 86 |
|
58 |
| - - name: Debug env vars |
| 87 | + - name: Debug Environment Variables |
59 | 88 | run: |
|
60 |
| - echo "sub=${{ needs.process_raw.outputs.sub }}" |
61 |
| - echo "task=${{ needs.process_raw.outputs.task }}" |
62 |
| - echo "version=${{ needs.process_raw.outputs.version }}" |
| 89 | + echo "Subject: ${{ needs.process_raw.outputs.sub }}" |
| 90 | + echo "Task: ${{ needs.process_raw.outputs.task }}" |
| 91 | + echo "Version: ${{ needs.process_raw.outputs.version }}" |
| 92 | + echo "Run Part: ${{ needs.process_raw.outputs.run_part }}" |
63 | 93 |
|
64 |
| - - name: run quality control |
| 94 | + - name: Install Python Dependencies |
65 | 95 | run: |
|
66 |
| - sub=${{ needs.process_raw.outputs.sub }} |
67 |
| - task=${{ needs.process_raw.outputs.task }} |
68 |
| - vers=${{ needs.process_raw.outputs.version }} |
69 |
| - for sub in ${sub}; do |
| 96 | + python -m pip install --upgrade pip |
| 97 | +
|
| 98 | + - name: Run Quality Control Script |
| 99 | + run: | |
| 100 | + sub=${{ needs.process_raw.outputs.sub }} |
| 101 | + task=${{ needs.process_raw.outputs.task }} |
| 102 | + vers=${{ needs.process_raw.outputs.version }} |
| 103 | + run_part=${{ needs.process_raw.outputs.run_part }} |
| 104 | +
|
| 105 | + for sub in ${sub}; do |
70 | 106 | echo "Processing subject: $sub"
|
71 | 107 | for task in ${task}; do
|
72 |
| - echo "Processing task: $task" |
73 |
| - for vers in ${vers}; do |
| 108 | + echo "Processing task: $task" |
| 109 | + for vers in ${vers}; do |
74 | 110 | echo "Processing version: $vers"
|
75 |
| - csv_file="./data/${sub}/processed/${sub}_${task}_${vers}.csv" |
76 |
| - log_file="./data/${sub}/qc_${task}_${vers}.log" |
| 111 | + csv_file="./data/${sub}/processed/${run_part}/${sub}_${task}_${vers}.csv" |
| 112 | + mkdir -p "./data/${sub}/${run_part}" |
| 113 | + log_file="./data/${sub}/${run_part}/qc_${task}_${vers}.log" |
77 | 114 | echo "CSV file: $csv_file"
|
78 | 115 | echo "Log file: $log_file"
|
79 | 116 | if [ -f "$csv_file" ]; then
|
80 |
| - python ./code/PCqC.py -s "$csv_file" -o "./data/${sub}/" -sub "$sub" | tee "$log_file" |
81 |
| - echo "QC for ${sub}_${task}_${vers} running" |
| 117 | + python ./code/PCqC.py -s "$csv_file" -o "./data/${sub}/${run_part}" -sub "$sub" | tee "$log_file" |
| 118 | + echo "QC for ${sub}_${task}_${vers} completed" |
82 | 119 | else
|
83 |
| - echo "CSV file $csv_file does not exist" |
| 120 | + echo "CSV file $csv_file does not exist" |
84 | 121 | fi
|
85 |
| - done |
86 |
| - done |
| 122 | + done |
87 | 123 | done
|
| 124 | + done |
| 125 | +
|
| 126 | +
|
| 127 | + - name: Commit and Push QC Results |
| 128 | + run: | |
| 129 | + git config --global user.name "miloswrath" |
| 130 | + git config --global user.email "[email protected]" |
| 131 | + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY |
| 132 | + git add ./data/*/*/*.png |
| 133 | + git commit -m "Add QC results for subjects $(date +%Y-%m-%d)" |
| 134 | + git push origin main |
| 135 | +
|
| 136 | + - name: List Directory After QC |
| 137 | + run: | |
| 138 | + echo "Listing directory after running QC:" |
| 139 | + find ./data -type d |
| 140 | + find ./data -type f |
| 141 | +
|
| 142 | +
|
| 143 | +
|
| 144 | + add: |
| 145 | + name: Generate Jekyll Posts and Deploy |
| 146 | + runs-on: ubuntu-latest |
| 147 | + needs: [process_raw, run_qc] |
88 | 148 |
|
89 |
| - push: |
90 |
| - runs-on: self-hosted |
91 |
| - needs: run_qc |
92 | 149 | steps:
|
93 |
| - - name: Commit and Push Changes |
| 150 | + # 1. Checkout the Repository |
| 151 | + |
| 152 | + - name: Checkout Repository |
| 153 | + uses: actions/checkout@v4 |
| 154 | + with: |
| 155 | + persist-credentials: false # Recommended for security |
| 156 | + fetch-depth: 0 |
| 157 | + ref: main |
| 158 | + - name: Pull Latest Changes |
| 159 | + run: git pull origin main |
| 160 | + |
| 161 | + # 4. Set Up Ruby Environment |
| 162 | + - name: Setup Ruby |
| 163 | + uses: ruby/setup-ruby@v1 |
| 164 | + with: |
| 165 | + ruby-version: '3.1' # Specify your Ruby version |
| 166 | + bundler-cache: true # Caches installed gems automatically |
| 167 | + cache-version: 1 # Increment if you need to reset the cache |
| 168 | + |
| 169 | + # 5. Install Ruby Dependencies |
| 170 | + - name: Install Dependencies |
| 171 | + run: bundle install |
| 172 | + |
| 173 | + # 6. Generate Jekyll Posts from PNGs |
| 174 | + - name: Generate Jekyll Posts |
| 175 | + run: | |
| 176 | + set -e # Exit immediately if a command exits with a non-zero status |
| 177 | + set -x # Print commands and their arguments as they are executed |
| 178 | + |
| 179 | + run_part=${{ needs.process_raw.outputs.run_part }} |
| 180 | + POSTS_DIR="_posts" |
| 181 | + mkdir -p "$POSTS_DIR" # Ensure the _posts directory exists |
| 182 | + |
| 183 | + # Initialize an associative array to group images by subject |
| 184 | + declare -A subjects |
| 185 | + |
| 186 | + # Get the list of PNG files added in the latest commit |
| 187 | + images=$(git diff --name-only HEAD~1 HEAD | grep '\.png$') |
| 188 | + echo "Images: $images" |
| 189 | + |
| 190 | + # Iterate over each PNG file and group them by subject number |
| 191 | + for file in $images; do |
| 192 | + # Check if the file exists to avoid errors |
| 193 | + if [ ! -f "$file" ]; then |
| 194 | + continue |
| 195 | + fi |
| 196 | + |
| 197 | + # Extract the subject number from the filename (assuming it's the first part before '_') |
| 198 | + filename=$(basename "$file") |
| 199 | + subject=$(echo "$filename" | awk -F_ '{print $1}') |
| 200 | + |
| 201 | + # Append the filename to the subject's array |
| 202 | + subjects["$subject"]+="$file " |
| 203 | + done |
| 204 | + |
| 205 | + # Generate Jekyll posts for each subject |
| 206 | + for subject in "${!subjects[@]}"; do |
| 207 | + # Define the post filename with current date and subject number |
| 208 | + timestamp=$(date +%H%M%S) |
| 209 | + post_filename="$POSTS_DIR/$(date +%Y-%m-%d)-subject-$subject-$timestamp.md" |
| 210 | + |
| 211 | + # Create the Jekyll post |
| 212 | + { |
| 213 | + echo "---" |
| 214 | + echo "layout: post" |
| 215 | + echo "title: Subject $subject" |
| 216 | + echo "date: $(date +%Y-%m-%d)" |
| 217 | + echo "categories: subjects" |
| 218 | + echo "---" |
| 219 | + echo "" |
| 220 | + # Add images to the post |
| 221 | + for image in ${subjects["$subject"]}; do |
| 222 | + # Adjust the image path based on your site structure |
| 223 | + # Assuming images are served from the root |
| 224 | + echo "" |
| 225 | + done |
| 226 | + } > "$post_filename" |
| 227 | + |
| 228 | + echo "Created post: $post_filename" |
| 229 | + done |
| 230 | + # 7. List _posts Directory for Verification (Optional) |
| 231 | + - name: List _posts Directory |
| 232 | + run: | |
| 233 | + echo "Listing _posts directory:" |
| 234 | + ls -la _posts |
| 235 | +
|
| 236 | + # 8. Commit and Push Generated Posts |
| 237 | + - name: Commit and Push Posts |
94 | 238 | run: |
|
95 | 239 | git config --global user.name "miloswrath"
|
96 | 240 | git config --global user.email "[email protected]"
|
97 | 241 | git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
|
98 |
| - git add . |
99 |
| - git commit -m "Automated commit by GitHub Actions" |
100 |
| - git push |
| 242 | + |
| 243 | + # Add new posts to git |
| 244 | + git add _posts/*.md |
| 245 | + |
| 246 | + # Commit changes if there are any |
| 247 | + if ! git diff --cached --exit-code > /dev/null; then |
| 248 | + git commit -m "Add new posts for subjects $(date +%Y-%m-%d)" |
| 249 | + git push origin main # Replace 'main' with your default branch if different |
| 250 | + else |
| 251 | + echo "No changes to commit." |
| 252 | + fi |
| 253 | + env: |
| 254 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 255 | + |
| 256 | + # 9. Build the Jekyll Site |
| 257 | + - name: Build with Jekyll |
| 258 | + run: bundle exec jekyll build --verbose --baseurl "${{ github.event.inputs.base_path || '' }}" |
101 | 259 | env:
|
102 |
| - GITHUB_TOKEN: ${{ secrets.GIT_PAT }} |
| 260 | + JEKYLL_ENV: production |
| 261 | + |
| 262 | + # 10. Deploy to GitHub Pages |
| 263 | + # Using GitHub's built-in Pages action |
| 264 | + - name: Configure GitHub Pages |
| 265 | + uses: actions/configure-pages@v5 |
| 266 | + |
| 267 | + - name: Upload Pages Artifact |
| 268 | + uses: actions/upload-pages-artifact@v1 |
| 269 | + with: |
| 270 | + path: ./_site # Ensure this matches your Jekyll build output |
| 271 | + |
| 272 | + - name: List _site Directory |
| 273 | + run: | |
| 274 | + echo "Listing _site directory:" |
| 275 | + ls -la _site |
| 276 | +
|
| 277 | + - name: Deploy to GitHub Pages |
| 278 | + uses: actions/deploy-pages@v1 |
| 279 | + with: |
| 280 | + token: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments