8000 Testing Getting Commits · yonib05/sdk-python@f08805d · GitHub
[go: up one dir, main page]

Skip to content

Test branch

Test branch #1

Workflow file for this run

name: Test and Lint
on:
pull_request: # Safer than pull_request_target for untrusted code
branches: [ main ]
types: [opened, synchronize, reopened, ready_for_review, review_requested, review_request_removed]
push:
branches: [ main ] # Also run on direct pushes to main
jobs:
check-approval:
name: Check if PR has contributor approval
runs-on: ubuntu-latest
permissions:
pull-requests: read
# Skip this check for direct pushes to main
if: github.event_name == 'pull_request'
outputs:
approved: ${{ steps.check-approval.outputs.approved }}
steps:
- name: Check if PR has been approved by a contributor
id: check-approval
uses: actions/github-script@v7
with:
script: |
const APPROVED_ASSOCIATION = ['COLLABORATOR', 'CONTRIBUTOR', 'MEMBER', 'OWNER']
const PR_AUTHOR_ASSOCIATION = context.payload.pull_request.author_association;
const { data: reviews } = await github.rest.pulls.listReviews({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
const { data: commits } = await github.rest.pulls.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
console.log(commits[0].commit);
const isApprovedContributor = APPROVED_ASSOCIATION.includes(PR_AUTHOR_ASSOCIATION);
// Check if any contributor has approved
const isApproved = reviews.some(review =>
review.state === 'APPROVED' && APPROVED_ASSOCIATION.includes(review.author_association)
) || isApprovedContributor;
core.setOutput('approved', isApproved);
if (!isApproved) {
core.notice('This PR does not have approval from a Contributor. Workflow will not run test jobs.');
return false;
}
return true;
unit-test:
name: Unit Tests - Python ${{ matrix.python-version }} - ${{ matrix.os-name }}
needs: check-approval
permissions:
contents: read
# Only run if PR is approved or this is a direct push to main
if: github.event_name == 'push' || needs.check-approval.outputs.approved == 'true'
strategy:
matrix:
include:
# Linux
- os: ubuntu-latest
os-name: linux
python-version: "3.10"
- os: ubuntu-latest
os-name: linux
python-version: "3.11"
- os: ubuntu-latest
os-name: linux
python-version: "3.12"
- os: ubuntu-latest
os-name: linux
python-version: "3.13"
# Windows
- os: windows-latest
os-name: windows
python-version: "3.10"
- os: windows-latest
os-name: windows
python-version: "3.11"
- os: windows-latest
os-name: windows
python-version: "3.12"
- os: windows-latest
os-name: windows
python-version: "3.13"
# MacOS - latest only; not enough runners for MacOS
- os: macos-latest
os-name: macos
python-version: "3.13"
fail-fast: false
runs-on: ${{ matrix.os }}
env:
LOG_LEVEL: DEBUG
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }} # Explicitly define which commit to checkout
persist-credentials: false # Don't persist credentials for subsequent actions
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install --no-cache-dir hatch
- name: Run Unit tests
id: tests
run: hatch test tests --cover
continue-on-error: false
lint:
name: Lint
runs-on: ubuntu-latest
needs: check-approval
permissions:
contents: read
if: github.event_name == 'push' || needs.check-approval.outputs.approved == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'pip'
- name: Install dependencies
run: |
pip install --no-cache-dir hatch
- name: Run lint
id: lint
run: hatch run test-lint
continue-on-error: false
0