{"action":"created","issue":{"url":"https://api.github.com/repos/habitat-sh/habitat/issues/2235","repository_url":"https://api.github.com/repos/habitat-sh/habitat","labels_url":"https://api.github.com/repos/habitat-sh/habitat/issues/2235/labels{/name}","comments_url":"https://api.github.com/repos/habitat-sh/habitat/issues/2235/comments","events_url":"https://api.github.com/repos/habitat-sh/habitat/issues/2235/events","html_url":"https://github.com/habitat-sh/habitat/pull/2235","id":226476546,"number":2235,"title":"[plan-build] Add optional helper to dynamically compute pkg_version.","user":{"login":"fnichol","id":261548,"avatar_url":"https://avatars1.githubusercontent.com/u/261548?v=3","gravatar_id":"","url":"https://api.github.com/users/fnichol","html_url":"https://github.com/fnichol","followers_url":"https://api.github.com/users/fnichol/followers","following_url":"https://api.github.com/users/fnichol/following{/other_user}","gists_url":"https://api.github.com/users/fnichol/gists{/gist_id}","starred_url":"https://api.github.com/users/fnichol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fnichol/subscriptions","organizations_url":"https://api.github.com/users/fnichol/orgs","repos_url":"https://api.github.com/users/fnichol/repos","events_url":"https://api.github.com/users/fnichol/events{/privacy}","received_events_url":"https://api.github.com/users/fnichol/received_events","type":"User","site_admin":false},"labels":[{"id":390274553,"url":"https://api.github.com/repos/habitat-sh/habitat/labels/Feature","name":"Feature","color":"1d76db","default":false},{"id":530455951,"url":"https://api.github.com/repos/habitat-sh/habitat/labels/Linux","name":"Linux","color":"bfdadc","default":false},{"id":446446011,"url":"https://api.github.com/repos/habitat-sh/habitat/labels/Plan-Build","name":"Plan-Build","color":"b60205","default":false}],"state":"open","locked":false,"assignee":{"login":"fnichol","id":261548,"avatar_url":"https://avatars1.githubusercontent.com/u/261548?v=3","gravatar_id":"","url":"https://api.github.com/users/fnichol","html_url":"https://github.com/fnichol","followers_url":"https://api.github.com/users/fnichol/followers","following_url":"https://api.github.com/users/fnichol/following{/other_user}","gists_url":"https://api.github.com/users/fnichol/gists{/gist_id}","starred_url":"https://api.github.com/users/fnichol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fnichol/subscriptions","organizations_url":"https://api.github.com/users/fnichol/orgs","repos_url":"https://api.github.com/users/fnichol/repos","events_url":"https://api.github.com/users/fnichol/events{/privacy}","received_events_url":"https://api.github.com/users/fnichol/received_events","type":"User","site_admin":false},"assignees":[{"login":"fnichol","id":261548,"avatar_url":"https://avatars1.githubusercontent.com/u/261548?v=3","gravatar_id":"","url":"https://api.github.com/users/fnichol","html_url":"https://github.com/fnichol","followers_url":"https://api.github.com/users/fnichol/followers","following_url":"https://api.github.com/users/fnichol/following{/other_user}","gists_url":"https://api.github.com/users/fnichol/gists{/gist_id}","starred_url":"https://api.github.com/users/fnichol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fnichol/subscriptions","organizations_url":"https://api.github.com/users/fnichol/orgs","repos_url":"https://api.github.com/users/fnichol/repos","events_url":"https://api.github.com/users/fnichol/events{/privacy}","received_events_url":"https://api.github.com/users/fnichol/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/habitat-sh/habitat/milestones/6","html_url":"https://github.com/habitat-sh/habitat/milestone/6","labels_url":"https://api.github.com/repos/habitat-sh/habitat/milestones/6/labels","id":2392161,"number":6,"title":"Pokemon Village","description":"","creator":{"login":"reset","id":54036,"avatar_url":"https://avatars2.githubusercontent.com/u/54036?v=3","gravatar_id":"","url":"https://api.github.com/users/reset","html_url":"https://github.com/reset","followers_url":"https://api.github.com/users/reset/followers","following_url":"https://api.github.com/users/reset/following{/other_user}","gists_url":"https://api.github.com/users/reset/gists{/gist_id}","starred_url":"https://api.github.com/users/reset/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reset/subscriptions","organizations_url":"https://api.github.com/users/reset/orgs","repos_url":"https://api.github.com/users/reset/repos","events_url":"https://api.github.com/users/reset/events{/privacy}","received_events_url":"https://api.github.com/users/reset/received_events","type":"User","site_admin":false},"open_issues":34,"closed_issues":46,"state":"open","created_at":"2017-03-16T23:44:37Z","updated_at":"2017-05-05T06:33:13Z","due_on":"2017-05-19T07:00:00Z","closed_at":null},"comments":5,"created_at":"2017-05-05T05:22:27Z","updated_at":"2017-05-05T07:43:38Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/habitat-sh/habitat/pulls/2235","html_url":"https://github.com/habitat-sh/habitat/pull/2235","diff_url":"https://github.com/habitat-sh/habitat/pull/2235.diff","patch_url":"https://github.com/habitat-sh/habitat/pull/2235.patch"},"body":"(Note: this builds on #2234, which should be merged first)\r\n\r\nThis change adds an alternative way to determine the version of a Plan\r\nwhen building a package. In seeing more Plans in the wild, it has become\r\nclear that some Plan authors wish to determine the package version by\r\ncat'ing a common version file, using a Git command, or by some other\r\nmeans which is dynamic.\r\n\r\nThere are 2 challenges to computing a package version:\r\n\r\n* how the version is computed\r\n* when the version should be computed\r\n\r\nTo implement the \"how\", a Plan author needs to write a `pkg_version()`\r\nfunction that prints the version string to standard output. The Plan\r\nauthor then explicitly calls the new `update_pkg_version()` helper in a\r\nbuild phase to determine the \"when\".\r\n\r\nThe `update_pkg_version()` can be called in the `do_before()` build\r\nphase all the way up to but not including the `do_prepare()` build\r\nphase, after which it is too late to safely recompute the other build\r\nvariables that depend on `$pkg_version`. If `update_pkg_version()` is\r\ncalled too late, the build program will fail the build with an error\r\nmessage.\r\n\r\nDue to this new optional strategy, a Plan author can omit defining a\r\n`pkg_version` variable, as long as they write a `pkg_version()`\r\nfunction. This is checked for by the build program so that if the Plan\r\nauthor omits the `pkg_version` variable and the `pkg_version()`\r\nfunction, the build will fail.\r\n\r\nExamples\r\n--------\r\n\r\nThe following are partial Plan implementations with extra build phases\r\nomitted for brevity.\r\n\r\nThis is a Plan which cats a static file in the source root of the\r\nproject to determine the version which can be safely determined in the\r\n`do_before()` phase:\r\n\r\n```\r\npkg_origin=acme\r\npkg_name=myapp\r\n\r\npkg_version() {\r\n  cat \"$SRC_PATH/version.txt\"\r\n}\r\n\r\ndo_before() {\r\n  do_default_before\r\n  update_pkg_version\r\n}\r\n```\r\n\r\nHere is the same Plan which uses a Git command to compute the number of\r\ncommits in the repository as the version. Note that since we are using\r\nthe `git` command, we are adding the `core/git` package as a build\r\ndependency:\r\n\r\n```\r\npkg_origin=acme\r\npkg_name=myapp\r\npkg_build_deps=(core/git)\r\n\r\npkg_version() {\r\n  git rev-list master --count\r\n}\r\n\r\ndo_before() {\r\n  do_default_before\r\n  update_pkg_version\r\n}\r\n```\r\n\r\nFinally, here is a partial implementation of a `cacerts` Plan which\r\ngreps a date (YYYY.mm.dd) from the CA certs file itself. The\r\n`pkg_version()` function does some grep'ing and sed'ing before using the\r\ndate program to format the final version string to standard output. As\r\nthe downloaded file is required before running the version logic, the\r\n`update_pkg_version()` helper is called in the `do_download()` build\r\nphase:\r\n\r\n```\r\npkg_origin=me\r\npkg_name=cacerts\r\npkg_source=http://curl.haxx.se/ca/cacert.pem\r\n\r\npkg_version() {\r\n  local build_date\r\n\r\n  # Extract the build date of the certificates file\r\n  build_date=$(cat $HAB_CACHE_SRC_PATH/$pkg_filename \\\r\n    | grep 'Certificate data from Mozilla' \\\r\n    | sed 's/^## Certificate data from Mozilla as of: //')\r\n\r\n  date --date=\"$build_date\" \"+%Y.%m.%d\"\r\n}\r\n\r\ndo_download() {\r\n  do_default_download\r\n  update_pkg_version\r\n}\r\n\r\n # ...\r\n```\r\n\r\nCloses #2212 \r\n\r\n![gif-keyboard-7704575195338198960](https://cloud.githubusercontent.com/assets/261548/25734451/32acbf86-3120-11e7-8195-d28cbd8803ff.gif)\r\n"},"comment":{"url":"https://api.github.com/repos/habitat-sh/habitat/issues/comments/299402517","html_url":"https://github.com/habitat-sh/habitat/pull/2235#issuecomment-299402517","issue_url":"https://api.github.com/repos/habitat-sh/habitat/issues/2235","id":299402517,"user":{"login":"thesentinels","id":18452204,"avatar_url":"https://avatars0.githubusercontent.com/u/18452204?v=3","gravatar_id":"","url":"https://api.github.com/users/thesentinels","html_url":"https://github.com/thesentinels","followers_url":"https://api.github.com/users/thesentinels/followers","following_url":"https://api.github.com/users/thesentinels/following{/other_user}","gists_url":"https://api.github.com/users/thesentinels/gists{/gist_id}","starred_url":"https://api.github.com/users/thesentinels/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thesentinels/subscriptions","organizations_url":"https://api.github.com/users/thesentinels/orgs","repos_url":"https://api.github.com/users/thesentinels/repos","events_url":"https://api.github.com/users/thesentinels/events{/privacy}","received_events_url":"https://api.github.com/users/thesentinels/received_events","type":"User","site_admin":false},"created_at":"2017-05-05T07:43:38Z","updated_at":"2017-05-05T07:43:38Z","body":":sparkling_heart: Travis CI [reports this PR passed](https://travis-ci.org/habitat-sh/habitat/builds/229022421).\n\nIt always makes me feel nice when humans approve of one anothers work. I'm merging this PR now.\n\nI just want you and the contributor to answer me one question:\n\n![gif-keyboard-3280869874741411265](https://cloud.githubusercontent.com/assets/4304/17755674/1e577b82-6490-11e6-96b7-1663d283c824.gif)"}}
{"actor":{"display_login":"thesentinels"}}