From 99919d045985a03bc8aece2c38db59773c47f3af Mon Sep 17 00:00:00 2001 From: Martin Buchleitner Date: Wed, 20 Jul 2022 12:17:22 +0200 Subject: [PATCH] use semantic release workflow --- .github/workflows/docker.yml | 54 ++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 1d5d1fb..389e9e8 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,8 +1,11 @@ -name: docker +name: ci on: push: - branches: [ main ] + branches: [ 'main' ] + pull_request: + branches: + - main jobs: build: @@ -10,20 +13,35 @@ jobs: 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} @@ -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 @@ -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