Repository: go-task/task

Issue #411: Make using both `sources` and `status` work
Created: 2020-11-30T12:00:39Z
I have a build task that takes in variables to decide which platform to build for.
I'm trying to find some way to tell Task that the job is up-to-date using the standard sources checksum plus also checking whether the platform variables have changed.
I can get one to work at a time, but not both as the status commands seem to take precedence over the sources meaning if you specify commands for status, the sources are ignored.
Is there any way to have both the sources and status checked? Otherwise is there any way to add specific variables to the sources somehow? It might be I'm missing something obvious but I can't see a way of achieving this.
Many thanks in advance and thank you for the fantastic tool!
Here's a snippet of my Taskfile.yml:
version: "3"

silent: true

vars:
  PROJECT_NAME: my-project

  VERSION:
    sh: echo "${VERSION:-$(git describe --tags --always 2> /dev/null)}"

  BUILD_TIME:
    sh: date -u +"%Y-%m-%dT%H:%M:%SZ"

  PACKAGENAME:
    sh: go list 2> /dev/null || true

  LD_FLAGS: >
    -ldflags "-X '{{.PACKAGENAME}}/version.Version={{.VERSION}}'
    -X '{{.PACKAGENAME}}/version.BuildTime={{.BUILD_TIME}}'"

tasks:
  default:
    cmds:
      - task: build

  build:
    desc: Build API executable for native platform platform specified by variables.
    cmds:
      - echo Building executable...
      - CGO_ENABLED="{{.CGO_ENABLED}}" GOOS="{{.GOOS}}" GOARCH="{{.GOARCH}}" go build {{.LD_FLAGS}}
      - echo "{{.GOOS}}-{{.GOARCH}}-{{.CGO_ENABLED}}" > .task/build-platform
    sources:
      - "**/*.go"
      - go.mod
      - go.sum
    status:
      - test -f .task/build-platform
      - "[ $(cat .task/build-platform) == \"{{.GOOS}}-{{.GOARCH}}-{{.CGO_ENABLED}}\" ]"
    generates:
      - "{{.PROJECT_NAME}}"

  build-linux:
    desc: Build Linux API executable.
    cmds:
      - echo Building Linux executable...
      - task: build
        vars:
          CGO_ENABLED: 0
          GOOS: linux
          GOARCH: amd64

Duplicate issue #427: Sources and status do not interoperate
Created: 2021-01-11T18:47:19Z
Task version: 3.2.0
Operating System: darwin

Description
The sources and status checks do not seem to interoperate.  If status returns 0, in this case the docker image exists, task is  skipping the source checks.
Expectation
I would expect a change to a listed source file OR a missing docker image to trigger a build.
Example Taskfile showing the issue
tasks:
  build-dev:
    cmds:
      - docker buildx bake -f app_build/docker-bake.hcl -f app_build/docker-bake.override.hcl dev

    preconditions:
      - sh: "jq --version"
        msg: "You must have jq installed, https://github.com/stedolan/jq/wiki/Installation"
      - sh: "[ $(cat ~/.docker/config.json | jq -r '.auths | has(\"foo.dkr.ecr.us-east-1.amazonaws.com\")') == \"true\" ]"
        msg: "Docker is not logged into ECR, run task aws-login"

    status:
      # Check for the alerting-service:dev docker image, if it does not exist trigger a build
      - "[ ! -z \"$(docker image list --format \"{{\"{{\"}}json .{{\"}}\"}}\" | jq -s '.' | jq -c '.[] | select(.Repository == \"alerting-service\" and .Tag == \"dev\")')\" ]"

    method: checksum
    sources:
      - ./requirements.txt
      - ./Dockerfile

Closing comment (2021-01-11T19:00:55Z): I just noticed that this is probably a dupe of: #411