Skip to content

Instantly share code, notes, and snippets.

@sdwvit

sdwvit/generate.sh

Created Oct 30, 2019
Embed
What would you like to do?
Generate cacheable key for CI depending on versioned files diff
#!/bin/sh
a="$(git diff master... --numstat | awk 'NF==3 {total+=$1+$2} END {printf("%d\n", total)}')" \
if [ "$a" -gt 100 ]
then
echo "bust $(date +%s)" > gitdiff
else
echo "keep" > gitdiff
fi
@sdwvit

This comment has been minimized.

Copy link
Owner Author

@sdwvit sdwvit commented Oct 30, 2019

Some parameters:
100 - describes number of lines changed threshold.
gitdiff - filepath for partial key, editable
bust/keep - editable

Usage example:

  terser_cache_key: &terser_cache_key v1-webpack_terser-{{ checksum "gitdiff" }}
  terser_cache_key_backup: &terser_cache_key_backup v1-webpack_terser-

  restore_terser_cache: &restore_terser_cache
    run:
      name: Generate partial key for terser-cache
      command: |
        #!/bin/sh

        a="$(git diff master... --numstat | awk 'NF==3 {total+=$1+$2} END {printf("%d\n", total)}')" \

        if [ "$a" -gt 100 ]
        then
          echo "bust $(date +%s)" > gitdiff
        else
          echo "keep" > gitdiff
        fi
    restore_cache:
      name: Restoring Cache (/tmp/terser)
      keys:
        - *terser_cache_key
        - *terser_cache_key_backup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment