Skip to content

Commit 18a4638

Browse files
Bordapre-commit-ci[bot]carmocca
authored
CI: clean install & share pkg build (#15986)
* abstract pkg build * share ci * syntax * Checkgroup * folders * whl 1st * doctest Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Carlos Mocholí <[email protected]>
1 parent ed52823 commit 18a4638

File tree

21 files changed

+182
-110
lines changed

21 files changed

+182
-110
lines changed

.github/actions/pkg-check/action.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ inputs:
55
pkg-name:
66
description: package name inside lightning.*
77
required: true
8-
default: ""
98
nb-dirs:
109
description: nb of packages in the wrap/distribution
1110
required: false

.github/actions/pkg-install/action.yml

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: Install and validate the package
22
description: Install and validate the package
33

44
inputs:
5+
pkg-folder:
6+
description: Define folder with packages
7+
required: true
58
pkg-name:
69
description: Package name to import
710
required: true
@@ -14,22 +17,27 @@ runs:
1417
using: "composite"
1518
steps:
1619
- name: Choose package import
20+
working-directory: ${{ inputs.pkg-folder }}
1721
run: |
18-
python -c "print('PKG_IMPORT=' + {'app': 'lightning_app', 'lite': 'lightning_lite', 'pytorch': 'pytorch_lightning', 'lightning': 'lightning', 'notset': 'lightning'}['${{matrix.pkg-name}}'])" >> $GITHUB_ENV
19-
shell: bash
20-
21-
- name: Install package - archive
22-
working-directory: ./dist
23-
run: |
24-
pip install *.tar.gz ${{ inputs.pip-flags }}
25-
pip list | grep lightning
26-
python -c "import ${{ env.PKG_IMPORT }}; print(${{ env.PKG_IMPORT }}.__version__)"
22+
ls -l
23+
python -c "print('PKG_IMPORT=' + {'app': 'lightning_app', 'lite': 'lightning_lite', 'pytorch': 'pytorch_lightning'}.get('${{matrix.pkg-name}}', 'lightning'))" >> $GITHUB_ENV
24+
python -c "import glob ; ls = glob.glob('*.tar.gz') ; print('PKG_SOURCE=' + ls[0])" >> $GITHUB_ENV
25+
python -c "import glob ; ls = glob.glob('*.whl') ; print('PKG_WHEEL=' + ls[0])" >> $GITHUB_ENV
2726
shell: bash
2827

2928
- name: Install package - wheel
30-
working-directory: ./dist
29+
working-directory: ${{ inputs.pkg-folder }}
3130
run: |
32-
pip install *.whl ${{ inputs.pip-flags }}
31+
pip install ${PKG_WHEEL} ${{ inputs.pip-flags }}
3332
pip list | grep lightning
3433
python -c "import ${{ env.PKG_IMPORT }}; print(${{ env.PKG_IMPORT }}.__version__)"
3534
shell: bash
35+
36+
# FIXME !!!
37+
# - name: Install package - archive
38+
# working-directory: ${{ inputs.pkg-folder }}
39+
# run: |
40+
# pip install ${PKG_SOURCE} ${{ inputs.pip-flags }}
41+
# pip list | grep lightning
42+
# python -c "import ${{ env.PKG_IMPORT }}; print(${{ env.PKG_IMPORT }}.__version__)"
43+
# shell: bash

.github/actions/pkg-publish/action.yml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: Publish package
22
description: publishing whl and src to PyPI
33

44
inputs:
5-
pkg-pattern:
6-
description: what file pattern is searched in folder, so for example `*_app*`
5+
pkg-folder:
6+
description: define folder with packages
77
required: true
88
pypi-test-token:
99
description: login token for PyPI
@@ -18,10 +18,7 @@ runs:
1818
using: "composite"
1919
steps:
2020

21-
- name: filter packages
22-
run: |
23-
mv dist/${{ inputs.pkg-pattern }} pypi/
24-
ls -l pypi/
21+
- run: ls -lh ${{ inputs.pkg-folder }}
2522
shell: bash
2623

2724
# We do this, since failures on test.pypi aren't that bad
@@ -32,7 +29,7 @@ runs:
3229
user: __token__
3330
password: ${{ inputs.pypi-test-token }}
3431
repository_url: https://test.pypi.org/legacy/
35-
packages_dir: pypi/
32+
packages_dir: ${{ inputs.pkg-folder }}
3633
verbose: true
3734

3835
- name: Publish distribution 📦 to PyPI
@@ -41,9 +38,5 @@ runs:
4138
with:
4239
user: __token__
4340
password: ${{ inputs.pypi-token }}
44-
packages_dir: pypi/
41+
packages_dir: ${{ inputs.pkg-folder }}
4542
verbose: true
46-
47-
- name: filter packages
48-
run: rm pypi/*
49-
shell: bash

.github/checkgroup.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ subprojects:
314314
- id: "install"
315315
paths:
316316
- ".actions/**"
317+
- ".github/actions/pkg-check/*"
318+
- ".github/actions/pkg-install/*"
319+
- ".github/workflows/_build-packages.yml"
317320
- ".github/workflows/ci-pkg-install.yml"
318321
- "setup.py"
319322
- "src/**"

.github/workflows/_build-packages.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Building packages
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
artifact-name:
7+
description: 'Unique name for collecting artifacts'
8+
required: true
9+
type: string
10+
pkg-names:
11+
description: 'list package names to be build in json format'
12+
required: false
13+
type: string
14+
default: |
15+
["lightning", "app", "lite", "pytorch"]
16+
17+
defaults:
18+
run:
19+
shell: bash
20+
21+
jobs:
22+
23+
init:
24+
runs-on: ubuntu-20.04
25+
steps:
26+
- uses: actions/checkout@v3
27+
- run: |
28+
mkdir dist && touch dist/.placeholder
29+
- uses: actions/upload-artifact@v3
30+
with:
31+
name: ${{ inputs.artifact-name }}
32+
path: dist
33+
34+
35+
build-packages:
36+
needs: init
37+
runs-on: ubuntu-20.04
38+
strategy:
39+
max-parallel: 1 # run sequential to prevent download/upload collisions
40+
matrix:
41+
pkg-name: ${{ fromJSON(inputs.pkg-names) }}
42+
steps:
43+
- uses: actions/checkout@v3
44+
- uses: actions/download-artifact@v3
45+
with:
46+
name: ${{ inputs.artifact-name }}
47+
path: pypi
48+
- uses: actions/setup-python@v4
49+
with:
50+
python-version: 3.9
51+
52+
- run: python -c "print('NB_DIRS=' + str(2 if '${{ matrix.pkg-name }}' == 'pytorch' else 1))" >> $GITHUB_ENV
53+
- uses: ./.github/actions/pkg-check
54+
with:
55+
pkg-name: ${{ matrix.pkg-name }}
56+
nb-dirs: ${{ env.NB_DIRS }}
57+
58+
- run: |
59+
mkdir pypi/${{ matrix.pkg-name }}
60+
cp dist/* pypi/${{ matrix.pkg-name }}/
61+
62+
- uses: actions/upload-artifact@v3
63+
with:
64+
name: ${{ inputs.artifact-name }}
65+
path: pypi

.github/workflows/ci-app-examples.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,16 @@ jobs:
9393

9494
- name: Adjust tests
9595
if: ${{ matrix.pkg-name == 'lightning' }}
96-
run: python .actions/assistant.py copy_replace_imports --source_dir="./tests" --source_import="lightning_app" --target_import="lightning.app"
96+
run: |
97+
python .actions/assistant.py copy_replace_imports --source_dir="./tests" \
98+
--source_import="lightning_app" --target_import="lightning.app"
9799
98100
- name: Adjust examples
99101
if: ${{ matrix.pkg-name != 'lightning' }}
100102
run: |
101-
python .actions/assistant.py copy_replace_imports --source_dir="./examples" --source_import="lightning.app,lightning" --target_import="lightning_app,lightning_app"
103+
python .actions/assistant.py copy_replace_imports --source_dir="./examples" \
104+
--source_import="lightning.app,lightning" \
105+
--target_import="lightning_app,lightning_app"
102106
103107
- name: Switch coverage scope
104108
run: python -c "print('COVERAGE_SCOPE=' + str('lightning' if '${{matrix.pkg-name}}' == 'lightning' else 'lightning_app'))" >> $GITHUB_ENV

.github/workflows/ci-app-tests.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,17 @@ jobs:
9494

9595
- name: Adjust tests
9696
if: ${{ matrix.pkg-name == 'lightning' }}
97-
run: python .actions/assistant.py copy_replace_imports --source_dir="./tests" --source_import="lightning_app,lightning_lite,pytorch_lightning" --target_import="lightning.app,lightning.lite,lightning.pytorch"
97+
run: |
98+
python .actions/assistant.py copy_replace_imports --source_dir="./tests" \
99+
--source_import="lightning_app,lightning_lite,pytorch_lightning" \
100+
--target_import="lightning.app,lightning.lite,lightning.pytorch"
98101
99102
- name: Adjust examples
100103
if: ${{ matrix.pkg-name != 'lightning' }}
101104
run: |
102-
python .actions/assistant.py copy_replace_imports --source_dir="./examples" --source_import="lightning.app,lightning" --target_import="lightning_app,lightning_app"
105+
python .actions/assistant.py copy_replace_imports --source_dir="./examples" \
106+
--source_import="lightning.app,lightning" \
107+
--target_import="lightning_app,lightning_app"
103108
104109
- name: Switch coverage scope
105110
run: python -c "print('COVERAGE_SCOPE=' + str('lightning' if '${{matrix.pkg-name}}' == 'lightning' else 'lightning_app'))" >> $GITHUB_ENV

.github/workflows/ci-lite-tests.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ jobs:
114114
115115
- name: Adjust tests
116116
if: ${{ matrix.pkg-name == 'lightning' }}
117-
run: python .actions/assistant.py copy_replace_imports --source_dir="./tests" --source_import="lightning_lite" --target_import="lightning.lite"
117+
run: |
118+
python .actions/assistant.py copy_replace_imports --source_dir="./tests" \
119+
--source_import="lightning_lite" --target_import="lightning.lite"
118120
119121
- name: Testing Warnings
120122
# the stacklevel can only be set on >=3.7

.github/workflows/ci-pkg-install.yml

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
types: [opened, reopened, ready_for_review, synchronize] # added `ready_for_review` since draft is skipped
1010
paths:
1111
- ".actions/**"
12+
- ".github/actions/pkg-check/*"
13+
- ".github/actions/pkg-install/*"
14+
- ".github/workflows/_build-packages.yml"
1215
- ".github/workflows/ci-pkg-install.yml"
1316
- "setup.py"
1417
- "src/**"
@@ -28,52 +31,71 @@ defaults:
2831

2932
jobs:
3033

34+
build-packages:
35+
uses: ./.github/workflows/_build-packages.yml
36+
with:
37+
artifact-name: dist-packages-${{ github.sha }}
38+
3139
install-pkg:
40+
needs: build-packages
3241
runs-on: ${{ matrix.os }}
3342
strategy:
3443
fail-fast: false
3544
matrix:
3645
os: [ubuntu-22.04, macOS-12, windows-2022]
3746
pkg-name: ["app", "lite", "pytorch", "lightning", "notset"]
3847
python-version: ["3.7" , "3.10"]
48+
# TODO: add also install from source
3949
steps:
4050
- uses: actions/checkout@v3
41-
4251
- uses: actions/setup-python@v4
4352
with:
4453
python-version: ${{ matrix.python-version }}
45-
46-
- name: DocTests actions
47-
working-directory: .actions/
48-
run: |
49-
pip install -q pytest
50-
python -m pytest setup_tools.py
51-
52-
- run: python -c "print('NB_DIRS=' + str(2 if '${{ matrix.pkg-name }}' == 'pytorch' else 1))" >> $GITHUB_ENV
53-
54-
- uses: ./.github/actions/pkg-check
54+
- uses: actions/download-artifact@v3
5555
with:
56-
pkg-name: ${{ matrix.pkg-name }}
57-
nb-dirs: ${{ env.NB_DIRS }}
56+
name: dist-packages-${{ github.sha }}
57+
path: dist
5858

59+
- run: |
60+
python -c "print('PKG_DIR=' + {'notset': 'lightning'}.get('${{matrix.pkg-name}}', '${{matrix.pkg-name}}'))" >> $GITHUB_ENV
5961
- uses: ./.github/actions/pkg-install
6062
with:
63+
pkg-folder: dist/${{ env.PKG_DIR }}
6164
pkg-name: ${{ matrix.pkg-name }}
6265

6366
- name: Run CLI (via python)
6467
if: ${{ matrix.pkg-name == 'lightning' || matrix.pkg-name == 'notset' }}
6568
run: python -m lightning --version
66-
6769
- name: Run CLI (direct bash)
6870
if: ${{ matrix.pkg-name == 'lightning' || matrix.pkg-name == 'app' }}
6971
run: lightning --version
7072

73+
- name: Adjust code for Lit
74+
if: ${{ matrix.pkg-name == 'lightning' || matrix.pkg-name == 'notset' }}
75+
run: |
76+
pip install -q -r .actions/requirements.txt
77+
python .actions/assistant.py copy_replace_imports --source_dir="./src" \
78+
--source_import="pytorch_lightning,lightning_lite,lightning_app" \
79+
--target_import="lightning.pytorch,lightning.lite,lightning.app"
80+
rm -rf src/lightning
81+
- name: Rename src folders
82+
working-directory: src/
83+
run: |
84+
mv pytorch_lightning pl
85+
mv lightning_lite lit_lite
86+
mv lightning_app lit_app
87+
88+
- name: DocTests actions
89+
working-directory: .actions/
90+
run: |
91+
pip install -q pytest
92+
python -m pytest setup_tools.py
7193
- name: DocTest package
7294
env:
7395
LIGHTING_TESTING: 1 # path for require wrapper
7496
PY_IGNORE_IMPORTMISMATCH: 1
7597
run: |
7698
pip install -q "pytest-doctestplus>=0.9.0"
7799
pip list
78-
PKG_NAME=$(python -c "print({'app': 'lightning_app', 'lite': 'lightning_lite', 'pytorch': 'pytorch_lightning', 'lightning': 'lightning', 'notset': 'lightning'}['${{matrix.pkg-name}}'])")
100+
PKG_NAME=$(python -c "print({'app': 'lit_app', 'lite': 'lit_lite', 'pytorch': 'pl'}.get('${{matrix.pkg-name}}', ''))")
79101
python -m pytest src/${PKG_NAME} --ignore-glob="**/cli/*-template/**"

.github/workflows/ci-pytorch-tests.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,10 @@ jobs:
169169
170170
- name: Adjust tests
171171
if: ${{ matrix.pkg-name == 'lightning' }}
172-
run: python .actions/assistant.py copy_replace_imports --source_dir="./tests" --source_import="pytorch_lightning,lightning_lite" --target_import="lightning.pytorch,lightning.lite"
172+
run: |
173+
python .actions/assistant.py copy_replace_imports --source_dir="./tests" \
174+
--source_import="pytorch_lightning,lightning_lite" \
175+
--target_import="lightning.pytorch,lightning.lite"
173176
174177
- name: Testing Warnings
175178
# the stacklevel can only be set on >=3.7

0 commit comments

Comments
 (0)