From b501b60470bf77046a74cab8c30cf18e1cb7d753 Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Thu, 16 Jan 2025 19:05:49 +0100 Subject: [PATCH 1/5] separated workflows and extended python versions --- .github/workflows/build-ultraplot.yml | 7 ++++++- .github/workflows/linter.yml | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-ultraplot.yml b/.github/workflows/build-ultraplot.yml index 6df88c53d..163f20033 100644 --- a/.github/workflows/build-ultraplot.yml +++ b/.github/workflows/build-ultraplot.yml @@ -6,9 +6,13 @@ on: branches: [main] jobs: - build: + build-ultraplot: runs-on: ubuntu-latest timeout-minutes: 15 + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + fail-fast: false steps: - uses: actions/checkout@v3 - uses: mamba-org/setup-micromamba@v2.0.3 @@ -16,6 +20,7 @@ jobs: environment-file: ./environment-dev.yml init-shell: bash create-args: --verbose + python=${{ matrix.python-version }} cache-environment: true cache-downloads: false diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 45fce116e..0ba6769e0 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -6,7 +6,7 @@ on: branches: [main] jobs: - build: + linter: runs-on: ubuntu-latest timeout-minutes: 15 steps: From a8798a2ed3e05feada717327d393fb42c80059a9 Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Thu, 16 Jan 2025 19:21:40 +0100 Subject: [PATCH 2/5] added a main matrix to different python versions --- .github/workflows/build-docs.yml | 11 +++--- .github/workflows/build-ultraplot.yml | 19 +++++------ .github/workflows/linter.yml | 9 ++--- .github/workflows/main.yml | 48 +++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/build-docs.yml b/.github/workflows/build-docs.yml index 627dbc24b..dfa347643 100644 --- a/.github/workflows/build-docs.yml +++ b/.github/workflows/build-docs.yml @@ -1,12 +1,13 @@ name: Build docs on: - push: - branches: [main] - pull_request: - branches: [main] + workflow_call: + inputs: + python-version: + required: true + type: string jobs: - build: + build-docs: runs-on: ubuntu-latest timeout-minutes: 15 steps: diff --git a/.github/workflows/build-ultraplot.yml b/.github/workflows/build-ultraplot.yml index 163f20033..4fcc0d43e 100644 --- a/.github/workflows/build-ultraplot.yml +++ b/.github/workflows/build-ultraplot.yml @@ -1,26 +1,25 @@ name: Build and Test on: - push: - branches: [main] - pull_request: - branches: [main] + workflow_call: + inputs: + python-version: + required: true + type: string jobs: build-ultraplot: + name: Test Python ${{ inputs.python-version }} runs-on: ubuntu-latest timeout-minutes: 15 - strategy: - matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] - fail-fast: false steps: - uses: actions/checkout@v3 - uses: mamba-org/setup-micromamba@v2.0.3 with: environment-file: ./environment-dev.yml init-shell: bash - create-args: --verbose - python=${{ matrix.python-version }} + create-args: >- + --verbose + python=${{ inputs.python-version }} cache-environment: true cache-downloads: false diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 0ba6769e0..ea802fcba 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -1,9 +1,10 @@ name: Linter check on: - push: - branches: [main] - pull_request: - branches: [main] + workflow_call: + inputs: + python-version: + required: true + type: string jobs: linter: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000..bd7954bd0 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,48 @@ +name: Matrix Test +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + get-python-versions: + runs-on: ubuntu-latest + outputs: + python-versions: ${{ steps.set-versions.outputs.python-versions }} + steps: + - uses: actions/checkout@v3 + - id: set-versions + run: | + VERSIONS=$(python3 -c ' + import tomli + import re + with open("pyproject.toml", "rb") as f: + data = tomli.load(f) + python_req = data["project"]["requires-python"] + min_version = re.search(r">=(\d+\.\d+)", python_req) + max_version = re.search(r"<(\d+\.\d+)", python_req) + if min_version and max_version: + min_v = tuple(map(int, min_version.group(1).split("."))) + max_v = tuple(map(int, max_version.group(1).split("."))) + versions = [] + current = min_v + while current < max_v: + versions.append(".".join(map(str, current))) + current = (current[0], current[1] + 1) + print(str(versions).replace("\'", "\"")) + ') + echo "python-versions=${VERSIONS}" >> $GITHUB_OUTPUT + + call-workflow: + needs: get-python-versions + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ${{ fromJson(needs.get-python-versions.outputs.python-versions) }} + steps: + - uses: actions/checkout@v3 + - name: Call Build Workflow + uses: ./.github/workflows/build-ultraplot.yml + with: + python-version: ${{ matrix.python-version }} From b9f08d234bb6f3208d2b6a950d3d2834b967b4a8 Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Thu, 16 Jan 2025 19:24:28 +0100 Subject: [PATCH 3/5] added py versions to docs and linter --- .github/workflows/build-docs.yml | 1 + .github/workflows/linter.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/build-docs.yml b/.github/workflows/build-docs.yml index dfa347643..a4a569828 100644 --- a/.github/workflows/build-docs.yml +++ b/.github/workflows/build-docs.yml @@ -17,6 +17,7 @@ jobs: environment-file: ./environment-dev.yml init-shell: bash create-args: --verbose + python=${{ inputs.python-version }} cache-environment: true cache-downloads: false diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index ea802fcba..fc6de3cc6 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -17,6 +17,7 @@ jobs: environment-file: ./environment-dev.yml init-shell: bash create-args: --verbose + python=${{ inputs.python-version }} cache-environment: true cache-downloads: false From 1ecb15c16c90d60bf9dab98aaafa47cfcf08bdff Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Thu, 16 Jan 2025 19:37:14 +0100 Subject: [PATCH 4/5] just run job on push without checkout all --- .github/workflows/linter.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index fc6de3cc6..0ba6769e0 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -1,10 +1,9 @@ name: Linter check on: - workflow_call: - inputs: - python-version: - required: true - type: string + push: + branches: [main] + pull_request: + branches: [main] jobs: linter: @@ -17,7 +16,6 @@ jobs: environment-file: ./environment-dev.yml init-shell: bash create-args: --verbose - python=${{ inputs.python-version }} cache-environment: true cache-downloads: false From 34e17948ddffeef19b2dade2f0bceec12d71f2c5 Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Thu, 16 Jan 2025 19:39:16 +0100 Subject: [PATCH 5/5] main workflow runs build and docs --- .github/workflows/main.yml | 44 +++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bd7954bd0..81c8075c0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,37 +12,57 @@ jobs: python-versions: ${{ steps.set-versions.outputs.python-versions }} steps: - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.11" + + - name: Install dependencies + run: pip install tomli + - id: set-versions run: | - VERSIONS=$(python3 -c ' + # Save the Python script to a file + cat > get_versions.py << 'EOF' import tomli import re + import json + with open("pyproject.toml", "rb") as f: data = tomli.load(f) python_req = data["project"]["requires-python"] min_version = re.search(r">=(\d+\.\d+)", python_req) max_version = re.search(r"<(\d+\.\d+)", python_req) + + versions = [] if min_version and max_version: min_v = tuple(map(int, min_version.group(1).split("."))) max_v = tuple(map(int, max_version.group(1).split("."))) - versions = [] current = min_v while current < max_v: versions.append(".".join(map(str, current))) current = (current[0], current[1] + 1) - print(str(versions).replace("\'", "\"")) - ') + + print(json.dumps(versions)) + EOF + + # Run the Python script and capture output + VERSIONS=$(python3 get_versions.py) echo "python-versions=${VERSIONS}" >> $GITHUB_OUTPUT - call-workflow: + build-test: needs: get-python-versions - runs-on: ubuntu-latest strategy: matrix: python-version: ${{ fromJson(needs.get-python-versions.outputs.python-versions) }} - steps: - - uses: actions/checkout@v3 - - name: Call Build Workflow - uses: ./.github/workflows/build-ultraplot.yml - with: - python-version: ${{ matrix.python-version }} + uses: ./.github/workflows/build-ultraplot.yml + with: + python-version: ${{ matrix.python-version }} + + build-docs: + needs: get-python-versions + strategy: + matrix: + python-version: ${{ fromJson(needs.get-python-versions.outputs.python-versions) }} + uses: ./.github/workflows/build-docs.yml + with: + python-version: ${{ matrix.python-version }}