Skip to content

Commit

Permalink
Merge pull request #13 from vsaw/436-build-darknet-release-on-git-tag
Browse files Browse the repository at this point in the history
Feat: Build darknet release based on git tag and ignore pushes to mas…
  • Loading branch information
vsaw authored Sep 15, 2021
2 parents d0b16ac + 0aa2602 commit b1fb0a3
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@ on:
pull_request:
branches-ignore:
- 'gh-pages'
release:
types: [created]

jobs:
# Build docker images
build-docker-and-publish:
runs-on: ubuntu-latest
# needs: build-and-test-code
env:
# Publish to Docker Hub if we have a change in the development or master branch
DOCKERHUB_PUBLISH: ${{ github.event_name == 'push' && (github.event.ref == 'refs/heads/development' || github.event.ref == 'refs/heads/master') && secrets.DOCKERHUB_USERNAME != '' }}
# Only publish to Docker Hub if the dockerhub username is set, and either happens
#
# - we have a change in the development branch
# - we have a new tag
DOCKERHUB_PUBLISH: ${{ (github.event_name == 'push' && (github.event.ref == 'refs/heads/development' || startsWith(github.event.ref, 'refs/tags/')) || github.event_name == 'release') && secrets.DOCKERHUB_USERNAME != '' }}
# In case we run a pull request, the secrets are not available to us. Therefore check first
# and assign a 'dummy' dockerhub username
DOCKERHUB_USERNAME: ${{ ( secrets.DOCKERHUB_USERNAME != '' && secrets.DOCKERHUB_USERNAME ) || 'dummy' }}
DOCKERHUB_TAG_SUFFIX: ${{ ( github.event.ref == 'refs/heads/development' && format('{0}-{1}', matrix.platform, 'development') ) || ( github.event.ref == 'refs/heads/master' && matrix.platform ) || format('{0}-{1}', matrix.platform, 'dummy') }}
strategy:
matrix:
include:
Expand All @@ -46,11 +50,22 @@ jobs:
# Use the secrets directly and not the validated environment DOCKERHUB_USERNAME
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Determine dockerhub tag
id: dockerhub-tag
# Determine the dockerhub tag based on if our current working tree points to a tag or not
# the tags will either be `<tag>-<platform>` or `development-<platform>`
run: |
GIT_TAG=$(git tag -l --points-at $(git log -n 1 --format=%H))
if [ ! -z $GIT_TAG ]; then
echo "::set-output name=dockerhub-tag::$GIT_TAG-${{ matrix.platform }}"
else
echo "::set-output name=dockerhub-tag::development-${{ matrix.platform }}"
fi
- name: Build and push
uses: docker/build-push-action@v2
with:
context: ./
file: docker/build/${{ matrix.platform }}/Dockerfile
platforms: ${{ matrix.docker-platform }}
push: ${{ env.DOCKERHUB_PUBLISH == 'true' }}
tags: ${{ env.DOCKERHUB_USERNAME }}/opendatacam-darknet-base:${{ env.DOCKERHUB_TAG_SUFFIX }}
tags: ${{ env.DOCKERHUB_USERNAME }}/opendatacam-darknet-base:${{ steps.dockerhub-tag.outputs.dockerhub-tag }}

0 comments on commit b1fb0a3

Please sign in to comment.