Skip to content

Commit

Permalink
issue #4: get PR info and push file
Browse files Browse the repository at this point in the history
  • Loading branch information
vivalareda committed Dec 15, 2023
1 parent 9a96d19 commit b76bfe2
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions .github/workflows/workflow-lint-test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ name: Reusable lint and test workflow for Python projects

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


jobs:
lint-test:
Expand All @@ -18,14 +23,6 @@ jobs:
python-version: '3.11.x'
cache: 'pip'

- name: Set threshold value
run: |
if test -f coverage_threshold.txt; then
echo "THRESHOLD=$(cat coverage_threshold.txt)" >> $GITHUB_ENV
else
echo "THRESHOLD=0" >> $GITHUB_ENV
fi
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -43,7 +40,7 @@ jobs:
run: |
python -m coverage run -m unittest discover -s tests
echo "CURRENTCOVERAGE=$(python -m coverage report | grep 'TOTAL' | awk '{print $NF}')" >> $GITHUB_ENV
python -m coverage report --fail-under=${{ env.THRESHOLD }}
python -m coverage report --fail-under=${{ inputs.threshold }}
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
LOUIS_DSN: ${{ secrets.LOUIS_DSN }}
Expand All @@ -61,26 +58,33 @@ jobs:
- name: Compare coverage with threshold
id: compare_values
run: |
if [ $(echo "$CURRENTCOVERAGE > $THRESHOLD" | bc) -eq 1 ]; then
echo "update_value=true" >> $GITHUB_OUTPUT
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
- name: Update file
if: steps.compare_values.outputs.update_value == 'true'
uses: BoundfoxStudios/action-write-file@v1
uses: richardrigutins/replace-in-files@v2
with:
path: ./coverage_threshold.txt
contents: |
$CURRENTCOVERAGE
write-mode: overwrite
files: '.github/workflows/gcp-deployment.yml'
search-text: 'threshold: ${{ inputs.threshold }}'
replacement-text: 'threshold: ${{ steps.compare_values.outputs.current_coverage }}'

- name: Commit & Push
if: github.ref == 'refs/heads/main'
uses: Andro999b/[email protected]
- name: Get PR Info
if: steps.compare_values.outputs.update_value == 'true'
uses: minhchienwikipedia/get-pr-info@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: main
force: true
message: 'Update threshold file'
token: ${{ secrets.GITHUB_TOKEN }}

- name: Push new file
run: |
git checkout -b ${{ env.GIT_BRANCH_NAME }}
cd .github/workflows
git add .github/workflows/gcp-deployment.yml
git commit -m "Update threshold"
git push origin ${{ env.GIT_BRANCH_NAME }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit b76bfe2

Please sign in to comment.