Skip to content

Commit

Permalink
Merge pull request #1 from infralovers/update-gh-workflow
Browse files Browse the repository at this point in the history
BREAKING CHANGE: use semantic release workflow
  • Loading branch information
mabunixda authored Jul 20, 2022
2 parents 2cd2fa5 + 99919d0 commit c809a36
Showing 1 changed file with 43 additions and 11 deletions.
54 changes: 43 additions & 11 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,47 @@
name: docker
name: ci

on:
push:
branches: [ main ]
branches: [ 'main' ]
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Prepare
- uses: go-semantic-release/action@v1
id: semrel
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
changelog-file: CHANGELOG.md

- name: Prepare tagging
id: prep
run: |
DOCKER_IMAGE=infralovers/colors
VERSION=latest
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
IMAGE_NAME=$(basename ${{ github.repository }})
IMAGE_REPO=${{ github.repository_owner }}
if [[ -n "${{ secrets.IMAGE_NAME }}" ]]; then
IMAGE_NAME="${{ secrets.IMAGE_NAME }}"
fi
if [[ -n "${{ secrets.IMAGE_REPO }}" ]]; then
IMAGE_REPO="${{ secrets.IMAGE_REPO }}"
fi
HUB_IMAGE="$IMAGE_REPO/$IMAGE_NAME"
QUAY_IMAGE="quay.io/$IMAGE_REPO/$IMAGE_NAME"
VERSION=dev
if [[ '${{ steps.semrel.outputs.version }}' != '' ]]; then
VERSION=${{ steps.semrel.outputs.version }}
fi
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=nightly
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
TAGS="${QUAY_IMAGE}:${VERSION},${HUB_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:latest"
TAGS="$TAGS,${QUAY_IMAGE}:latest,${HUB_IMAGE}:latest"
fi
echo ::set-output name=tags::${TAGS}
Expand All @@ -40,12 +58,19 @@ jobs:
${{ runner.os }}-buildx-
- name: Login to DockerHub
if: github.event_name != 'pull_request'
if: github.event_name != 'pull_request' && steps.semrel.outputs.version != ''
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to Quay
if: github.event_name != 'pull_request' && steps.semrel.outputs.version != ''
uses: docker/login-action@v1
with:
registry: quay.io
username: ${{ secrets.QUAY_USER }}
password: ${{ secrets.QUAY_TOKEN }}

- name: Build and push
id: docker_build
Expand All @@ -54,5 +79,12 @@ jobs:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' }}
push: ${{ github.event_name != 'pull_request' && steps.semrel.outputs.version != '' }}
tags: ${{ steps.prep.outputs.tags }}

- name: Update changelog
uses: stefanzweifel/git-auto-commit-action@v4
if: github.event_name != 'pull_request' && steps.semrel.outputs.version != ''
with:
commit_message: 'chore(ci): commit changes from go-semantic-release'
file_pattern: CHANGELOG.md

0 comments on commit c809a36

Please sign in to comment.