[Integration][BitBucket] PR identifiers not unique across repos #9048
This file contains hidden or 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
name: 🌊 Ocean Core Tests | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
workflow_dispatch: | |
jobs: | |
detect-changes: | |
uses: ./.github/workflows/detect-changes-matrix.yml | |
test: | |
name: 🌊 Ocean Core Tests | |
needs: detect-changes | |
runs-on: ubuntu-latest | |
if: ${{ needs.detect-changes.outputs.core == 'true' }} | |
steps: | |
- name: Checkout Repo | |
uses: actions/checkout@v5 | |
- name: Install poetry | |
run: pipx install 'poetry>=1.0.0,<2.0.0' | |
- name: Set up Python 3.12 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12' | |
cache: 'poetry' | |
- name: Install dependencies | |
run: | | |
make install | |
- name: Unit Test Core | |
env: | |
PYTEST_ADDOPTS: --cov --cov-report= --cov-append --junitxml=junit/unit-test-results-ocean/core.xml | |
run: | | |
make test | |
- name: Build core for smoke test | |
run: | | |
make build | |
- name: Run fake integration for core test | |
env: | |
PORT_CLIENT_ID: ${{ secrets.PORT_CLIENT_ID }} | |
PORT_CLIENT_SECRET: ${{ secrets.PORT_CLIENT_SECRET }} | |
PORT_BASE_URL: ${{ secrets.PORT_BASE_URL }} | |
SMOKE_TEST_SUFFIX: ${{ github.run_id }} | |
OCEAN__PROCESS_EXECUTION_MODE: single_process | |
OCEAN__CACHING_STORAGE_MODE: memory | |
run: | | |
./scripts/run-smoke-test.sh | |
- name: Smoke Test Core | |
env: | |
PYTEST_ADDOPTS: --cov --cov-report= --cov-append --junitxml=junit/smoke-test-results-ocean/core.xml | |
PORT_CLIENT_ID: ${{ secrets.PORT_CLIENT_ID }} | |
PORT_CLIENT_SECRET: ${{ secrets.PORT_CLIENT_SECRET }} | |
PORT_BASE_URL: ${{ secrets.PORT_BASE_URL }} | |
SMOKE_TEST_SUFFIX: ${{ github.run_id }} | |
run: | | |
make smoke/test | |
- name: Cleanup Smoke Test | |
if: always() | |
env: | |
PYTEST_ADDOPTS: --cov --cov-report= --cov-append --junitxml=junit/smoke-test-results-ocean/core.xml | |
PORT_CLIENT_ID: ${{ secrets.PORT_CLIENT_ID }} | |
PORT_CLIENT_SECRET: ${{ secrets.PORT_CLIENT_SECRET }} | |
PORT_BASE_URL: ${{ secrets.PORT_BASE_URL }} | |
SMOKE_TEST_SUFFIX: ${{ github.run_id }} | |
run: | | |
make smoke/clean | |
- name: Run fake integration for core test with multiprocessing enabled | |
env: | |
PORT_CLIENT_ID: ${{ secrets.PORT_CLIENT_ID }} | |
PORT_CLIENT_SECRET: ${{ secrets.PORT_CLIENT_SECRET }} | |
PORT_BASE_URL: ${{ secrets.PORT_BASE_URL }} | |
SMOKE_TEST_SUFFIX: ${{ github.run_id }} | |
OCEAN__PROCESS_EXECUTION_MODE: multi_process | |
OCEAN__CACHING_STORAGE_MODE: disk | |
run: | | |
./scripts/run-smoke-test.sh | |
- name: Smoke Test Core | |
env: | |
PYTEST_ADDOPTS: --cov --cov-report= --cov-append --junitxml=junit/smoke-test-results-ocean/core.xml | |
PORT_CLIENT_ID: ${{ secrets.PORT_CLIENT_ID }} | |
PORT_CLIENT_SECRET: ${{ secrets.PORT_CLIENT_SECRET }} | |
PORT_BASE_URL: ${{ secrets.PORT_BASE_URL }} | |
SMOKE_TEST_SUFFIX: ${{ github.run_id }} | |
run: | | |
make smoke/test | |
- name: Cleanup Smoke Test | |
if: always() | |
env: | |
PYTEST_ADDOPTS: --cov --cov-report= --cov-append --junitxml=junit/smoke-test-results-ocean/core.xml | |
PORT_CLIENT_ID: ${{ secrets.PORT_CLIENT_ID }} | |
PORT_CLIENT_SECRET: ${{ secrets.PORT_CLIENT_SECRET }} | |
PORT_BASE_URL: ${{ secrets.PORT_BASE_URL }} | |
SMOKE_TEST_SUFFIX: ${{ github.run_id }} | |
run: | | |
make smoke/clean | |
- name: Install current core for all integrations | |
run: | | |
echo "Installing local core for all integrations" | |
SCRIPT_TO_RUN='make install/local-core' make execute/all | |
- name: Test all integrations with current core | |
run: | | |
echo "Testing all integrations with local core" | |
SCRIPT_TO_RUN="PYTEST_ADDOPTS=\"--cov --cov-report= --cov-append --junitxml=${PWD}/junit/test-results-core-change/\`pwd | xargs basename\`.xml\" make test" make execute/all | |
- 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: Produce coverage report | |
run: | | |
mkdir -p coverage-merge | |
i=0 | |
find . -type f -name ".coverage" | while read -r file; do | |
i=$((i + 1)) | |
cp "$file" "coverage-merge/.coverage.$i" | |
done | |
make coverage | |
- name: Upload coverage report | |
id: upload-coverage | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage-report | |
path: 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' coverage.json) | |
echo "STMTS_COVERAGE=$stmts" >> $GITHUB_OUTPUT | |
- name: Comment PR with code coverage summary | |
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_MAIN_CLIENT_ID }} | |
clientSecret: ${{ secrets.PORT_MAIN_CLIENT_SECRET }} | |
baseUrl: https://api.getport.io | |
operation: GET | |
identifier: ocean | |
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_MAIN_CLIENT_ID }} | |
clientSecret: ${{ secrets.PORT_MAIN_CLIENT_SECRET }} | |
baseUrl: https://api.getport.io | |
operation: UPSERT | |
identifier: ocean | |
blueprint: repository | |
properties: |- | |
{ | |
"coverage_percent": "${{ steps.set-stmts-coverage.outputs.STMTS_COVERAGE }}" | |
} | |
- name: Publish Test Report | |
uses: mikepenz/action-junit-report@v5 | |
if: ${{ always() }} | |
with: | |
report_paths: '**/junit/**-test-results-**/*.xml' | |
include_passed: true | |
require_tests: true | |
fail_on_failure: true |