From 34e806df968decc3026d2461d174335e315b990f Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Fri, 18 Sep 2020 15:38:33 -0600 Subject: [PATCH] Maybe smart image tags? --- .github/workflows/build+test.yml | 24 +++++------------------- build/ci/gitlab-vars | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 19 deletions(-) create mode 100755 build/ci/gitlab-vars diff --git a/.github/workflows/build+test.yml b/.github/workflows/build+test.yml index 4c83c4d..406dbbd 100644 --- a/.github/workflows/build+test.yml +++ b/.github/workflows/build+test.yml @@ -32,23 +32,11 @@ jobs: - name: Retrieve code uses: actions/checkout@v2 - - name: Get current branch + - name: Gitlab variables id: vars - run: | - echo "GITHUB_REF: $GITHUB_REF" - case $GITHUB_REF in - refs/tags/*) - TAGS=latest,${GITHUB_REF#refs/tags/} - ;; - refs/heads/master) - TAGS=latest - ;; - esac - echo "tags: $TAGS" - echo "::set-output name=tags::$TAGS" + run: build/ci/gitlab-vars - name: Login to GitHub Packages Docker Registry - if: steps.vars.tags != '' uses: docker/login-action@v1 with: registry: docker.pkg.github.com @@ -56,7 +44,6 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Login to DockerHub - if: steps.vars.tags != '' uses: docker/login-action@v1 with: username: neale @@ -67,15 +54,14 @@ jobs: with: target: moth file: build/package/Containerfile - tags: | - dirtbags/moth:latest - docker.pkg.github.com/dirtbags/moth/moth:latest + push: ${{ steps.vars.outputs.tags != '' }} + tags: ${{ steps.vars.outputs.moth-tags }} - name: Build and push moth-devel image uses: docker/build-push-action@v2 with: target: moth file: build/package/Containerfile - tags: | + tags: ${{ steps.vars.outputs.devel-tags }} dirtbags/moth-devel:latest docker.pkg.github.com/dirtbags/moth/moth-devel:latest diff --git a/build/ci/gitlab-vars b/build/ci/gitlab-vars new file mode 100755 index 0000000..582d871 --- /dev/null +++ b/build/ci/gitlab-vars @@ -0,0 +1,25 @@ +#! /bin/sh + +case $1 in + -h|-help|--help) + echo "Usage: $0 TARGET" + echo + echo "Sets CI build variables for gitlab" + exit 1 + ;; +esac + +branch=$(git symbolic-ref -q --short HEAD) +if [ "$branch" = "main" ]; then + branch=latest +fi + +printf "Branch: %s\n" "$branch" +printf "::set-output name=branch::%s\n" "$branch" +printf "::set-output name=tag::%s\n" "$branch" + +# I think it will use whichever comes last +git tag --points-at HEAD | while read tag; do + printf "Tag: %s\n" "$tag" + printf "::set-output name=tag::%s\n" "$tag" +done