From a81f38fce6f3020192bc590b8c14481b6786c07a Mon Sep 17 00:00:00 2001 From: Till Hartmann Date: Mon, 9 Dec 2024 11:38:27 +0100 Subject: [PATCH 01/17] feat: Use composite action instead of docker action --- Dockerfile | 4 ---- action.yml | 47 ++++++++++++++++++++++++++++++--------- entrypoint.sh | 25 --------------------- environment.yaml.template | 6 +++++ 4 files changed, 43 insertions(+), 39 deletions(-) delete mode 100644 Dockerfile delete mode 100755 entrypoint.sh create mode 100644 environment.yaml.template diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 67cdb03..0000000 --- a/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM snakemake/snakemake:stable -COPY entrypoint.sh /entrypoint.sh -ENV CONDA_ENVS_PATH /github/workspace/.conda -ENTRYPOINT ["/entrypoint.sh"] diff --git a/action.yml b/action.yml index 84013b6..4d22178 100644 --- a/action.yml +++ b/action.yml @@ -27,17 +27,44 @@ inputs: required: false default: 'run' show-disk-usage-on-error: - descriptions: Whether to return the used disk space on failing. + description: Whether to return the used disk space on failing. required: false default: false + snakemake-version: + description: Which snakemake version to use + required: false + default: 8.25.5 runs: - using: 'docker' - image: 'Dockerfile' - args: - - ${{ inputs.directory }} - - ${{ inputs.snakefile }} - - ${{ inputs.args }} - - ${{ inputs.stagein }} - - ${{ inputs.task }} - - ${{ inputs.show-disk-usage-on-error }} + using: 'composite' + steps: + - shell: bash -el {0} + run: sed 's/{{ snakemake_version }}/${{ inputs.snakemake-version }}/g' environment.yaml.template > environment.yaml + - name: Setup conda + uses: conda-incubator/setup-miniconda@v3 + with: + channels: conda-forge,bioconda + channel-priority: strict + miniforge-version: latest + environment-file: environment.yaml + - name: Run snakemake + if: ${{ inputs.task == 'run' }} + shell: bash -el {0} + run: | + snakemake --directory ${{ inputs.directory }} --snakefile ${{ inputs.snakefile }} --show-failed-logs ${{ inputs.args }} + if [[ "$?" -ne 0 ]]; then + if [[ "$6" = true ]]; then + # return disk usage and space on failing + df -h + printf "disk usage working directory" + du -h -d3 $1 + fi + exit 1 + fi + - name: Containerize snakemake + if: ${{ inputs.task == 'containerize' }} + shell: bash -el {0} + run: snakemake --directory ${{ inputs.directory }} --snakefile ${{ inputs.snakefile }} --show-failed-logs ${{ inputs.args }} --containerize > Dockerfile + - if: ${{ ! (inputs.task == 'containerize' || inputs.task == 'run' )}} + run: echo "Invalid value for 'task': '${{ inputs.task }}'. Options: 'containerize', 'run'." && exit 1 + diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100755 index 668ad36..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -mkdir -p /github/workspace/.conda - -# run given stagein command -eval "$4" - -# create container file -if [ "$5" = 'containerize' ] ; then - snakemake --directory $1 --snakefile $2 --show-failed-logs $3 --containerize > Dockerfile -elif [ "$5" = 'run' ] ; then - # run snakemake with given args - snakemake --directory $1 --snakefile $2 --show-failed-logs $3 - if [[ "$?" -ne 0 ]]; then - if [[ "$6" = true ]]; then - # return disk usage and space on failing - df -h - printf "disk usage working directory" - du -h -d3 $1 - fi - exit 1 - fi -else - echo "Task input not recognized." && exit 1 -fi diff --git a/environment.yaml.template b/environment.yaml.template new file mode 100644 index 0000000..d6b4e2d --- /dev/null +++ b/environment.yaml.template @@ -0,0 +1,6 @@ +channels: + - conda-forge + - bioconda + - nodefaults +dependencies: + - snakemake =={{ snakemake_version }} From 34e5f691f728f19125299511041bb84013c87ee2 Mon Sep 17 00:00:00 2001 From: Till Hartmann Date: Mon, 9 Dec 2024 11:40:58 +0100 Subject: [PATCH 02/17] fix indentation --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 4d22178..7c4517d 100644 --- a/action.yml +++ b/action.yml @@ -60,7 +60,7 @@ runs: du -h -d3 $1 fi exit 1 - fi + fi - name: Containerize snakemake if: ${{ inputs.task == 'containerize' }} shell: bash -el {0} From 35f7d8ce213cdbf47f33e00b5ee96a4e76154d9a Mon Sep 17 00:00:00 2001 From: Till Hartmann Date: Mon, 9 Dec 2024 11:42:55 +0100 Subject: [PATCH 03/17] swap quotes --- action.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 7c4517d..6d565ae 100644 --- a/action.yml +++ b/action.yml @@ -66,5 +66,7 @@ runs: shell: bash -el {0} run: snakemake --directory ${{ inputs.directory }} --snakefile ${{ inputs.snakefile }} --show-failed-logs ${{ inputs.args }} --containerize > Dockerfile - if: ${{ ! (inputs.task == 'containerize' || inputs.task == 'run' )}} - run: echo "Invalid value for 'task': '${{ inputs.task }}'. Options: 'containerize', 'run'." && exit 1 + run: | + echo 'Invalid value for "task": "${{ inputs.task }}". Options: "containerize", "run".' + exit 1 From 2551a815e7634c324973441dcad30f2be9a73d02 Mon Sep 17 00:00:00 2001 From: Till Hartmann Date: Mon, 9 Dec 2024 11:44:10 +0100 Subject: [PATCH 04/17] include shell --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index 6d565ae..deeace6 100644 --- a/action.yml +++ b/action.yml @@ -66,6 +66,7 @@ runs: shell: bash -el {0} run: snakemake --directory ${{ inputs.directory }} --snakefile ${{ inputs.snakefile }} --show-failed-logs ${{ inputs.args }} --containerize > Dockerfile - if: ${{ ! (inputs.task == 'containerize' || inputs.task == 'run' )}} + shell: bash -el {0} run: | echo 'Invalid value for "task": "${{ inputs.task }}". Options: "containerize", "run".' exit 1 From 786074daff6272e22b07903fc3df68d604fd690b Mon Sep 17 00:00:00 2001 From: Till Hartmann Date: Mon, 9 Dec 2024 11:46:43 +0100 Subject: [PATCH 05/17] move check for containerize/run to top --- action.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index deeace6..955abe8 100644 --- a/action.yml +++ b/action.yml @@ -38,6 +38,12 @@ inputs: runs: using: 'composite' steps: + - name: Validate inputs + if: ${{ ! (inputs.task == 'containerize' || inputs.task == 'run' )}} + shell: bash -el {0} + run: | + echo 'Invalid value for "task": "${{ inputs.task }}". Options: "containerize", "run".' + exit 1 - shell: bash -el {0} run: sed 's/{{ snakemake_version }}/${{ inputs.snakemake-version }}/g' environment.yaml.template > environment.yaml - name: Setup conda @@ -65,9 +71,4 @@ runs: if: ${{ inputs.task == 'containerize' }} shell: bash -el {0} run: snakemake --directory ${{ inputs.directory }} --snakefile ${{ inputs.snakefile }} --show-failed-logs ${{ inputs.args }} --containerize > Dockerfile - - if: ${{ ! (inputs.task == 'containerize' || inputs.task == 'run' )}} - shell: bash -el {0} - run: | - echo 'Invalid value for "task": "${{ inputs.task }}". Options: "containerize", "run".' - exit 1 From d84999bbfa00c22c0d4fb627670fad1f5095df74 Mon Sep 17 00:00:00 2001 From: Till Hartmann Date: Mon, 9 Dec 2024 11:50:51 +0100 Subject: [PATCH 06/17] check show-disk-usage-on-error --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 955abe8..b836aeb 100644 --- a/action.yml +++ b/action.yml @@ -59,7 +59,7 @@ runs: run: | snakemake --directory ${{ inputs.directory }} --snakefile ${{ inputs.snakefile }} --show-failed-logs ${{ inputs.args }} if [[ "$?" -ne 0 ]]; then - if [[ "$6" = true ]]; then + if [[ ${{ inputs.show-disk-usage-on-error }} = true ]]; then # return disk usage and space on failing df -h printf "disk usage working directory" From eeb286cc1813ef60af3a76ae39d91ed64b8d482a Mon Sep 17 00:00:00 2001 From: Till Hartmann Date: Mon, 9 Dec 2024 11:53:26 +0100 Subject: [PATCH 07/17] fix du for directory --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index b836aeb..09931e6 100644 --- a/action.yml +++ b/action.yml @@ -63,7 +63,7 @@ runs: # return disk usage and space on failing df -h printf "disk usage working directory" - du -h -d3 $1 + du -h -d3 ${{ inputs.directory }} fi exit 1 fi From 68b501bd07ce984472f69054e774b21121d7a1e8 Mon Sep 17 00:00:00 2001 From: Till Hartmann Date: Mon, 9 Dec 2024 17:46:09 +0100 Subject: [PATCH 08/17] rename env to 'snakemake' --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index 09931e6..9c6aad3 100644 --- a/action.yml +++ b/action.yml @@ -53,6 +53,7 @@ runs: channel-priority: strict miniforge-version: latest environment-file: environment.yaml + activate-environment: snakemake - name: Run snakemake if: ${{ inputs.task == 'run' }} shell: bash -el {0} From 8ae899760389b50f7d94451ad9d8bdac0d8d47dd Mon Sep 17 00:00:00 2001 From: Till Hartmann Date: Mon, 9 Dec 2024 17:50:42 +0100 Subject: [PATCH 09/17] Update action.yml Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- action.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 9c6aad3..a47c232 100644 --- a/action.yml +++ b/action.yml @@ -31,9 +31,8 @@ inputs: required: false default: false snakemake-version: - description: Which snakemake version to use - required: false - default: 8.25.5 + description: Snakemake version to use. If not specified, uses latest version. Pin a specific version (e.g., '8.25.5') for reproducibility. + required: false runs: using: 'composite' From 53479d3882abf21936ef928a67581b463f094cab Mon Sep 17 00:00:00 2001 From: Till Hartmann Date: Mon, 9 Dec 2024 18:03:41 +0100 Subject: [PATCH 10/17] simply use '*' as default for snakemake version --- action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/action.yml b/action.yml index a47c232..1d330cf 100644 --- a/action.yml +++ b/action.yml @@ -33,6 +33,7 @@ inputs: snakemake-version: description: Snakemake version to use. If not specified, uses latest version. Pin a specific version (e.g., '8.25.5') for reproducibility. required: false + default: '*' runs: using: 'composite' @@ -45,6 +46,7 @@ runs: exit 1 - shell: bash -el {0} run: sed 's/{{ snakemake_version }}/${{ inputs.snakemake-version }}/g' environment.yaml.template > environment.yaml + - name: Setup conda uses: conda-incubator/setup-miniconda@v3 with: From 8a08969e94a0ad2d0e4a6a8cdca4ba478467a9a7 Mon Sep 17 00:00:00 2001 From: Till Hartmann Date: Mon, 9 Dec 2024 18:05:34 +0100 Subject: [PATCH 11/17] show installed snakemake version by default --- action.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/action.yml b/action.yml index 1d330cf..f981a90 100644 --- a/action.yml +++ b/action.yml @@ -55,6 +55,9 @@ runs: miniforge-version: latest environment-file: environment.yaml activate-environment: snakemake + - name: Display snakemake version + shell: bash -el {0} + run: snakemake --version - name: Run snakemake if: ${{ inputs.task == 'run' }} shell: bash -el {0} From 991091fbba987356f4ab6e77fc520c086cf6fdea Mon Sep 17 00:00:00 2001 From: Till Hartmann Date: Mon, 9 Dec 2024 18:08:53 +0100 Subject: [PATCH 12/17] add apptainer installation option --- action.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index f981a90..0d0f93f 100644 --- a/action.yml +++ b/action.yml @@ -34,6 +34,10 @@ inputs: description: Snakemake version to use. If not specified, uses latest version. Pin a specific version (e.g., '8.25.5') for reproducibility. required: false default: '*' + install-apptainer: + description: Install Apptainer (true/false) + required: false + default: false runs: using: 'composite' @@ -44,7 +48,15 @@ runs: run: | echo 'Invalid value for "task": "${{ inputs.task }}". Options: "containerize", "run".' exit 1 - - shell: bash -el {0} + + - name: Install Apptainer + if: ${{ inputs.install-apptainer == 'true' }} + run: | + sudo apt-get update + sudo apt-get install -y apptainer + + - name: Prepare environment.yaml + shell: bash -el {0} run: sed 's/{{ snakemake_version }}/${{ inputs.snakemake-version }}/g' environment.yaml.template > environment.yaml - name: Setup conda @@ -55,9 +67,11 @@ runs: miniforge-version: latest environment-file: environment.yaml activate-environment: snakemake + - name: Display snakemake version shell: bash -el {0} run: snakemake --version + - name: Run snakemake if: ${{ inputs.task == 'run' }} shell: bash -el {0} @@ -72,6 +86,7 @@ runs: fi exit 1 fi + - name: Containerize snakemake if: ${{ inputs.task == 'containerize' }} shell: bash -el {0} From 861c528bda7dc43bbffa95eaef95d3c26ecca990 Mon Sep 17 00:00:00 2001 From: Till Hartmann Date: Mon, 9 Dec 2024 18:10:09 +0100 Subject: [PATCH 13/17] =?UTF-8?q?add=20missing=20'shell:=20=E2=80=A6'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index 0d0f93f..01db76b 100644 --- a/action.yml +++ b/action.yml @@ -51,6 +51,7 @@ runs: - name: Install Apptainer if: ${{ inputs.install-apptainer == 'true' }} + shell: bash -el {0} run: | sudo apt-get update sudo apt-get install -y apptainer From 8c55e2b266498a031a016a1659b4b40e224ecc85 Mon Sep 17 00:00:00 2001 From: Till Hartmann Date: Tue, 10 Dec 2024 13:52:30 +0100 Subject: [PATCH 14/17] use here string --- action.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 01db76b..0ae6c36 100644 --- a/action.yml +++ b/action.yml @@ -56,9 +56,17 @@ runs: sudo apt-get update sudo apt-get install -y apptainer - - name: Prepare environment.yaml + - name: Prepare .snakemake.environment.yaml shell: bash -el {0} - run: sed 's/{{ snakemake_version }}/${{ inputs.snakemake-version }}/g' environment.yaml.template > environment.yaml + run: |8 + cat < .snakemake.environment.yaml + channels: + - conda-forge + - bioconda + - nodefaults + dependencies: + - snakemake ==${{ inputs.snakemake-version }} + EOF - name: Setup conda uses: conda-incubator/setup-miniconda@v3 @@ -66,7 +74,7 @@ runs: channels: conda-forge,bioconda channel-priority: strict miniforge-version: latest - environment-file: environment.yaml + environment-file: .snakemake.environment.yaml activate-environment: snakemake - name: Display snakemake version From 8d6dd0449330b5cad99d9b1ff69e0e187cd60e70 Mon Sep 17 00:00:00 2001 From: Till Hartmann Date: Tue, 10 Dec 2024 13:53:57 +0100 Subject: [PATCH 15/17] I guess the yaml parser does not support |8 notation --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 0ae6c36..89fb0c0 100644 --- a/action.yml +++ b/action.yml @@ -58,7 +58,7 @@ runs: - name: Prepare .snakemake.environment.yaml shell: bash -el {0} - run: |8 + run: | cat < .snakemake.environment.yaml channels: - conda-forge From dedc6dc3cec13d813258896645d60db1d1ea2e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20K=C3=B6ster?= Date: Tue, 10 Dec 2024 15:34:05 +0100 Subject: [PATCH 16/17] Delete environment.yaml.template --- environment.yaml.template | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 environment.yaml.template diff --git a/environment.yaml.template b/environment.yaml.template deleted file mode 100644 index d6b4e2d..0000000 --- a/environment.yaml.template +++ /dev/null @@ -1,6 +0,0 @@ -channels: - - conda-forge - - bioconda - - nodefaults -dependencies: - - snakemake =={{ snakemake_version }} From cebcb23c87aa3a23efddff3f79b3a4bd143d4120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20K=C3=B6ster?= Date: Tue, 10 Dec 2024 15:34:39 +0100 Subject: [PATCH 17/17] Update action.yml Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- action.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 89fb0c0..b1c06bb 100644 --- a/action.yml +++ b/action.yml @@ -53,9 +53,12 @@ runs: if: ${{ inputs.install-apptainer == 'true' }} shell: bash -el {0} run: | + if ! command -v apt-get &> /dev/null; then + echo "Error: This action currently supports Apptainer installation only on Ubuntu runners" + exit 1 + fi sudo apt-get update sudo apt-get install -y apptainer - - name: Prepare .snakemake.environment.yaml shell: bash -el {0} run: |