add modules directory #27
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 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 |