-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(check): add check script forwarding to git-resource
using test-infra from git-resource
- Loading branch information
1 parent
7e42c5e
commit b5bc1fb
Showing
9 changed files
with
202 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.swp | ||
test/gpg/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM concourse/git-resource as resource | ||
|
||
RUN mv /opt/resource /opt/git-resource | ||
|
||
ADD assets/ /opt/resource/ | ||
RUN chmod +x /opt/resource/* | ||
|
||
|
||
FROM resource AS tests | ||
ADD test/ /tests | ||
RUN /tests/all.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,35 @@ | ||
# gate-resource | ||
|
||
A generic quality-gate resource for Concourse CI | ||
|
||
## Development | ||
|
||
### Prerequisites | ||
|
||
* docker is *required* - version 17.06.x is tested; earlier versions may also | ||
work. | ||
|
||
### Running the tests | ||
|
||
The tests have been embedded with the `Dockerfile`; ensuring that the testing | ||
environment is consistent across any `docker` enabled platform. When the docker | ||
image builds, the test are run inside the docker container, on failure they | ||
will stop the build. | ||
|
||
Run the tests with the following command: | ||
|
||
```sh | ||
docker build -t gate-resource . | ||
``` | ||
|
||
#### Note about the integration tests | ||
|
||
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, | ||
`[email protected]:concourse-git-tester/git-resource-integration-tests.git` or | ||
`[email protected]:concourse-git-tester/git-resource-integration-tests.git#testing` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
# vim: set ft=sh | ||
|
||
set -e | ||
|
||
exec 3>&1 # make stdout available as fd 3 for the result | ||
exec 1>&2 # redirect all output to stderr for logging | ||
|
||
payload=$TMPDIR/gate-resource-request | ||
cat > $payload <&0 | ||
|
||
# extract git configuration and pass it to git resource | ||
git_source=$(cat "$payload" | jq -r .source.git) | ||
git_payload=$(echo '{ "source": '$git_source' }' | jq -r) | ||
|
||
# forward to git-resource | ||
echo "$git_payload" | /opt/git-resource/check $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"source": { | ||
"git": { | ||
"uri": "/tmp/git-tests.okbgNh/git-tests.PKjJDj/repo.njodkK" | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#! /usr/bin/env node | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# $(dirname $0)/image.sh | ||
$(dirname $0)/check.sh | ||
# $(dirname $0)/get.sh | ||
# $(dirname $0)/put.sh | ||
|
||
echo -e '\e[32mall tests passed!\e[0m' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
source $(dirname $0)/helpers.sh | ||
|
||
it_can_check_from_head() { | ||
local repo=$(init_repo) | ||
local ref=$(make_commit $repo) | ||
|
||
check_uri $repo | jq -e " | ||
. == [{ref: $(echo $ref | jq -R .)}] | ||
" | ||
} | ||
|
||
run it_can_check_from_head |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#!/bin/bash | ||
|
||
set -e -u | ||
|
||
set -o pipefail | ||
|
||
export TMPDIR_ROOT=$(mktemp -d /tmp/git-tests.XXXXXX) | ||
trap "rm -rf $TMPDIR_ROOT" EXIT | ||
|
||
if [ -d /opt/resource ]; then | ||
resource_dir=/opt/resource | ||
else | ||
resource_dir=$(cd $(dirname $0)/../assets && pwd) | ||
fi | ||
test_dir=$(cd $(dirname $0) && pwd) | ||
keygrip=276D99F5B65388AF85DF54B16B08EF0A44C617AC | ||
fingerprint=A3E20CD6371D49E244B0730D1CDD25AEB0F5F8EF | ||
|
||
run() { | ||
export TMPDIR=$(mktemp -d ${TMPDIR_ROOT}/git-tests.XXXXXX) | ||
|
||
echo -e 'running \e[33m'"$@"$'\e[0m...' | ||
eval "$@" 2>&1 | sed -e 's/^/ /g' | ||
echo "" | ||
} | ||
|
||
init_repo() { | ||
( | ||
set -e | ||
|
||
cd $(mktemp -d $TMPDIR/repo.XXXXXX) | ||
|
||
git init -q | ||
|
||
# start with an initial commit | ||
git \ | ||
-c user.name='test' \ | ||
-c user.email='[email protected]' \ | ||
commit -q --allow-empty -m "init" | ||
|
||
# create some bogus branch | ||
git checkout -b bogus | ||
|
||
git \ | ||
-c user.name='test' \ | ||
-c user.email='[email protected]' \ | ||
commit -q --allow-empty -m "commit on other branch" | ||
|
||
# back to master | ||
git checkout master | ||
|
||
# print resulting repo | ||
pwd | ||
) | ||
} | ||
|
||
check_uri() { | ||
jq -n "{ | ||
source: { | ||
git: { | ||
uri: $(echo $1 | jq -R .) | ||
} | ||
} | ||
}" | ${resource_dir}/check | tee /dev/stderr | ||
} | ||
|
||
make_commit_to_file_on_branch() { | ||
local repo=$1 | ||
local file=$2 | ||
local branch=$3 | ||
local msg=${4-} | ||
|
||
# ensure branch exists | ||
if ! git -C $repo rev-parse --verify $branch >/dev/null; then | ||
git -C $repo branch $branch master | ||
fi | ||
|
||
# switch to branch | ||
git -C $repo checkout -q $branch | ||
|
||
# modify file and commit | ||
echo x >> $repo/$file | ||
git -C $repo add $file | ||
git -C $repo \ | ||
-c user.name='test' \ | ||
-c user.email='[email protected]' \ | ||
commit -q -m "commit $(wc -l $repo/$file) $msg" | ||
|
||
# output resulting sha | ||
git -C $repo rev-parse HEAD | ||
} | ||
|
||
make_commit_to_file() { | ||
make_commit_to_file_on_branch $1 $2 master "${3-}" | ||
} | ||
|
||
make_commit_to_branch() { | ||
make_commit_to_file_on_branch $1 some-file $2 | ||
} | ||
|
||
make_commit() { | ||
make_commit_to_file $1 some-file "${2:-}" | ||
} |