Skip to content

2024-06-19 20:38 - updates ci:test #252

2024-06-19 20:38 - updates ci:test

2024-06-19 20:38 - updates ci:test #252

Workflow file for this run

name: Test
on:
push:
branches:
- develop
- master
- staging
- release/*
- feature/*
- bugfix/*
- hotfix/*
pull_request:
branches: [develop, master]
types: [synchronize, opened, reopened, ready_for_review]
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true
defaults:
run:
shell: bash
jobs:
changes:
runs-on: ubuntu-latest
timeout-minutes: 1
defaults:
run:
shell: bash
outputs:
run_tests: ${{ steps.changes.outputs.run_tests }}
steps:
- name: Checkout code
uses: actions/[email protected]
- id: changes
name: Check for file changes
uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd # v3.0.0
with:
base: ${{ github.ref }}
token: ${{ github.token }}
filters: .github/file-filters.yml
build:
needs: [changes]
runs-on: ubuntu-latest
timeout-minutes: 10
defaults:
run:
shell: bash
outputs:
image: ${{ steps.build.outputs.image }}
version: ${{ steps.build.outputs.version }}
steps:
- name: Checkout code
uses: actions/[email protected]
- id: checksum
uses: ./.github/actions/checksum
- name: Build and Test
id: build
uses: ./.github/actions/docker_build
with:
target: 'python_dev_deps'
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
code_checksum: ${{ steps.checksum.outputs.checksum }}
test:
name: Run Test Suite
needs: [changes,build]
if: needs.changes.outputs.run_tests == 'true' || contains(github.event.head_commit.message, 'ci:test')
runs-on: ubuntu-latest
services:
redis:
image: redis
db:
image: postgres:14
env:
POSTGRES_DATABASE: dedupe
POSTGRES_PASSWORD: postgres
POSTGRES_USERNAME: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
DOCKER_DEFAULT_PLATFORM: linux/amd64
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run tests
run: |
docker run --rm \
-e DATABASE_URL=postgres://postgres:postgres@localhost:5432/dedupe \
-e SECRET_KEY=secret_key \
-e CACHE_URL=redis://redis:6379/0 \
-e CELERY_BROKER_URL=redis://redis:6379/0 \
--network host \
-v $PWD:/code/app \
-w /code/app \
-t ${{needs.build.outputs.image}} \
pytest tests -v --create-db -v --maxfail=10
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
env_vars: OS,PYTHON
fail_ci_if_error: true
files: coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
verbose: false
name: codecov-${{env.GITHUB_REF_NAME}}
#
#
trivy:
name: Check Image with Trivy
runs-on: ubuntu-latest
needs: [build]
if: needs.setup.outputs.updated != 'true' || contains(github.event.head_commit.message, 'ci:build')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: DockerHub login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{needs.build.outputs.image}}
format: 'sarif'
output: 'trivy-results.sarif'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: 'trivy-results.sarif'
release:
needs: [test]
runs-on: ubuntu-latest
timeout-minutes: 10
defaults:
run:
shell: bash
steps:
- name: Checkout code
uses: actions/[email protected]
- id: checksum
uses: ./.github/actions/checksum
- name: Build
uses: ./.github/actions/docker_build
with:
target: 'dist'
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
checksum: ${{ steps.checksum.outputs.checksum }}
#
# setup:
# needs: [changes]
# if: needs.changes.outputs.run_tests == 'true' || contains(github.event.head_commit.message, 'ci:')
# runs-on: ubuntu-latest
# timeout-minutes: 10
# defaults:
# run:
# shell: bash
# outputs:
# image_name: ${{steps.image_name.outputs.name}}
# updated: ${{steps.image_status.outputs.updated}}
#
# version: ${{ steps.meta.outputs.version }}
# tags: ${{steps.meta.outputs.tags}}
# labels: ${{steps.meta.outputs.labels}}
# annotations: ${{steps.meta.outputs.annotations}}
#
# source_commit: ${{steps.meta.build_args.SOURCE_COMMIT}}
# checksum: ${{ steps.build_args.outputs.checksum }}
# build_date: ${{ steps.build_args.outputs.build_date }}
#
# steps:
# - name: Checkout code
# uses: actions/[email protected]
# - name: Cache regclient
# id: cache-regclient
# uses: actions/cache@v4
# with:
# path: $HOME/.regctl
# key: ${{ runner.os }}-regclient
# - name: Install regctl
# if: steps.cache-regclient.outputs.cache-hit != 'true'
# uses: regclient/actions/regctl-installer@main
# - name: Prepare Build Args
# id: build_args
# uses: ./.github/actions/build_args
# with:
# debug: true
# - name: Docker meta
# id: meta
# uses: docker/[email protected]
# with:
# images: ${{ vars.DOCKER_IMAGE }}
# flavor: |
# prefix=test-
# env:
# DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
# - name: "Image Name"
# id: image_name
# run: echo "name=${{ vars.DOCKER_IMAGE }}:${{ steps.meta.outputs.version }}" >> $GITHUB_OUTPUT
# - name: "Check Image"
# id: image_status
# shell: bash
# run: |
# echo "::notice::ℹ Checking checksum for ${{ steps.image_name.outputs.name }}"
# image_checksum=$(regctl image inspect -p linux/amd64 \
# --format '{{index .Config.Labels "checksum"}}' \
# ${{ steps.image_name.outputs.name }} )
# code_checksum="${{ steps.build_args.outputs.CHECKSUM }}"
#
# if [[ -z "$image_checksum" ]]; then
# echo "::warning::🤔 No image checksum found"
# echo "updated=false" >> $GITHUB_OUTPUT
# elif [[ $image_checksum == $code_checksum ]]; then
# echo "::notice::😀 Image is updated"
# echo "updated=true" >> $GITHUB_OUTPUT
# else
# echo "::warning::🤬 Checksum: found '${image_checksum}' expected '${code_checksum}'"
# echo "updated=false" >> $GITHUB_OUTPUT
# fi
#
#
# build:
# name: Build Test Image
# needs: [setup]
# runs-on: ubuntu-latest
# outputs:
# image_name: ${{ needs.setup.outputs.image_name }}
# steps:
# - name: Info
# run: |
# if [[ "${{needs.setup.outputs.updated}}" != "true" ]]; then
# echo "::notice:: Rebuild due to image outdated"
# else
# echo "::notice:: Forced rebuild due to commit message ${{github.event.head_commit.message}}"
# fi
# - name: Checkout code
# if: needs.setup.outputs.updated != 'true' || contains(github.event.head_commit.message, 'ci:build')
# uses: actions/[email protected]
# - name: DockerHub login
# if: needs.setup.outputs.updated != 'true' || contains(github.event.head_commit.message, 'ci:build')
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}
# - name: Set up Docker Buildx
# if: needs.setup.outputs.updated != 'true' || contains(github.event.head_commit.message, 'ci:build')
# uses: docker/[email protected]
# with:
# platforms: linux/amd64
# driver: docker-container
# driver-opts: |
# image=moby/buildkit:v0.13.2
# network=host
# - name: Build and push
# if: needs.setup.outputs.updated != 'true' || contains(github.event.head_commit.message, 'ci:build')
# id: build_push
# uses: docker/build-push-action@v6
# with:
# context: .
# tags: ${{ needs.setup.outputs.image_name }}
# labels: "${{ needs.setup.outputs.labels }}\na=1\nb=2"
# annotations: "${{ needs.setup.outputs.annotations }}\nchecksum=${{ needs.setup.outputs.checksum }}\ncommit=${{ needs.setup.outputs.source_commit }}"
# target: 'python_dev_deps'
# file: ./docker/Dockerfile
# platforms: linux/amd64
# push: true
# sbom: true
# provenance: true
# cache-from: type=registry,ref=${{ needs.setup.outputs.image_name }}-cache
# cache-to: type=registry,ref=${{ needs.setup.outputs.image_name }}-cache,mode=max,image-manifest=true
# build-args: |
# BUILD_DATE=${{ needs.setup.outputs.build_date }}
# CHECKSUM=${{ needs.setup.outputs.checksum }}
# VERSION=${{ needs.setup.outputs.version }}
# SOURCE_COMMIT=${{ needs.setup.outputs.source_commit }}
# GITHUB_SERVER_URL=${{ github.server_url }}
# GITHUB_REPOSITORY=${{ github.repository }}
#
#
# trivy:
# name: Check Image with Trivy
# runs-on: ubuntu-latest
# needs: [build]
# if: needs.setup.outputs.updated != 'true' || contains(github.event.head_commit.message, 'ci:build')
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: DockerHub login
# uses: docker/login-action@v1
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}
# - name: Run Trivy vulnerability scanner
# uses: aquasecurity/trivy-action@master
# with:
# image-ref: ${{needs.build.outputs.image}}
# format: 'sarif'
# output: 'trivy-results.sarif'
# - name: Upload Trivy scan results to GitHub Security tab
# uses: github/codeql-action/upload-sarif@v2
# with:
# sarif_file: 'trivy-results.sarif'
#
# test:
# name: Run Test Suite
# needs: [changes,setup,build]
# if: needs.changes.outputs.run_tests == 'true' || contains(github.event.head_commit.message, 'ci:test')
# runs-on: ubuntu-latest
# services:
# redis:
# image: redis
# db:
# image: postgres:14
# env:
# POSTGRES_DATABASE: dedupe
# POSTGRES_PASSWORD: postgres
# POSTGRES_USERNAME: postgres
# ports:
# - 5432:5432
# options: >-
# --health-cmd pg_isready
# --health-interval 10s
# --health-timeout 5s
# --health-retries 5
# env:
# DOCKER_DEFAULT_PLATFORM: linux/amd64
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Dump 'Build' outputs
# run: echo "${{ toJSON(needs.build.outputs) }}"
# - name: Dump 'Setup' outputs
# run: echo "${{ toJSON(needs.setup.outputs) }}"
# - name: Run tests
# run: |
# docker run --rm \
# -e DATABASE_URL=postgres://postgres:postgres@localhost:5432/dedupe \
# -e SECRET_KEY=secret_key \
# -e CACHE_URL=redis://redis:6379/0 \
# -e CELERY_BROKER_URL=redis://redis:6379/0 \
# --network host \
# -v $PWD:/code/app \
# -w /code/app \
# -t ${{needs.build.outputs.image_name}} \
# pytest tests -v --create-db -v --maxfail=10
# - name: Upload coverage to Codecov
# uses: codecov/codecov-action@v4
# with:
# env_vars: OS,PYTHON
# fail_ci_if_error: true
# files: coverage.xml
# token: ${{ secrets.CODECOV_TOKEN }}
# verbose: false
# name: codecov-${{env.GITHUB_REF_NAME}}
##
##
#
## release:
### if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
## name: Build and Push Distribution
## needs: [setup, test]
## runs-on: ubuntu-latest
## defaults:
## run:
## shell: bash
## outputs:
## image: ${{steps.image_name.outputs.name}}
## steps:
## - name: Checkout code
## uses: actions/checkout@v4
## - name: Define target image name
## id: image_name
## run: |
## branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
## ver="${branch/\//-}"
## echo "name=${{vars.DOCKER_IMAGE}}:$ver" >> $GITHUB_OUTPUT
## - id: doit
## uses: ./.github/actions/docker_build
## with:
## image: ${{steps.image_name.outputs.name}}
## checksum: ${{needs.setup.outputs.checksum}}
## target: "dist"
## username: ${{ secrets.DOCKERHUB_USERNAME }}
## password: ${{ secrets.DOCKERHUB_TOKEN }}
## token: ${{ secrets.GITHUB_TOKEN }}
## - run: |
## echo "::notice:: ${{steps.image_name.outputs.name}} pushed to dockerhub"