diff --git a/README.md b/README.md index 9b25d04..ebd7624 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1670 TILs and counting..._ +_1671 TILs and counting..._ See some of the other learning resources I work on: @@ -83,6 +83,7 @@ If you've learned something here, support my efforts writing daily TILs by * [SQLite](#sqlite) * [Streaming](#streaming) * [Tailwind CSS](#tailwind-css) +* [Taskfile](#taskfile) * [tmux](#tmux) * [TypeScript](#typescript) * [Unix](#unix) @@ -1494,6 +1495,10 @@ If you've learned something here, support my efforts writing daily TILs by - [Specify Paths For Purging Unused CSS](tailwind/specify-paths-for-purging-unused-css.md) - [Use Tailwind Typography Prose In Dark Mode](tailwind/use-tailwind-typography-prose-in-dark-mode.md) +### Taskfile + +- [Run A Task If It Meets Criteria](taskfile/run-a-task-if-it-meets-criteria.md) + ### tmux - [Access Past Copy Buffer History](tmux/access-past-copy-buffer-history.md) diff --git a/taskfile/run-a-task-if-it-meets-criteria.md b/taskfile/run-a-task-if-it-meets-criteria.md new file mode 100644 index 0000000..084dc5a --- /dev/null +++ b/taskfile/run-a-task-if-it-meets-criteria.md @@ -0,0 +1,31 @@ +# Run A Task If It Meets Criteria + +The [Taskfile `status` +directive](https://taskfile.dev/docs/guide#limiting-when-tasks-run) can be used +to tell a task when it needs to run. If it doesn't need to run, it can be +skipped over. The idea being that we're making a status check to see if we're +up-to-date or need to run the task. + +For instance, here is a `status` check that determines if there are changes to +commit and push. If there are changes to `NOTES.md`, then we are out-of-date and +need to run the `cmds` that make up the task. + +```yaml + notes:push: + desc: Commit and push changes to notes submodule + dir: '{{.NOTES_DIR}}' + cmds: + - git add NOTES.md + - git commit -m "Update notes - $(date '+%Y-%m-%d %H:%M')" + - git push + status: + - git diff --exit-code NOTES.md + silent: false +``` + +This is useful because I don't want the `git add`, `git commit`, and `git push` +commands to run when there is nothing to do. + +Note: this is different from the `preconditions` directive. Instead of +short-circuiting a sequence of tasks, this will either run or skip the task and +move on to the next one.