Skip to content

Commit

Permalink
issue #4: add threshold
Browse files Browse the repository at this point in the history
issue #4: remove PAT use

issue #4: add permissions

issue #4: change secret

issue #4: use PAT

issue #4: push changes without action

fix syntax

add env to add and commit

issue #4: add token

add permission

add PR reference to checkout

issue #4: reusable workflow add and commit

issue #4: no pull

pull branch and rebase true

add true to rebase

add main to pull

remove branch name from pul

issue #4: echo value for debug

issue #4: add pull origin command

issue #4: add username and email

issue #4: edit push step

issue #4: add id to step

issue #4: change compare step

issue #4: get PR info and push file

issue #4: add push

issue #4: change deprecated var assignment

issue #4: add steps

issue #4: change value set strategy

issue #4: change aciton for file presence

issue #4: change action branch

issue #4: remove fail condition

issue #4: install coverage package
  • Loading branch information
vivalareda committed Dec 22, 2023
1 parent 46c1b5d commit 72619e3
Showing 1 changed file with 58 additions and 3 deletions.
61 changes: 58 additions & 3 deletions .github/workflows/workflow-lint-test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,52 @@ name: Reusable lint and test workflow for Python projects

on:
workflow_call:
inputs:
threshold:
required: true
type: number

permissions:
actions: read
pull-requests: write

jobs:
lint-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Checkout code
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11.x'
cache: 'pip'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff==0.1.0
pip install ruff==0.1.0 coverage
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with ruff
run: |
# stop the build if there are Python syntax errors or undefined names
ruff --output-format=github --select=E9,F63,F7,F82 --target-version=py311 .
# default set of ruff rules with GitHub Annotations
ruff --output-format=github --target-version=py311 .
- name: Test and Coverage with unittest
run: |
python -m coverage run -m unittest discover -s tests
python -m coverage report --show-missing --fail-under=60
COVERAGE=$(python -m coverage report | grep 'TOTAL' | awk '{print $NF}' | sed 's/%//')
echo "CURRENTCOVERAGE=$COVERAGE" >> $GITHUB_ENV
python -m coverage report --fail-under=${{ inputs.threshold }}
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
LOUIS_DSN: ${{ secrets.LOUIS_DSN }}
Expand All @@ -42,3 +61,39 @@ jobs:
PGPASSWORD: ${{ secrets.PGPASSWORD }}
PGPORT: ${{ secrets.PGPORT }}
PGUSER: ${{ secrets.PGUSER }}

- name: Compare coverage with threshold
id: compare_values
run: |
if [ $(echo "$CURRENTCOVERAGE > ${{ inputs.threshold }}" | bc) -eq 1 ]; then
echo "update_value=true" >> $GITHUB_OUTPUT
echo "::set-output name=current_coverage::$CURRENTCOVERAGE"
else
echo "update_value=false" >> $GITHUB_OUTPUT
fi
shell: /usr/bin/bash -e {0}
env:
CURRENTCOVERAGE: ${{ env.CURRENTCOVERAGE }}

- name: Update file
if: steps.compare_values.outputs.update_value == 'true'
uses: richardrigutins/replace-in-files@v2
with:
files: '.github/workflows/gcp-deployment.yml'
search-text: 'threshold: ${{ inputs.threshold }}'
replacement-text: 'threshold: ${{ steps.compare_values.outputs.current_coverage }}'

- name: Get PR Info
if: steps.compare_values.outputs.update_value == 'true'
uses: minhchienwikipedia/get-pr-info@master
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Push changes
if: steps.compare_values.outputs.update_value == 'true'
run: |
git config --global user.name "GitHub bot"
git config --global user.email "[email protected]"
git add -A
git commit -m "Update threshold value in workflow"
git push

0 comments on commit 72619e3

Please sign in to comment.