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..b1c06bb 100644 --- a/action.yml +++ b/action.yml @@ -27,17 +27,80 @@ 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: 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: 'docker' - image: 'Dockerfile' - args: - - ${{ inputs.directory }} - - ${{ inputs.snakefile }} - - ${{ inputs.args }} - - ${{ inputs.stagein }} - - ${{ inputs.task }} - - ${{ inputs.show-disk-usage-on-error }} + 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 + + - name: Install Apptainer + 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: | + cat < .snakemake.environment.yaml + channels: + - conda-forge + - bioconda + - nodefaults + dependencies: + - snakemake ==${{ inputs.snakemake-version }} + EOF + + - name: Setup conda + uses: conda-incubator/setup-miniconda@v3 + with: + channels: conda-forge,bioconda + channel-priority: strict + miniforge-version: latest + environment-file: .snakemake.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} + run: | + snakemake --directory ${{ inputs.directory }} --snakefile ${{ inputs.snakefile }} --show-failed-logs ${{ inputs.args }} + if [[ "$?" -ne 0 ]]; then + if [[ ${{ inputs.show-disk-usage-on-error }} = true ]]; then + # return disk usage and space on failing + df -h + printf "disk usage working directory" + du -h -d3 ${{ inputs.directory }} + 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 + 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