Add tag names

This commit is contained in:
Lars Gohr
2019-10-18 22:06:08 +02:00
parent cade1bc239
commit a770e120e6
4 changed files with 34 additions and 0 deletions

View File

@@ -116,3 +116,15 @@ with:
password: ${{ secrets.DOCKER_PASSWORD }}
cache: true
```
### tag_names
Use `tag_names` when you want to push tags/release by their git name (e.g. `refs/tags/MY_TAG_NAME`).
> CAUTION: Images produced by this feature can be override by branches with the same name - without a way to restore.
```yaml
with:
name: myDocker/repository
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
tag_names: true
```

View File

@@ -32,6 +32,9 @@ inputs:
cache:
description: 'Use cache when you have big images, that you would only like to build partially'
required: false
tag_names:
description: 'Use tag_names when you want to push tags/release by their git name'
required: false
outputs:
tag:
description: 'Is the tag, which was pushed'

View File

@@ -62,6 +62,8 @@ function translateDockerTag() {
INPUT_NAME=$(echo ${INPUT_NAME} | cut -d':' -f1)
elif isOnMaster; then
TAG="latest"
elif isGitTag && uses "${INPUT_TAG_NAMES}"; then
TAG=$(echo ${GITHUB_REF} | sed -e "s/refs\/tags\///g")
elif isGitTag; then
TAG="latest"
elif isPullRequest; then

View File

@@ -8,6 +8,7 @@ setup(){
}
teardown() {
unset INPUT_TAG_NAMES
unset INPUT_SNAPSHOT
unset INPUT_DOCKERFILE
unset INPUT_REGISTRY
@@ -77,6 +78,22 @@ Called /usr/local/bin/docker logout"
[ "$output" = "$expected" ]
}
@test "with tag names it pushes tags using the name" {
export GITHUB_REF='refs/tags/myRelease'
export INPUT_TAG_NAMES=true
run /entrypoint.sh
local expected="
Called /usr/local/bin/docker login -u USERNAME --password-stdin
Called /usr/local/bin/docker build -t my/repository:myRelease .
Called /usr/local/bin/docker push my/repository:myRelease
::set-output name=tag::myRelease
Called /usr/local/bin/docker logout"
echo $output
[ "$output" = "$expected" ]
}
@test "it pushes specific Dockerfile to latest" {
export INPUT_DOCKERFILE='MyDockerFileName'