From a87e473f02c986cdb366d42d586700c35e304ff3 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Thu, 10 Oct 2019 15:27:06 +0200 Subject: [PATCH 1/3] fix markdown syntax Signed-off-by: David Bernard --- README.md | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 40da7662..0015b804 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ Tracks the commits in a [git](http://git-scm.com/) repository. - ## Source Configuration * `uri`: *Required.* The location of the repository. @@ -10,10 +9,10 @@ Tracks the commits in a [git](http://git-scm.com/) repository. * `branch`: The branch to track. This is *optional* if the resource is only used in `get` steps; however, it is *required* when used in a `put` step. If unset for `get`, the repository's default branch is used; usually `master` but [could be different](https://help.github.com/articles/setting-the-default-branch/). - * `private_key`: *Optional.* Private key to use when pulling/pushing. Example: - ``` + + ```yaml private_key: | -----BEGIN RSA PRIVATE KEY----- MIIEowIBAAKCAQEAtCS10/f7W7lkQaSgD/mVeaSOvSF9ql4hf/zfMwfVGgHWjj+W @@ -74,7 +73,6 @@ Tracks the commits in a [git](http://git-scm.com/) repository. * `gpg_keyserver`: *Optional.* GPG keyserver to download the public keys from. Defaults to `hkp:///keys.gnupg.net/`. - * `git_crypt_key`: *Optional.* Base64 encoded [git-crypt](https://github.com/AGWA/git-crypt) key. Setting this will unlock / decrypt the repository with `git-crypt`. To get the key simply @@ -82,12 +80,11 @@ Tracks the commits in a [git](http://git-scm.com/) repository. * `https_tunnel`: *Optional.* Information about an HTTPS proxy that will be used to tunnel SSH-based git commands over. Has the following sub-properties: - * `proxy_host`: *Required.* The host name or IP of the proxy server - * `proxy_port`: *Required.* The proxy server's listening port - * `proxy_user`: *Optional.* If the proxy requires authentication, use this username - * `proxy_password`: *Optional.* If the proxy requires authenticate, - use this password - + * `proxy_host`: *Required.* The host name or IP of the proxy server + * `proxy_port`: *Required.* The proxy server's listening port + * `proxy_user`: *Optional.* If the proxy requires authentication, use this username + * `proxy_password`: *Optional.* If the proxy requires authenticate, use this password + * `commit_filter`: *Optional.* Object containing commit message filters * `commit_filter.exclude`: *Optional.* Array containing strings that should cause a commit to be skipped @@ -192,18 +189,18 @@ the case. #### Additional files populated - * `.git/committer`: For committer notification on failed builds. - This special file `.git/committer` which is populated with the email address - of the author of the last commit. This can be used together with an email - resource like [mdomke/concourse-email-resource](https://github.com/mdomke/concourse-email-resource) - to notify the committer in an on_failure step. +* `.git/committer`: For committer notification on failed builds. + This special file `.git/committer` which is populated with the email address + of the author of the last commit. This can be used together with an email + resource like [mdomke/concourse-email-resource](https://github.com/mdomke/concourse-email-resource) + to notify the committer in an on_failure step. - * `.git/ref`: Version reference detected and checked out. It will usually contain - the commit SHA-1 ref, but also the detected tag name when using `tag_filter`. +* `.git/ref`: Version reference detected and checked out. It will usually contain + the commit SHA-1 ref, but also the detected tag name when using `tag_filter`. - * `.git/short_ref`: Short (first seven characters) of the `.git/ref`. Can be templated with `short_ref_format` parameter. +* `.git/short_ref`: Short (first seven characters) of the `.git/ref`. Can be templated with `short_ref_format` parameter. - * `.git/commit_message`: For publishing the Git commit message on successful builds. +* `.git/commit_message`: For publishing the Git commit message on successful builds. ### `out`: Push to a repository. @@ -275,6 +272,7 @@ docker build -t git-resource -f dockerfiles/ubuntu/Dockerfile . If you want to run the integration tests, a bit more work is required. You will require an actual git repo to which you can push and pull, configured for SSH access. To do this, add two files to `integration-tests/ssh` (note that names **are** important): + * `test_key`: This is the private key used to authenticate against your repo. * `test_repo`: This file contains one line of the form `test_repo_url[#test_branch]`. If the branch is not specified, it defaults to `master`. For example, From b970e6b3f9af10929c33283f38c1115a2dbb2324 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Thu, 10 Oct 2019 16:42:24 +0200 Subject: [PATCH 2/3] add generation of `.git/describe_ref` fulfilled via `git describe`. Its contents can then be used to publish package, docker image with unique version. Signed-off-by: David Bernard --- README.md | 21 +++++++++++++++++++++ assets/in | 5 +++++ test/get.sh | 5 +++++ 3 files changed, 31 insertions(+) diff --git a/README.md b/README.md index 0015b804..2b8f6b82 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,23 @@ 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`. +* `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`. + + ```txt + --all use any ref + --tags use any tag, even unannotated + --long always use long format + --first-parent only follow first parent + --abbrev[=] use digits to display SHA-1s + --exact-match only output exact matches + --candidates consider most recent tags (default: 10) + --match only consider tags matching + --exclude do not consider tags matching + --always show abbreviated commit object as fallback + --dirty[=] append on dirty working tree (default: "-dirty") + --broken[=] append on broken working tree (default: "-broken") + ``` + #### GPG signature verification If `commit_verification_keys` or `commit_verification_key_ids` is specified in @@ -202,6 +219,10 @@ the case. * `.git/commit_message`: For publishing the Git commit message on successful builds. +* `.git/describe_ref`: Version reference detected and checked out. Can be templated with `describe_ref_options` parameter. + By default, it will contain the `--g` (eg. `v1.6.2-1-g13dfd7b`). + If the repo was never tagged before, this falls back to a short commit SHA-1 ref. + ### `out`: Push to a repository. Push the checked-out reference to the source's URI and branch. All tags are diff --git a/assets/in b/assets/in index 6f589b0c..2f4f9ed4 100755 --- a/assets/in +++ b/assets/in @@ -49,6 +49,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) +describe_ref_options=$(jq -r '(.params.describe_ref_options // "--always --dirty --broken")' < $payload) configure_git_global "${git_config_payload}" @@ -188,6 +189,10 @@ echo "${return_ref}" | cut -c1-7 | awk "{ printf \"${short_ref_format}\", \$1 }" # for example git log -1 --format=format:%B > .git/commit_message +# 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 + metadata=$(git_metadata) if [ "$clean_tags" == "true" ]; then diff --git a/test/get.sh b/test/get.sh index 7c7ad4b2..dcc93a4b 100755 --- a/test/get.sh +++ b/test/get.sh @@ -652,6 +652,11 @@ it_can_get_returned_ref() { local expected_short_ref="test-$(echo ${ref3} | cut -c1-7)" test "$(cat $dest/.git/short_ref)" = $expected_short_ref || \ ( echo ".git/short_ref does not match. Expected '${expected_short_ref}', got '$(cat $dest/.git/short_ref)'"; return 1 ) + + test -e $dest/.git/describe_ref || ( echo ".git/describe_ref does not exist."; return 1 ) + local expected_describe_ref="0.9-production" + test "$(cat $dest/.git/describe_ref)" = $expected_describe_ref || \ + ( echo ".git/describe_ref does not match. Expected '${expected_describe_ref}', got '$(cat $dest/.git/describe_ref)'"; return 1 ) } it_can_get_commit_message() { From 0e39077d7711b24f8a396a9334eff6a781c00a7c Mon Sep 17 00:00:00 2001 From: David Bernard Date: Fri, 19 Jun 2020 11:47:34 +0200 Subject: [PATCH 3/3] README: remove list of available options for `git describe` Signed-off-by: David Bernard --- README.md | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/README.md b/README.md index 3fd6764d..08ef8f91 100644 --- a/README.md +++ b/README.md @@ -238,21 +238,6 @@ correct key is provided set in `git_crypt_key`. * `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`. - ```txt - --all use any ref - --tags use any tag, even unannotated - --long always use long format - --first-parent only follow first parent - --abbrev[=] use digits to display SHA-1s - --exact-match only output exact matches - --candidates consider most recent tags (default: 10) - --match only consider tags matching - --exclude do not consider tags matching - --always show abbreviated commit object as fallback - --dirty[=] append on dirty working tree (default: "-dirty") - --broken[=] append on broken working tree (default: "-broken") - ``` - #### GPG signature verification If `commit_verification_keys` or `commit_verification_key_ids` is specified in