Skip to content

Commit

Permalink
Improve CI workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Aug 2, 2024
1 parent f86e2da commit 26692e2
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 101 deletions.
11 changes: 0 additions & 11 deletions .codebeatsettings

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Docker Push"
name: "CD (Release)"

on:
release:
Expand All @@ -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
Expand All @@ -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' ')
Expand All @@ -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"
Expand All @@ -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
Expand Down
69 changes: 69 additions & 0 deletions .github/workflows/ci-pr.yml
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions .github/workflows/ci-push.yml
Original file line number Diff line number Diff line change
@@ -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
78 changes: 3 additions & 75 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -45,7 +29,7 @@ jobs:
- name: Download dependencies
run: make deps

- name: Build binary
- name: Build binaries
run: make all

Perfecto:
Expand Down Expand Up @@ -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
Expand All @@ -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
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
<p align="center">
<a href="https://kaos.sh/r/rbinstall"><img src="https://kaos.sh/r/rbinstall.svg" alt="GoReportCard" /></a>
<a href="https://kaos.sh/l/rbinstall"><img src="https://kaos.sh/l/5680ef76d53ea9526739.svg" alt="Code Climate Maintainability" /></a>
<a href="https://kaos.sh/b/rbinstall"><img src="https://kaos.sh/b/b78de32a-6867-4bd3-9135-8244d4813531.svg" alt="codebeat badge" /></a>
<a href="https://kaos.sh/w/rbinstall/ci"><img src="https://kaos.sh/w/rbinstall/ci.svg" alt="GitHub Actions CI Status" /></a>
<a href="https://kaos.sh/w/rbinstall/ci"><img src="https://kaos.sh/w/rbinstall/ci-push.svg" alt="GitHub Actions CI Status" /></a>
<a href="https://kaos.sh/w/rbinstall/codeql"><img src="https://kaos.sh/w/rbinstall/codeql.svg" alt="GitHub Actions CodeQL Status" /></a>
<a href="#license"><img src=".github/images/license.svg"/></a>
</p>
Expand All @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 26692e2

Please sign in to comment.