---
platform: linux

image_resource:
  type: registry-image
  source:
    repository: alpine/git

inputs:
- name: repo

outputs:
- name: package-version

run:
  path: ash
  args:
  - -exc
  - |
    latest=$(cd repo;git tag -l '20*'|tail -1)  # TODO: use shell logic only
    latest_date=${latest/.*}
    todays_date=$(date '+%Y%m%d')
    latest_build=0
    if [[ $latest_date == $todays_date ]]; then
      latest_build=${latest/*.}
      latest_build=$((latest_build+1))
    fi
    printf "%s.%02d\n" "${todays_date}" "${latest_build}" | tee package-version/version
