-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a96d19
commit b76bfe2
Showing
1 changed file
with
27 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
|
@@ -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 | ||
|
@@ -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 }} | ||
|
@@ -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 }} |