adds a failed hook for stages

Previously there was no way for third-party hooks to run if a stage fails. Introducing a `failed_#{stage}` hook allows scripts to run code when specific stages fail. For example this is needed for a set of hooks which will use the github project status api to link build pass/failures to commits.