Add new module to class #40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update subworkflows | |
| on: | |
| pull_request: | |
| types: [opened] | |
| branches: [main] | |
| # Cancel if a newer run is started | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| module-added: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| new_module_added: ${{ steps.check-class-modules.outputs.new_module_added }} | |
| class_name: ${{ steps.check-class-modules.outputs.class_name }} | |
| steps: | |
| - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 | |
| - name: Check if a class module list changed | |
| id: check-class-modules | |
| run: | | |
| # Fetch the base branch | |
| git fetch origin main | |
| # Get the base branch commit | |
| base_sha=$(git rev-parse origin/main) | |
| # Get the changed class YAMLs | |
| changed_class_ymls=$(git diff --name-only $base_sha HEAD | grep '^classes/.*\.yml$' || true) | |
| new_module_added=false | |
| class_name="" | |
| for class_file in $changed_class_ymls; do | |
| # Get the class name (filename without path and extension) | |
| cname=$(basename "$class_file" .yml) | |
| # Get modules list in main and PR | |
| main_modules=$(git show origin/main:$class_file | yq eval '.components.modules // []' - 2>/dev/null || echo "[]") | |
| pr_modules=$(yq eval '.components.modules // []' "$class_file" 2>/dev/null || echo "[]") | |
| # Find new modules in PR not in main | |
| new_in_pr=$(comm -13 <(echo "$main_modules" | sort) <(echo "$pr_modules" | sort) | grep -v '^\s*$' || true) | |
| if [[ -n "$new_in_pr" ]]; then | |
| new_module_added=true | |
| class_name=$cname | |
| break | |
| fi | |
| done | |
| echo "new_module_added=$new_module_added" >> $GITHUB_OUTPUT | |
| echo "class_name=$class_name" >> $GITHUB_OUTPUT | |
| update-subworkflow: | |
| runs-on: ubuntu-latest | |
| needs: module-added | |
| if: needs.module-added.outputs.new_module_added == 'true' | |
| steps: | |
| - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 | |
| with: | |
| ref: ${{ github.head_ref }} | |
| - name: Setup Nextflow | |
| uses: nf-core/setup-nextflow@v2 | |
| - name: Install nf-class | |
| run: pip install git+https://github.com/mirpedrol/nf-class.git@dev | |
| - name: Get author | |
| id: get-author | |
| run: | | |
| echo "author=$(yq eval '.authors[0]' subworkflows/mirpedrol/${{ needs.module-added.outputs.class_name }}/meta.yml)" >> $GITHUB_OUTPUT | |
| - name: Update subworkflows | |
| run: nf-class subworkflows --branch ${{ github.head_ref }} expand-class ${{ needs.module-added.outputs.class_name }} --force --author ${{ steps.get-author.outputs.author }} | |
| - name: Commit changes | |
| run: | | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git config user.name "github-actions[bot]" | |
| git add subworkflows/ | |
| git status | |
| git commit -m "[automated] Update expanded subworkflows for class ${{ needs.module-added.outputs.class_name }}" | |
| git push | |
| update-snapshot: | |
| runs-on: ubuntu-latest | |
| needs: | |
| - module-added | |
| - update-subworkflow | |
| if: needs.module-added.outputs.new_module_added == 'true' | |
| env: | |
| NXF_ANSI_LOG: false | |
| NFTEST_VER: "0.8.4" | |
| steps: | |
| - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 | |
| with: | |
| ref: ${{ github.head_ref }} | |
| fetch-depth: 0 | |
| - uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b # v4 | |
| with: | |
| distribution: "temurin" | |
| java-version: "17" | |
| - name: Install nf-core tools development version | |
| run: python -m pip install --upgrade --force-reinstall git+https://github.com/nf-core/tools.git@dev | |
| - name: Setup Nextflow | |
| uses: nf-core/setup-nextflow@v2 | |
| - name: Set up Python | |
| uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Install nf-test | |
| uses: nf-core/setup-nf-test@v1 | |
| with: | |
| version: "0.9.2" | |
| install-pdiff: true | |
| - name: Install Python dependencies | |
| run: python -m pip install --upgrade pip cryptography | |
| # Install the subworkflow to a pipeline | |
| - name: create a pipeline | |
| run: | | |
| mkdir create-test-wf | |
| cd create-test-wf | |
| nf-core --log-file log.txt pipelines create -n testpipeline -d "This pipeline is for testing subworkflows" -a "Me" | |
| - name: update resource limits | |
| run: | | |
| cd create-test-wf | |
| cat <<EOF >> nf-core-testpipeline/tests/nextflow.config | |
| process { | |
| withName: '.*'{ | |
| cpus = 2 | |
| memory = 15.GB | |
| time = 2.h | |
| } | |
| } | |
| EOF | |
| - name: Install subworkflow ${{ needs.module-added.outputs.class_name }} | |
| run: | | |
| cd create-test-wf/nf-core-testpipeline | |
| nf-core subworkflows --git-remote https://github.com/mirpedrol/class-modules --branch ${{ github.head_ref }} install ${{ needs.module-added.outputs.class_name }} | |
| # Generate snapshot | |
| - name: Run nf-test | |
| shell: bash | |
| env: | |
| NFT_DIFF: "pdiff" | |
| NFT_DIFF_ARGS: "--line-numbers --width 120 --expand-tabs=2" | |
| run: | | |
| cd create-test-wf/nf-core-testpipeline | |
| PROFILE=docker | |
| NFT_WORKDIR=~ | |
| nf-test test \ | |
| --profile=docker \ | |
| --verbose \ | |
| subworkflows/mirpedrol/${{ needs.module-added.outputs.class_name }} | |
| - name: Commit changes | |
| run: | | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git config user.name "github-actions[bot]" | |
| git add subworkflows/ | |
| git status | |
| git commit -m "[automated] Update subworkflows ${{ needs.module-added.outputs.class_name }} snapshot" | |
| git push |