terraform-docs icon indicating copy to clipboard operation
terraform-docs copied to clipboard

run docs only on folders where content has changed

Open Marcus-James-Adams opened this issue 4 years ago • 1 comments

I think this is what #17 is referencing.

But we too run a mono repo for lots of projects.

It may be that the solution is with int git hub actions side of things to only pass to tf_docs_working_dir a list of folders where the code has actually changed

I would like the ability to restrict docs to execute only in those subfolders that contain terraform code that has actually changed. This is to avoid docs files being recreated on folders with no changes and skewing timestamps and diffs.

Marcus-James-Adams avatar Nov 26 '20 19:11 Marcus-James-Adams

Would be a nice addition in the action.

We solved this by adding another run bash step that return the changed module as a list which terraform doc uses:

     - uses: actions/checkout@v2
        with:
          ref: ${{ github.ref }}
          fetch-depth: 0

      - name: Get changed modules
        shell: bash
        run: |
          BLOCK_LIST=(".github" "bin" "_example-module" "configs")
          CHANGED_FILES=$(git diff --name-only origin/master..${{ github.ref }} | cut -f1 -d'/' | sort -u)
          for FILE in $CHANGED_FILES; do
            # Ignore all entries in blocklist
            [[ " ${BLOCK_LIST[@]} " =~ " $FILE " ]] && continue
            # Ignore all entries that are not folders, and append to MODULES variable
            [[ -d ${FILE} ]] && MODULES="${MODULES},${FILE}"
          done
          # Strip the first comma from the list of modules and make it an environment variable
          echo "Modules that have been changed: ${MODULES:1}"
          echo MODULES=${MODULES:1} >> $GITHUB_ENV
          
       - name: Automatically generated docs
        uses: Dirrk/[email protected] 
        with:
          tf_docs_working_dir: ${{ env.MODULES }}

tomasbackman avatar Jan 28 '21 11:01 tomasbackman