Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ correct key is provided set in `git_crypt_key`.

* `short_ref_format`: *Optional.* When populating `.git/short_ref` use this `printf` format. Defaults to `%s`.

* `timestamp_format`: *Optional.* When populating `.git/commit_timestamp` use this options to pass to [`git log --date`](https://git-scm.com/docs/git-log#Documentation/git-log.txt---dateltformatgt). Defaults to `iso8601`.

* `describe_ref_options`: *Optional.* When populating `.git/describe_ref` use this options to call [`git describe`](https://git-scm.com/docs/git-describe). Defaults to `--always --dirty --broken`.

#### GPG signature verification
Expand All @@ -261,6 +263,8 @@ the case.

* `.git/commit_message`: For publishing the Git commit message on successful builds.

* `.git/commit_timestamp`: For tagging builds with a timestamp.

* `.git/describe_ref`: Version reference detected and checked out. Can be templated with `describe_ref_options` parameter.
By default, it will contain the `<latest annoted git tag>-<the number of commit since the tag>-g<short_ref>` (eg. `v1.6.2-1-g13dfd7b`).
If the repo was never tagged before, this falls back to a short commit SHA-1 ref.
Expand Down
4 changes: 4 additions & 0 deletions assets/in
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ gpg_keyserver=$(jq -r '.source.gpg_keyserver // "hkp://ipv4.pool.sks-keyservers.
disable_git_lfs=$(jq -r '(.params.disable_git_lfs // false)' < $payload)
clean_tags=$(jq -r '(.params.clean_tags // false)' < $payload)
short_ref_format=$(jq -r '(.params.short_ref_format // "%s")' < $payload)
timestamp_format=$(jq -r '(.params.timestamp_format // "iso8601")' < $payload)
describe_ref_options=$(jq -r '(.params.describe_ref_options // "--always --dirty --broken")' < $payload)

# If params not defined, get it from source
Expand Down Expand Up @@ -197,6 +198,9 @@ echo "${return_ref}" | cut -c1-7 | awk "{ printf \"${short_ref_format}\", \$1 }"
# for example
git log -1 --format=format:%B > .git/commit_message

# Store commit date in .git/commit_timestamp. Can be used for tagging builds
git log -1 --format=%cd --date=${timestamp_format} > .git/commit_timestamp

# Store describe_ref when available. Useful to build Docker images with
# a custom tag, or package to publish
echo "$(git describe ${describe_ref_options})" > .git/describe_ref
Expand Down
27 changes: 27 additions & 0 deletions test/get.sh
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,32 @@ it_can_get_commit_message() {
( echo "Commit message does not match."; return 1 )
}

it_can_get_commit_timestamps() {
run test_commit_timestamp_format "iso8601"
run test_commit_timestamp_format "iso-strict"
run test_commit_timestamp_format "rfc"
run test_commit_timestamp_format "short"
run test_commit_timestamp_format "raw"
run test_commit_timestamp_format "unix"
}

test_commit_timestamp_format() {
local repo=$(init_repo)
local commit_message='Time-is-relevant!'
local ref=$(make_commit $repo $commit_message)
local dest=$TMPDIR/destination

get_uri_with_custom_timestamp $repo $dest $1

pushd $dest
local expected_timestamp=$(git log -1 --date=$1 --format=format:%cd)
popd

test -e $dest/.git/commit_timestamp || ( echo ".git/commit_timestamp does not exist."; return 1 )
test "$(cat $dest/.git/commit_timestamp)" = "$expected_timestamp" || \
( echo "Commit timestamp for format $1 differs from expectation."; return 1 )
}

it_decrypts_git_crypted_files() {
local repo=$(git_crypt_fixture_repo_path)
local dest=$TMPDIR/destination
Expand Down Expand Up @@ -831,6 +857,7 @@ run it_can_get_signed_commit_via_tag
run it_can_get_committer_email
run it_can_get_returned_ref
run it_can_get_commit_message
run it_can_get_commit_timestamps
run it_decrypts_git_crypted_files
run it_clears_tags_with_clean_tags_param
run it_retains_tags_by_default
Expand Down
11 changes: 11 additions & 0 deletions test/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,17 @@ get_uri_with_clean_tags() {
}" | ${resource_dir}/in "$2" | tee /dev/stderr
}

get_uri_with_custom_timestamp() {
jq -n "{
source: {
uri: $(echo $1 | jq -R .),
},
params: {
timestamp_format: \"$3\"
}
}" | ${resource_dir}/in "$2" | tee /dev/stderr
}

put_uri() {
jq -n "{
source: {
Expand Down