Python package #3730
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
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions | |
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | |
name: Python package | |
on: | |
workflow_dispatch: | |
push: | |
branches: [ main ] | |
paths-ignore: | |
- 'WORKSPACE' | |
- 'src/**' | |
pull_request: | |
branches: [ main ] | |
paths-ignore: | |
- 'WORKSPACE' | |
- 'src/**' | |
schedule: | |
# This job runs at 00:00 JST every day. | |
- cron: '0 9 * * *' | |
env: | |
LAUNCHABLE_ORGANIZATION: "launchableinc" | |
LAUNCHABLE_WORKSPACE: "cli" | |
GITHUB_PULL_REQUEST_URL: ${{ github.event.pull_request.html_url }} | |
GITHUB_PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-20.04, windows-latest] | |
python-version: [3.6, 3.7, 3.8, 3.9, "3.10", "3.11", "3.12"] | |
steps: | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
with: | |
fetch-depth: 0 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Set up JDK 1.8 | |
uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0 | |
with: | |
java-version: 8 | |
distribution: 'temurin' | |
- name: Install specific dependencies in 3.6 | |
if: matrix.python-version == '3.6' | |
uses: nick-fields/retry@7152eba30c6575329ac0576536151aca5a72780e # v3.0.0 | |
with: | |
max_attempts: 3 | |
timeout_minutes: 5 | |
retry_on: error | |
command: | | |
python -m pip install --upgrade pip | |
pip install pipenv==2021.11.5 | |
pipenv install --dev --python ${{ matrix.python-version }} | |
- name: Install dependencies | |
if: matrix.python-version != '3.6' | |
uses: nick-fields/retry@7152eba30c6575329ac0576536151aca5a72780e # v3.0.0 | |
with: | |
max_attempts: 3 | |
timeout_minutes: 5 | |
retry_on: error | |
command: | | |
python -m pip install --upgrade pip | |
pip install pipenv | |
pipenv install --dev --python ${{ matrix.python-version }} | |
- name: Build | |
run: | | |
pipenv run pip list | |
pipenv run build | |
pipenv run install | |
- name: Type check | |
run: pipenv run type | |
- name: Lint with flake8 | |
run: | | |
# stop the build if there are Python syntax errors or undefined names | |
pipenv run lint | |
- name: Pull request validation | |
run: | | |
# Install Launchable CLI from this repos's code | |
pip3 install . > /dev/null | |
set -x | |
launchable verify | |
# Tell Launchable about the build you are producing and testing | |
launchable record build --name ${GITHUB_RUN_ID} | |
launchable record session --build ${GITHUB_RUN_ID} --flavor os=${{ matrix.os }} --flavor python=${{ matrix.python-version }} > session.txt | |
# Find 25% of the relevant tests to run for this change | |
find tests -name test_*.py | grep -v tests/data | launchable subset --target 25% --session $(cat session.txt) --rest launchable-remainder.txt file > subset.txt | |
function record() { | |
# Record test results | |
LAUNCHABLE_SLACK_NOTIFICATION=true launchable record tests --session $(cat session.txt) file test-results/*.xml | |
} | |
trap record EXIT | |
# Test subset of tests | |
pipenv run test-xml $(tr '\r\n' '\n' < subset.txt) | |
# Test rest of tests | |
pipenv run test-xml $(tr '\r\n' '\n' < launchable-remainder.txt) | |
shell: bash |