@@ -3,11 +3,11 @@ name: Build
33on :
44 pull_request :
55 branches :
6- - development
6+ - main
77 push :
8- branches : [ development, staging ]
8+ branches : [main ]
99 release :
10- types : [ " published" ]
10+ types : [' published' ]
1111 workflow_dispatch :
1212 inputs :
1313 tagName :
@@ -18,56 +18,55 @@ jobs:
1818 build :
1919 runs-on : ubuntu-latest
2020 steps :
21+ - name : Checkout
22+ uses : actions/checkout@v2
2123
22- - name : Checkout
23- uses : actions/checkout@v2
24+ - name : Prepare
25+ id : prep
26+ run : |
27+ DOCKER_IMAGE=cmusei/player-ui
28+ VERSION=development
29+ if [[ ! -z "${{ github.event.inputs.tagName }}" ]]; then
30+ VERSION=${{ github.event.inputs.tagName }}
31+ TAGS="${DOCKER_IMAGE}:${VERSION}"
32+ elif [[ $GITHUB_REF == refs/tags/* ]]; then
33+ VERSION=${GITHUB_REF#refs/tags/}
34+ MAJORMINORVERSION=$(echo $VERSION | grep -oP '(\d+)\.(\d+)')
35+ TAGS="${DOCKER_IMAGE}:${VERSION},${DOCKER_IMAGE}:${MAJORMINORVERSION}"
36+ elif [[ $GITHUB_REF == refs/heads/* ]]; then
37+ VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
38+ TAGS="${DOCKER_IMAGE}:${VERSION}"
39+ fi
40+ if [[ "${{ github.event_name }}" == "pull_request" ]]; then
41+ echo ::set-output name=push::false
42+ echo "event is pull_request, not pushing image"
43+ else
44+ echo ::set-output name=push::true
45+ echo "event is not pull_request, pushing image"
46+ fi
47+ echo ::set-output name=version::${VERSION}
48+ echo ::set-output name=tags::${TAGS}
49+ echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
2450
25- - name : Prepare
26- id : prep
27- run : |
28- DOCKER_IMAGE=cmusei/player-ui
29- VERSION=development
30- if [[ ! -z "${{ github.event.inputs.tagName }}" ]]; then
31- VERSION=${{ github.event.inputs.tagName }}
32- TAGS="${DOCKER_IMAGE}:${VERSION}"
33- elif [[ $GITHUB_REF == refs/tags/* ]]; then
34- VERSION=${GITHUB_REF#refs/tags/}
35- MAJORMINORVERSION=$(echo $VERSION | grep -oP '(\d+)\.(\d+)')
36- TAGS="${DOCKER_IMAGE}:${VERSION},${DOCKER_IMAGE}:${MAJORMINORVERSION}"
37- elif [[ $GITHUB_REF == refs/heads/* ]]; then
38- VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
39- TAGS="${DOCKER_IMAGE}:${VERSION}"
40- fi
41- if [[ "${{ github.event_name }}" == "pull_request" ]]; then
42- echo ::set-output name=push::false
43- echo "event is pull_request, not pushing image"
44- else
45- echo ::set-output name=push::true
46- echo "event is not pull_request, pushing image"
47- fi
48- echo ::set-output name=version::${VERSION}
49- echo ::set-output name=tags::${TAGS}
50- echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
51+ - name : Set up Docker Buildx
52+ uses : docker/setup-buildx-action@v1
5153
52- - name : Set up Docker Buildx
53- uses : docker/setup-buildx-action@v1
54+ - name : Login to DockerHub
55+ if : github.event_name != 'pull_request'
56+ uses : docker/login-action@v1
57+ with :
58+ username : ${{ secrets.DOCKERHUB_USERNAME }}
59+ password : ${{ secrets.DOCKERHUB_PASSWORD }}
5460
55- - name : Login to DockerHub
56- if : github.event_name != 'pull_request'
57- uses : docker/login-action@v1
58- with :
59- username : ${{ secrets.DOCKERHUB_USERNAME }}
60- password : ${{ secrets.DOCKERHUB_PASSWORD }}
61-
62- - name : Build and push
63- uses : docker/build-push-action@v2
64- with :
65- context : .
66- file : ./Dockerfile
67- push : ${{ steps.prep.outputs.push }}
68- pull : true
69- tags : ${{ steps.prep.outputs.tags }}
70- labels : |
71- org.opencontainers.image.source=${{ github.event.repository.clone_url }}
72- org.opencontainers.image.created=${{ steps.prep.outputs.created }}
73- org.opencontainers.image.revision=${{ github.sha }}
61+ - name : Build and push
62+ uses : docker/build-push-action@v2
63+ with :
64+ context : .
65+ file : ./Dockerfile
66+ push : ${{ steps.prep.outputs.push }}
67+ pull : true
68+ tags : ${{ steps.prep.outputs.tags }}
69+ labels : |
70+ org.opencontainers.image.source=${{ github.event.repository.clone_url }}
71+ org.opencontainers.image.created=${{ steps.prep.outputs.created }}
72+ org.opencontainers.image.revision=${{ github.sha }}
0 commit comments