Skip to content

Commit 55f4a5e

Browse files
Update workflows to be able to run scripts on PRs
1 parent 8e2f352 commit 55f4a5e

2 files changed

Lines changed: 70 additions & 4 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: "Run sct_run_batch -s process_data.sh"
2+
# The tl;dr purpose of this workflow is to:
3+
# - A) Run the batch processing script part of the the SCT Course
4+
# - B) If run manually, then take some of the output files and package them into tutorial-specific datasets.
5+
#
6+
# In-depth explanation:
7+
# Most of SCT's tutorials depend on files generated by previous steps. (For example, 'sct_register_to_template'
8+
# depends on the segmented spinal cord image file generated by `sct_deepseg`. This creates a dilemma: If we want
9+
# SCT's tutorials to stand alone, we need to provide these intermediate files. But, if we want to run the tutorials
10+
# start to finish in a sequence (e.g. during the SCT Course), it would be confusing if the intermediate files
11+
# were already there.
12+
#
13+
# The solution is to only store the minimally-necessary files in the repository, then generate the intermediate files
14+
# using this workflow. That way, we can provide 2 different downloads:
15+
# - 'sct_course_data.zip': Files required to run the SCT course from start to finish.
16+
# - 'registration.zip', 'segmentation.zip', etc.: Files required by individual tutorials.
17+
18+
on:
19+
pull_request:
20+
21+
jobs:
22+
run-course-script:
23+
runs-on: ubuntu-latest
24+
steps:
25+
26+
- name: Checkout spinalcordtoolbox
27+
uses: actions/checkout@v2
28+
with:
29+
repository: spinalcordtoolbox/spinalcordtoolbox
30+
path: spinalcordtoolbox
31+
32+
# install_sct edits ~/.bashrc, but those environment changes don't get passed to subsequent steps in GH Actions.
33+
# So, we filter through the .bashrc and pass the values to $GITHUB_ENV and $GITHUB_PATH.
34+
# Relevant documentation: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#environment-files
35+
# This workaround should be replaced by https://github.com/spinalcordtoolbox/spinalcordtoolbox/pull/3198#discussion_r568225392
36+
- name: Install spinalcordtoolbox
37+
run: |
38+
cd spinalcordtoolbox
39+
./install_sct -iy
40+
cat ~/.bashrc | grep "export SCT_DIR" | cut -d " " -f 2 >> $GITHUB_ENV
41+
cat ~/.bashrc | grep "export PATH" | grep -o "/.*" | cut -d ':' -f 1 >> $GITHUB_PATH
42+
43+
- name: "Checkout '${{ github.event.repository.name }}'"
44+
uses: actions/checkout@v2
45+
with:
46+
path: ${{ github.event.repository.name }}
47+
48+
- name: Run sct_run_batch -s process_data.sh
49+
run: |
50+
cd "${{ github.event.repository.name }}/multi_subject"
51+
sct_run_batch -script process_data.sh -d
52+
53+
- name: Assert that script executed without error
54+
run: |
55+
cd "${{ github.event.repository.name }}/multi_subject/output/log"
56+
[ "$(compgen -G "process_data_sub-0*.log")" ] # Log files should exist
57+
[ ! "$(compgen -G "err.process_data_sub-0*.log")" ] # Error files should NOT exist

.github/workflows/create_release.yml renamed to .github/workflows/run_script_and_create_release.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
name: "Package course data into subsets"
2-
# The purpose of this workflow is to convert the SCT Course dataset into tutorial-specific datasets.
1+
name: "Run batch_single_subject.sh"
2+
# The tl;dr purpose of this workflow is to:
3+
# - A) Run all of the commands in the SCT Course
4+
# - B) If the workflow is run manually, then take the output files and package them into tutorial-specific datasets.
35
#
46
# In-depth explanation:
57
# Most of SCT's tutorials depend on files generated by previous steps. (For example, 'sct_register_to_template'
@@ -14,14 +16,15 @@ name: "Package course data into subsets"
1416
# - 'registration.zip', 'segmentation.zip', etc.: Files required by individual tutorials.
1517

1618
on:
19+
pull_request:
1720
workflow_dispatch:
1821
inputs:
1922
release_title:
2023
description: 'Release title (e.g. rYYYYMMDD)'
2124
required: true
2225

2326
jobs:
24-
create-tutorial-data-release:
27+
run-course-script:
2528
runs-on: ubuntu-latest
2629
steps:
2730

@@ -57,13 +60,17 @@ jobs:
5760
run: |
5861
cd ${{ github.event.repository.name }}
5962
awk -F, '{ print $1,$2 }' tutorial-datasets.csv | xargs -l zip -u
63+
# Only package data if workflow is run manually. (This allows the workflow to double as a PR test.)
64+
if: github.event_name == 'workflow_dispatch'
6065

6166
- uses: ncipollo/release-action@v1
6267
name: Create release ('${{ github.event.inputs.release_title }}')
6368
id: create_release
6469
with:
6570
tag: ${{ github.event.inputs.release_title }}
6671
token: ${{ secrets.GITHUB_TOKEN }}
72+
# Only create release if workflow is run manually. (This allows the workflow to double as a PR test.)
73+
if: github.event_name == 'workflow_dispatch'
6774

6875
- uses: xresloader/upload-to-github-release@v1
6976
name: Attach .zip files to newly-created release
@@ -73,4 +80,6 @@ jobs:
7380
file: "${{ github.event.repository.name }}/*.zip"
7481
draft: false
7582
tag_name: ${{ github.event.inputs.release_title }}
76-
release_id: ${{ steps.create_release.outputs.id }}
83+
release_id: ${{ steps.create_release.outputs.id }}
84+
# Only attach to release if workflow is run manually. (This allows the workflow to double as a PR test.)
85+
if: github.event_name == 'workflow_dispatch'

0 commit comments

Comments
 (0)