Skip to content

Commit

Permalink
chore: refactor CI into a single workflow and automated builds
Browse files Browse the repository at this point in the history
  • Loading branch information
meysam81 committed Jun 11, 2024
1 parent d2e5f15 commit c0db134
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 75 deletions.
182 changes: 182 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
name: ci

on:
pull_request:
branches:
- main
push:
branches:
- main
tags:
- "*"

env:
IMAGE_REPOSITORY: ${{ github.repository }}
IMAGE_REGISTRY: ghcr.io
PYTHON_VERSION: "3.11"

jobs:
publish-pypi:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Prepare
run: pip install wheel && python setup.py sdist bdist_wheel
- name: Publish PyPi
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}

build-docker-pr:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
username: ${{ github.actor }}
- id: meta
name: Docker metadata
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_REPOSITORY }}
- name: Build and push
uses: docker/build-push-action@v5
with:
cache-from: type=gha
cache-to: type=gha,mode=max
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ steps.meta.outputs.tags }}
${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:${{ github.run_id }}
- if: contains(github.event.pull_request.labels.*.name, 'check-cves')
name: Docker Scout - cves
uses: docker/scout-action@v1
with:
command: cves
ignore-unchanged: true
image: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:${{ github.run_id }}
only-fixed: true
only-severities: medium,high,critical
sarif-file: sarif.output.json
summary: true
- if: contains(github.event.pull_request.labels.*.name, 'check-cves')
name: Upload artifact
uses: actions/upload-artifact@v4
with:
if-no-files-found: warn
name: scout-results
path: sarif.output.json


build-docker-edge:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
username: ${{ github.actor }}
- id: meta
name: Docker metadata
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_REPOSITORY }}
- name: Build and push
uses: docker/build-push-action@v5
with:
cache-from: type=gha
cache-to: type=gha,mode=max
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ steps.meta.outputs.tags }}
${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:${{ github.run_id }}
${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:latest
- name: Docker Scout - cves
uses: docker/scout-action@v1
with:
command: cves
ignore-unchanged: true
image: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:${{ github.run_id }}
only-fixed: true
only-severities: medium,high,critical
sarif-file: sarif.output.json
summary: true
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
if-no-files-found: warn
name: scout-results
path: sarif.output.json

build-docker-stable:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
username: ${{ github.actor }}
- id: meta
name: Docker metadata
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_REPOSITORY }}
- name: Build and push
uses: docker/build-push-action@v5
with:
cache-from: type=gha
cache-to: type=gha,mode=max
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
- name: Docker Scout - cves
uses: docker/scout-action@v1
with:
command: cves
ignore-unchanged: true
image: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:${{ github.run_id }}
only-fixed: true
only-severities: medium,high,critical
sarif-file: sarif.output.json
summary: true
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
if-no-files-found: warn
name: scout-results
path: sarif.output.json
42 changes: 0 additions & 42 deletions .github/workflows/log-forwarder-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,4 @@ on:
description: 'Target Docker image tag'
required: true

env:
IMAGE_REPOSITORY: licenseware/logblocks
GITHUB_REGISTRY: ghcr.io

jobs:
build-docker-image:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Set up QEMU needed for Docker
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
logout: false
password: ${{ secrets.GITHUB_TOKEN }}
registry: ${{ env.GITHUB_REGISTRY }}
username: ${{ github.actor }}
- name: Login to Docker hub
uses: docker/login-action@v2
with:
logout: false
password: ${{ secrets.DOCKERHUB_PASSWORD }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
- id: meta
name: Docker metadata
uses: docker/metadata-action@v4
with:
images: |
${{ env.GITHUB_REGISTRY }}/${{ env.IMAGE_REPOSITORY }}
${{ env.IMAGE_REPOSITORY }}
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
labels: ${{ steps.meta.outputs.labels }}
push: true
tags: |
${{ env.GITHUB_REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:${{ inputs.docker-image-tag }}
${{ env.IMAGE_REPOSITORY }}:${{ inputs.docker-image-tag }}
29 changes: 0 additions & 29 deletions .github/workflows/publish-pypi.yml

This file was deleted.

6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repos:
stages:
- commit
repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 5.13.2
- hooks:
- args:
- "-ri"
Expand All @@ -19,10 +19,10 @@ repos:
stages:
- commit
repo: https://github.com/PyCQA/autoflake
rev: v2.0.1
rev: v2.3.1
- hooks:
- id: black
stages:
- commit
repo: https://github.com/psf/black
rev: 23.1.0
rev: 24.4.2
1 change: 0 additions & 1 deletion tests/test_post_slack_message.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os


from logblocks.logblocks import get_slack_message, post_message


Expand Down

0 comments on commit c0db134

Please sign in to comment.