Skip to content

Support HTTPS Polling for Port-Agent #344

Support HTTPS Polling for Port-Agent

Support HTTPS Polling for Port-Agent #344

Workflow file for this run

name: Python application
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v3
with:
python-version: "3.11"
# Install Poetry
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
export PATH="$HOME/.local/bin:$PATH"
# Install dependencies via Poetry
- name: Install dependencies
run: |
export PATH="$HOME/.local/bin:$PATH"
poetry install --no-interaction --no-ansi
# Run Lint
- name: Lint
run: |
export PATH="$HOME/.local/bin:$PATH"
poetry run ./scripts/lint.sh
# Run Tests with Pytest
- name: Test with pytest
run: |
export PATH="$HOME/.local/bin:$PATH"
poetry run ./scripts/test.sh
- name: Create coverage report
run: |
cd app
poetry run coverage html
poetry run coverage json
- name: Upload coverage report
id: upload-coverage
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: app/htmlcov
- name: Set repo code coverage percentage by the percentage of statements covered in the tests
id: set-stmts-coverage
run: |
stmts=$(jq '.totals.percent_covered | . * 100 | round | . / 100' app/coverage.json)
echo "STMTS_COVERAGE=$stmts" >> $GITHUB_OUTPUT
- name: Get PR_NUMBER
id: pr-number
run: |
if [ ! -z ${{ inputs.PR_NUMBER }} ]; then
echo "PR_NUMBER=${{ inputs.PR_NUMBER }}" >> $GITHUB_OUTPUT
elif [ ! -z ${{ github.event.pull_request.number }} ]; then
echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
else
echo "PR_NUMBER=0" >> $GITHUB_OUTPUT
fi
- name: Comment PR with code coverage summary
if: ${{ steps.pr-number.outputs.PR_NUMBER != 0 }}
uses: actions/github-script@v7
env:
CODE_COVERAGE_ARTIFACT_URL: ${{ steps.upload-coverage.outputs.artifact-url }}
PR_NUMBER: ${{ steps.pr-number.outputs.PR_NUMBER }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Code Coverage Artifact 📈: ${{ env.CODE_COVERAGE_ARTIFACT_URL }}
#### Code Coverage Total Percentage: \`${{ steps.set-stmts-coverage.outputs.STMTS_COVERAGE }}%\``;
github.rest.issues.createComment({
issue_number: ${{ env.PR_NUMBER }},
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
- name: Get current repo coverage percentage from Port
uses: port-labs/port-github-action@v1
id: get-current-coverage
with:
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.getport.io
operation: GET
identifier: port-agent
blueprint: repository
- name: Set current code coverage
id: set-current-coverage
run: echo "CURRENT_COVERAGE=${{ fromJson(steps.get-current-coverage.outputs.entity).properties.coverage_percent }}" >> $GITHUB_OUTPUT
- name: Comment if Coverage Regression
if: ${{ (fromJson(steps.set-stmts-coverage.outputs.STMTS_COVERAGE) < fromJson(steps.set-current-coverage.outputs.CURRENT_COVERAGE)) && (steps.pr-number.outputs.PR_NUMBER != 0) }}
uses: actions/github-script@v7
env:
PR_NUMBER: ${{ steps.pr-number.outputs.PR_NUMBER }}
CURRENT_COVERAGE: ${{ steps.set-current-coverage.outputs.CURRENT_COVERAGE }}
NEW_COVERAGE: ${{ steps.set-stmts-coverage.outputs.STMTS_COVERAGE }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `🚨 The new code coverage percentage is lower than the current one. Current coverage: \`${{ env.CURRENT_COVERAGE }}\`\n While the new one is: \`${{ env.NEW_COVERAGE }}\``;
github.rest.issues.createComment({
issue_number: ${{ env.PR_NUMBER }},
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
- name: Calculate minimum required coverage with tolerance
run: |
STMT_COVERAGE=${{ steps.set-stmts-coverage.outputs.STMTS_COVERAGE }}
THRESHOLD_DELTA=${{ vars.COVERAGE_THRESHOLD_DELTA }}
MIN_REQUIRED=$(echo "$STMT_COVERAGE + $THRESHOLD_DELTA" | bc)
echo "MIN_REQUIRED_COVERAGE=$MIN_REQUIRED" >> $GITHUB_ENV
- name: Fail PR if current code coverage percentage is higher than the new one
if: ${{ (fromJson(env.MIN_REQUIRED_COVERAGE) < fromJson(steps.set-current-coverage.outputs.CURRENT_COVERAGE)) && (vars.CODE_COVERAGE_ENFORCEMENT == 'true') }}
run: exit 1
- name: Update service code coverage percentage in Port
if: ${{ (github.event_name == 'push') }}
uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.getport.io
operation: UPSERT
identifier: port-agent
blueprint: repository
properties: |-
{
"coverage_percent": "${{ steps.set-stmts-coverage.outputs.STMTS_COVERAGE }}"
}