From 26692e2c45d8f63cb852edf67cde85a691a15594 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Fri, 2 Aug 2024 23:11:14 +0300 Subject: [PATCH] Improve CI workflow --- .codebeatsettings | 11 --- .../{docker-push.yml => cd-release.yml} | 49 +++++++++--- .github/workflows/ci-pr.yml | 69 ++++++++++++++++ .github/workflows/ci-push.yml | 26 +++++++ .github/workflows/ci.yml | 78 +------------------ README.md | 11 ++- 6 files changed, 143 insertions(+), 101 deletions(-) delete mode 100644 .codebeatsettings rename .github/workflows/{docker-push.yml => cd-release.yml} (74%) create mode 100644 .github/workflows/ci-pr.yml create mode 100644 .github/workflows/ci-push.yml diff --git a/.codebeatsettings b/.codebeatsettings deleted file mode 100644 index e06ac69..0000000 --- a/.codebeatsettings +++ /dev/null @@ -1,11 +0,0 @@ -{ - "GOLANG": { - "ABC": [25, 50, 75, 100], - "CYCLO": [30, 50, 75, 100], - "TOO_MANY_IVARS": [12, 16, 20, 24], - "TOO_MANY_FUNCTIONS": [50, 70, 90, 120], - "LOC": [35, 50, 75, 100], - "TOTAL_COMPLEXITY": [100, 180, 280, 400], - "TOTAL_LOC": [500, 750, 1000, 2000] - } -} diff --git a/.github/workflows/docker-push.yml b/.github/workflows/cd-release.yml similarity index 74% rename from .github/workflows/docker-push.yml rename to .github/workflows/cd-release.yml index 739e087..fadcd8e 100644 --- a/.github/workflows/docker-push.yml +++ b/.github/workflows/cd-release.yml @@ -1,4 +1,4 @@ -name: "Docker Push" +name: "CD (Release)" on: release: @@ -19,15 +19,16 @@ permissions: env: IMAGE_NAME: ${{ github.repository }} + LATEST_IMAGE: ol8 jobs: - Docker: - name: Docker Build & Publish + BuildImage: + name: Image Build & Publish runs-on: ubuntu-latest strategy: matrix: - image: [ 'ol8', 'ol9' ] + image: [ 'ol8', 'ol9', 'ruby', 'ruby-jemalloc', 'jruby' ] steps: - name: Checkout @@ -48,9 +49,32 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Prepare metadata for build + - name: Checkout the latest tag + run: | + rev=$(git rev-list --tags --max-count=1) + tag=$(git describe --tags "$rev") + + if [[ -z "$tag" ]] ; then + echo "::error::Can't find the latest tag" + exit 1 + fi + + echo -e "\033[34mRev:\033[0m $rev" + echo -e "\033[34mTag:\033[0m $tag" + + git checkout "$tag" + + - name: Prepare metadata for the 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=".docker/${{matrix.image}}.docker" base_image=$(grep 'FROM ' $docker_file | grep -v 'builder' | sed 's#${REGISTRY}/##' | tail -1 | cut -f2 -d' ') @@ -59,14 +83,21 @@ jobs: exit 1 fi - dh_tags="${{env.IMAGE_NAME}}:${{matrix.image}}" - gh_tags="ghcr.io/${{env.IMAGE_NAME}}:${{matrix.image}}" + dh_tags="${{env.IMAGE_NAME}}:${{matrix.image}}-$version,${{env.IMAGE_NAME}}:${{matrix.image}}" + gh_tags="ghcr.io/${{env.IMAGE_NAME}}:${{matrix.image}}-$version,ghcr.io/${{env.IMAGE_NAME}}:${{matrix.image}}" + + if [[ -n "${{env.LATEST_IMAGE}}" && "${{env.LATEST_IMAGE}}" == "${{matrix.image}}" ]] ; then + dh_tags="$dh_tags,${{env.IMAGE_NAME}}:latest" + gh_tags="$gh_tags,ghcr.io/${{env.IMAGE_NAME}}:latest" + fi + echo "version=$version" >> $GITHUB_OUTPUT echo "dockerfile=$docker_file" >> $GITHUB_OUTPUT echo "baseimage=$base_image" >> $GITHUB_OUTPUT echo "dh_tags=$dh_tags" >> $GITHUB_OUTPUT echo "gh_tags=$gh_tags" >> $GITHUB_OUTPUT + echo -e "\033[34mVersion:\033[0m $version" echo -e "\033[34mDockerfile:\033[0m $docker_file" echo -e "\033[34mBase image:\033[0m $base_image" echo -e "\033[34mDH Tags:\033[0m $dh_tags" @@ -75,13 +106,13 @@ jobs: - name: Check if build/rebuild is required id: build_check run: | - if [[ "${{github.event_name}}" == "release" ]] ; then + if [[ "$GITHUB_EVENT_NAME" == "release" ]] ; then echo "build=true" >> $GITHUB_OUTPUT exit 0 fi if [[ "${{ github.event.inputs.force_rebuild }}" == "true" ]] ; then - echo "::warning::Rebuild ${{matrix.image}} (reason: forced rebuild)" + echo "::warning::Rebuild ${{matrix.version}} (reason: forced rebuild)" echo "build=true" >> $GITHUB_OUTPUT exit 0 fi diff --git a/.github/workflows/ci-pr.yml b/.github/workflows/ci-pr.yml new file mode 100644 index 0000000..a072791 --- /dev/null +++ b/.github/workflows/ci-pr.yml @@ -0,0 +1,69 @@ +name: CI (PR) + +on: + pull_request: + branches: [master] + workflow_dispatch: + inputs: + force_run: + description: 'Force workflow run' + required: true + type: choice + options: [yes, no] + +permissions: + actions: read + contents: read + statuses: write + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + CI: + uses: ./.github/workflows/ci.yml + secrets: inherit + + ImageBuild: + name: Container Image Build Check + runs-on: ubuntu-latest + + needs: CI + + env: + REGISTRY: ghcr.io + + strategy: + matrix: + image: [ 'ol8', 'ol9', 'ruby', 'ruby-jemalloc', 'jruby' ] + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Login to DockerHub + uses: docker/login-action@v3 + env: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + if: ${{ env.DOCKERHUB_USERNAME != '' }} + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build Docker image + run: | + docker build --build-arg REGISTRY=${REGISTRY} -f .docker/${{matrix.image}}.docker -t ${{matrix.image}} . + + - name: Show info about built Docker image + uses: essentialkaos/docker-info-action@v1 + with: + image: ${{matrix.image}} + show-labels: true diff --git a/.github/workflows/ci-push.yml b/.github/workflows/ci-push.yml new file mode 100644 index 0000000..04d2363 --- /dev/null +++ b/.github/workflows/ci-push.yml @@ -0,0 +1,26 @@ +name: CI (Push) + +on: + push: + branches: [master, develop] + workflow_dispatch: + inputs: + force_run: + description: 'Force workflow run' + required: true + type: choice + options: [yes, no] + +permissions: + actions: read + contents: read + statuses: write + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + CI: + uses: ./.github/workflows/ci.yml + secrets: inherit diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6571b0c..0af750d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,29 +1,13 @@ name: CI on: - push: - branches: [master, develop] - pull_request: - branches: [master] - schedule: - - cron: '0 19 */15 * *' - workflow_dispatch: - inputs: - force_run: - description: 'Force workflow run' - required: true - type: choice - options: [yes, no] + workflow_call: permissions: actions: read contents: read statuses: write -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - jobs: Go: name: Go @@ -45,7 +29,7 @@ jobs: - name: Download dependencies run: make deps - - name: Build binary + - name: Build binaries run: make all Perfecto: @@ -83,7 +67,7 @@ jobs: - name: Check dockerfiles with Hadolint uses: essentialkaos/hadolint-action@v1 with: - files: .docker/ol8.docker .docker/ol9.docker .docker/ruby.docker .docker/ruby-jemalloc.docker .docker/jruby.docker + files: .docker/*.docker Typos: name: Typos @@ -98,59 +82,3 @@ jobs: - name: Check spelling continue-on-error: true uses: crate-ci/typos@master - - DockerBuild: - name: Docker Build Check - runs-on: ubuntu-latest - - needs: [Hadolint] - - env: - REGISTRY: ghcr.io - - strategy: - matrix: - image: [ 'ol8', 'ol9' ] - - steps: - - name: Check event type - run: | - if [[ "${{github.event_name}}" != "pull_request" ]] ; then - echo "::notice::Event type is not 'pull_request', all job actions will be skipped" - fi - - # This step is a hack for needs+if issue with actions - # More info about issue: https://github.com/actions/runner/issues/491 - - - name: Checkout - uses: actions/checkout@v4 - if: ${{ github.event_name == 'pull_request' }} - - - name: Login to DockerHub - uses: docker/login-action@v3 - env: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - if: ${{ github.event_name == 'pull_request' && env.DOCKERHUB_USERNAME != '' }} - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - if: ${{ github.event_name == 'pull_request' }} - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build Docker image - if: ${{ github.event_name == 'pull_request' }} - run: | - docker build --build-arg REGISTRY=${REGISTRY} -f .docker/${{matrix.image}}.docker -t ${{matrix.image}} . - - - name: Show info about built Docker image - uses: essentialkaos/docker-info-action@v1 - if: ${{ github.event_name == 'pull_request' }} - with: - image: ${{matrix.image}} - show-labels: true diff --git a/README.md b/README.md index 26a308e..73ad133 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,7 @@

GoReportCard Code Climate Maintainability - codebeat badge - GitHub Actions CI Status + GitHub Actions CI Status GitHub Actions CodeQL Status

@@ -27,8 +26,8 @@ #### From [ESSENTIAL KAOS Public Repository](https://kaos.sh/kaos-repo) ```bash -sudo yum install -y https://pkgs.kaos.st/kaos-repo-latest.el$(grep 'CPE_NAME' /etc/os-release | tr -d '"' | cut -d':' -f5).noarch.rpm -sudo yum install rbinstall +sudo dnf install -y https://pkgs.kaos.st/kaos-repo-latest.el$(grep 'CPE_NAME' /etc/os-release | tr -d '"' | cut -d':' -f5).noarch.rpm +sudo dnf install rbinstall ``` ### Usage @@ -49,8 +48,8 @@ sudo yum install rbinstall | Branch | Status | |--------|--------| -| `master` | [![CI](https://kaos.sh/w/rbinstall/ci.svg?branch=master)](https://kaos.sh/w/rbinstall/ci?query=branch:master) | -| `develop` | [![CI](https://kaos.sh/w/rbinstall/ci.svg?branch=develop)](https://kaos.sh/w/rbinstall/ci?query=branch:develop) | +| `master` | [![CI](https://kaos.sh/w/rbinstall/ci-push.svg?branch=master)](https://kaos.sh/w/rbinstall/ci-push?query=branch:master) | +| `develop` | [![CI](https://kaos.sh/w/rbinstall/ci-push.svg?branch=develop)](https://kaos.sh/w/rbinstall/ci-push?query=branch:develop) | ### Contributing