diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f0abe83..e60347a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,14 +8,14 @@ on: schedule: - cron: '0 12 */15 * *' +env: + SRC_DIR: src/github.com/${{ github.repository }} + jobs: Go: name: Go runs-on: ubuntu-latest - env: - SRC_DIR: src/github.com/${{ github.repository }} - strategy: matrix: go: [ '1.17.x', '1.18.x' ] @@ -25,7 +25,6 @@ jobs: uses: actions/setup-go@v3 with: go-version: ${{ matrix.go }} - id: go - name: Checkout uses: actions/checkout@v3 @@ -50,16 +49,11 @@ jobs: needs: Go - env: - SRC_DIR: src/github.com/${{ github.repository }} - GO111MODULE: auto - steps: - name: Set up Go uses: actions/setup-go@v3 with: go-version: '1.17.x' - id: go - name: Checkout uses: actions/checkout@v3 @@ -86,17 +80,15 @@ jobs: - name: Code checkout uses: actions/checkout@v3 - - name: Login to DockerHub + - name: Login to GitHub Container Registry uses: docker/login-action@v2 - env: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - if: ${{ env.DOCKERHUB_USERNAME != '' }} with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Check specs with Perfecto - uses: essentialkaos/perfecto-action@v1 + uses: essentialkaos/perfecto-action@v2 with: files: common/yo.spec diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml new file mode 100644 index 0000000..27cb7cc --- /dev/null +++ b/.github/workflows/docker-push.yml @@ -0,0 +1,122 @@ +name: "Docker Push" + +on: + release: + types: [published] + schedule: + - cron: '30 12 * * *' + +permissions: + packages: write + contents: read + +env: + IMAGE_NAME: ${{ github.repository }} + +jobs: + Docker: + name: Docker Build & Publish + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Prepare metadata for build + id: metadata + run: | + rev=$(git rev-list --tags --max-count=1) + version=$(git describe --tags "$rev" | tr -d 'v') + + if [[ -z "$version" ]] ; then + echo "::error::Can't find version info" + exit 1 + fi + + docker_file="Dockerfile" + base_image=$(grep 'FROM ' $docker_file | tail -1 | cut -f2 -d' ') + + if [[ -z "$base_image" ]] ; then + echo "::error::Can't extract base image info" + exit 1 + fi + + echo "::set-output name=version::$version" + echo "::set-output name=dockerfile::$docker_file" + echo "::set-output name=baseimage::$base_image" + + echo -e "\033[34mVersion:\033[0m $version" + echo -e "\033[34mDockerfile:\033[0m $docker_file" + echo -e "\033[34mBase image:\033[0m $base_image" + + - name: Check if build/rebuild is required + id: build_check + run: | + if [[ "${{github.event_name}}" == "release" ]] ; then + echo "::set-output name=build::true" + exit 0 + fi + + echo -e "::group::\033[34mDownloading built image…\033[0m" + + if ! docker pull ghcr.io/${{env.IMAGE_NAME}}:latest ; then + echo "::error::Can't download image ghcr.io/${{env.IMAGE_NAME}}:latest" + exit 1 + fi + + echo "::endgroup::" + echo -e "::group::\033[34mDownloading base image…\033[0m" + + if ! docker pull ${{steps.metadata.outputs.baseimage}} ; then + echo "::error::Can't download image ${{steps.metadata.outputs.baseimage}}" + exit 1 + fi + + echo "::endgroup::" + + base_layer=$(docker inspect "${{steps.metadata.outputs.baseimage}}" | jq -r '.[0].RootFS.Layers[-1]') + + if [[ -z "$base_layer" ]] ; then + echo "::error::Can't extract layers info from base image" + exit 1 + fi + + if ! docker inspect "ghcr.io/${{env.IMAGE_NAME}}:latest" | jq -r '.[0].RootFS.Layers' | grep -q "$base_layer" ; then + echo "::warning::Rebuild image (reason: base image rebuilt)" + echo "::set-output name=build::true" + exit 0 + fi + + - name: Build and push Docker image + if: ${{ steps.build_check.outputs.build == 'true' }} + uses: docker/build-push-action@v3 + with: + push: true + context: . + file: ${{steps.metadata.outputs.dockerfile}} + tags: | + ghcr.io/${{env.IMAGE_NAME}}:latest + ghcr.io/${{env.IMAGE_NAME}}:${{steps.metadata.outputs.version}} + ${{env.IMAGE_NAME}}:latest + ${{env.IMAGE_NAME}}:${{steps.metadata.outputs.version}} + + - name: Show info about built Docker image + uses: essentialkaos/docker-info-action@v1 + with: + image: ${{env.IMAGE_NAME}}:latest + show-labels: true diff --git a/.github/workflows/ghcr.yml b/.github/workflows/ghcr.yml deleted file mode 100644 index dd4ae8e..0000000 --- a/.github/workflows/ghcr.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: "GHCR Publish" - -on: - release: - types: [published] - workflow_dispatch: - -permissions: - packages: write - contents: read - -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} - -jobs: - Publish: - name: Build and push image - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Login to GitHub Container Registry - uses: docker/login-action@v2 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v4 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - flavor: latest=true - - - name: Build and push Docker image - uses: docker/build-push-action@v3 - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} diff --git a/Makefile b/Makefile index cc79908..19b420a 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ ################################################################################ -# This Makefile generated by GoMakeGen 2.0.0 using next command: +# This Makefile generated by GoMakeGen 2.1.0 using next command: # gomakegen --mod . # # More info: https://kaos.sh/gomakegen @@ -13,6 +13,9 @@ ifdef VERBOSE ## Print verbose information (Flag) VERBOSE_FLAG = -v endif +MAKEDIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) +GITREV ?= $(shell test -s $(MAKEDIR)/.git && git rev-parse --short HEAD) + ################################################################################ .DEFAULT_GOAL := help @@ -23,7 +26,7 @@ endif all: yo ## Build all binaries yo: - go build $(VERBOSE_FLAG) yo.go + go build $(VERBOSE_FLAG) -ldflags="-X main.gitrev=$(GITREV)" yo.go install: ## Install all binaries cp yo /usr/bin/yo @@ -91,6 +94,6 @@ help: ## Show this info | sed 's/ifdef //' \ | awk 'BEGIN {FS = " .*?## "}; {printf " \033[32m%-14s\033[0m %s\n", $$1, $$2}' @echo -e '' - @echo -e '\033[90mGenerated by GoMakeGen 2.0.0\033[0m\n' + @echo -e '\033[90mGenerated by GoMakeGen 2.1.0\033[0m\n' ################################################################################ diff --git a/common/yo.spec b/common/yo.spec index 70c0833..76b8a77 100644 --- a/common/yo.spec +++ b/common/yo.spec @@ -44,7 +44,7 @@ Summary: Command-line YAML processor Name: yo -Version: 0.5.3 +Version: 0.5.4 Release: 0%{?dist} Group: Applications/System License: Apache License, Version 2.0 @@ -71,7 +71,7 @@ Command-line YAML processor. %build export GOPATH=$(pwd) pushd src/github.com/essentialkaos/%{name} - go build -mod vendor -o $GOPATH/%{name} %{name}.go + go build -o $GOPATH/%{name} %{name}.go popd %install @@ -126,6 +126,9 @@ fi ################################################################################ %changelog +* Fri May 27 2022 Anton Novojilov - 0.5.4-0 +- Updated for compatibility with the latest version of ek package + * Mon May 09 2022 Anton Novojilov - 0.5.3-0 - Updated for compatibility with the latest version of ek package diff --git a/go.mod b/go.mod index 18b6235..44c572b 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/essentialkaos/yo go 1.17 require ( - github.com/essentialkaos/ek/v12 v12.45.0 + github.com/essentialkaos/ek/v12 v12.46.0 github.com/essentialkaos/go-simpleyaml/v2 v2.1.3 ) diff --git a/go.sum b/go.sum index f8091f4..e6ef62c 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/essentialkaos/check v1.2.1/go.mod h1:PhxzfJWlf5L/skuyhzBLIvjMB5Xu9TIyDIsqpY5MvB8= github.com/essentialkaos/check v1.3.0 h1:ria+8o22RCLdt2D/1SHQsEH5Mmy5S+iWHaGHrrbPUc0= github.com/essentialkaos/check v1.3.0/go.mod h1:PhxzfJWlf5L/skuyhzBLIvjMB5Xu9TIyDIsqpY5MvB8= -github.com/essentialkaos/ek/v12 v12.45.0 h1:5KVZl5MAsPwxfjda+wb+cCxneQ747lU9zA5mjCA5Fyg= -github.com/essentialkaos/ek/v12 v12.45.0/go.mod h1:uQUkpvaZHWR9aI8GfknZqOG5FC+G2PYJLFyMw9fdjbo= +github.com/essentialkaos/ek/v12 v12.46.0 h1:TNw9YmKPf67E9L886EzhH9xUO49bROqvqHR4bzOqf/E= +github.com/essentialkaos/ek/v12 v12.46.0/go.mod h1:uQUkpvaZHWR9aI8GfknZqOG5FC+G2PYJLFyMw9fdjbo= github.com/essentialkaos/go-linenoise/v3 v3.3.5/go.mod h1:g4X3LhT83XT4h7xwrCLclAdMkJvS9qWBQTGNdS6y4vo= github.com/essentialkaos/go-simpleyaml/v2 v2.1.3 h1:DAFvXut4ZtkuiTKWqSux3W0myuv3TOAwiD6w5MKWxsM= github.com/essentialkaos/go-simpleyaml/v2 v2.1.3/go.mod h1:LAUFukPmTZ4fmHa1K3LsH8MO257r/CL/BqlaP/2Vgcs= diff --git a/yo.go b/yo.go index 638c969..8aad060 100644 --- a/yo.go +++ b/yo.go @@ -33,7 +33,7 @@ import ( const ( APP = "Yo" - VER = "0.5.3" + VER = "0.5.4" DESC = "Command-line YAML processor" )