diff --git a/README.md b/README.md index ba27bbe..1c30814 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,17 @@ with: dockerfile: MyDockerFileName ``` +### workdir +Use `workdir` when you would like to change the directory for building. + +```yaml +with: + name: myDocker/repository + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + workdir: mySubDirectory +``` + ### cache Use `cache` when you have big images, that you would only like to build partially (changed layers). > CAUTION: This will cache the non changed parts forever. If you use this option, make sure that these parts will be updated by another job! diff --git a/entrypoint.sh b/entrypoint.sh index 1ba1a63..2b95e42 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -35,6 +35,10 @@ if [ $(echo ${GITHUB_REF} | sed -e "s/refs\/pull\///g") != ${GITHUB_REF} ]; then BRANCH="pr$(echo ${GITHUB_REF} | sed -e "s/refs\/pull\///g" | sed -e "s/\///g")" fi; +if [ ! -z "${INPUT_WORKDIR}" ]; then + cd "${INPUT_WORKDIR}" +fi + echo ${INPUT_PASSWORD} | docker login -u ${INPUT_USERNAME} --password-stdin ${INPUT_REGISTRY} DOCKERNAME="${INPUT_NAME}:${BRANCH}" diff --git a/test.bats b/test.bats index a16b6ef..eabbabd 100755 --- a/test.bats +++ b/test.bats @@ -256,3 +256,14 @@ Called /usr/local/bin/docker logout" [ "$status" -eq 1 ] [ "$output" = "$expected" ] } + +@test "it errors when the working directory is configured but not present" { + export INPUT_WORKDIR='mySubDir' + + run /entrypoint.sh + + local expected="/entrypoint.sh: cd: line 39: can't cd to mySubDir: No such file or directory" + echo "$output" + [ "$status" -eq 2 ] + [ "$output" = "$expected" ] +}