Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration option to trigger a rebuild if a variable changes #394

Open
lukbukkit opened this issue Nov 1, 2020 · 3 comments
Open

Configuration option to trigger a rebuild if a variable changes #394

lukbukkit opened this issue Nov 1, 2020 · 3 comments
Labels
area: variables Changes related to variables.

Comments

@lukbukkit
Copy link

Hello,
I'm using Task version 3.0.0 on Windows and I'm very happy about this build tool.

While using this program, I noticed one feature would be very helpful: Trigger a rebuild based on the change of a variable.
In my case, it's the PURGE variable which if activated, generates a smaller file.

If I run at first task build assets and then task build assets PURGE=true, no rebuild is triggered. But in this case it would be very useful, because the output file would change. Of course you can use the --force option to always trigger a rebuild.

I tried to implement my own workaround. But this does only work on Unix shells (/bin/bash, Git Bash ...) and not if you're using the PowerShell.

Here you can take a look at my Taskfile.yml

version: '3'

tasks:
  assets:
    desc: Creates the assets using yarn
    dir: resources
    cmds:
      - yarn
      - yarn run build
      - echo "{{if .PURGE}}true{{else}}false{{end}}" > last_build_mode # my workaround
    sources:
      - styles.css
    generates:
      - output.css
    status:
      - cat last_build_mode
      - test "{{if .PURGE}}true{{else}}false{{end}}" = $(cat last_build_mode) # my workaround
    env:
      NODE_ENV:
        sh: echo {{if .PURGE}} production {{else}} development {{end}}

My suggestion would be to add a new field like var-deps, where you can specify variables which trigger a rebuild.

version: '3'

tasks:
  assets:
    desc: Creates the assets using yarn
    dir: resources
    cmds:
      - yarn
      - yarn run build
    sources:
      - styles.css
    generates:
      - output.css
    var-deps: 
      - PURGE

Thanks a lot for this useful software. :)

@andreynering andreynering added type: feature A new feature or functionality. proposal area: variables Changes related to variables. labels Dec 5, 2020
@andreynering
Copy link
Member

Hi @lukbukkit, thanks for opening this issue!

This sounds like a very valid use case / feature request.

@andreynering
Copy link
Member

andreynering commented Jun 13, 2021

I'd like to note that, specifically for sources when using the checksum mode, there's actually a way of achieving that currently:

version: '3'

tasks:
  my-task:
    # ...
    label: 'my-task-{{.VARIABLE}}'

The label: prop is used to identify the task, so concatenating a variable there will make it have a different key when that changes.

This will not work for timestamp mode or plain status:, though. So this feature request still makes sense.

@sylv-io
Copy link
Contributor

sylv-io commented Jul 30, 2021

There is an alternative workaround by using a helper script for status:
system-transparency/system-transparency@38fd6cb

tl;dr: it creates a config file under .task/config/<target> based on a variable name pattern. Any change does trigger a rebuild.

However the script .task_config.sh is written specifically for the project, but you could adapt it to generate a sub-config based on your own variable name pattern.

IMHO this could be a great new task feature 👍 If there is interest, i would give it a try.

@pd93 pd93 removed type: feature A new feature or functionality. type: proposal labels Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: variables Changes related to variables.
Projects
None yet
Development

No branches or pull requests

4 participants