From b76bfe259e0b197a235404148e5eb73ce49a6027 Mon Sep 17 00:00:00 2001 From: reda Date: Fri, 15 Dec 2023 13:05:58 -0500 Subject: [PATCH] issue #4: get PR info and push file --- .../workflows/workflow-lint-test-python.yml | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index 978afd1..2dce3d5 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -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/push@v1.3 + - 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 }}