-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from 7rikazhexde/dev24-11-6
👷Add python test workflow
- Loading branch information
Showing
2 changed files
with
122 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
name: Python Test | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- 'main' | ||
paths: | ||
- 'json2vars_setter/**' | ||
- 'tests/**' | ||
- 'pyproject.toml' | ||
- 'poetry.lock' | ||
- 'requirements-dev.txt' | ||
- 'requirements.txt' | ||
- '.github/workflows/python_test.yml' | ||
|
||
jobs: | ||
set_variables: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
os: ${{ steps.json2vars.outputs.os }} | ||
versions_python: ${{ steps.json2vars.outputs.versions_python }} | ||
ghpages_branch: ${{ steps.json2vars.outputs.ghpages_branch }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4.2.2 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set variables from JSON | ||
id: json2vars | ||
uses: 7rikazhexde/json2vars-setter@main | ||
with: | ||
#json-file: .github/workflows/matrix.json | ||
json-file: .github/workflows/python_project_matrix.json | ||
|
||
- name: Debug output values | ||
run: | | ||
echo "os: ${{ steps.json2vars.outputs.os }}" | ||
echo "versions_python: ${{ steps.json2vars.outputs.versions_python }}" | ||
echo "ghpages_branch: ${{ steps.json2vars.outputs.ghpages_branch }}" | ||
run_tests: | ||
needs: set_variables | ||
strategy: | ||
matrix: | ||
os: ${{ fromJson(needs.set_variables.outputs.os) }} | ||
python-version: ${{ fromJson(needs.set_variables.outputs.versions_python) }} | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4.2.2 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5.3.0 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Set timezone | ||
uses: szenius/set-timezone@v2.0 | ||
with: | ||
timezoneLinux: "Asia/Tokyo" | ||
timezoneMacos: "Asia/Tokyo" | ||
timezoneWindows: "Tokyo Standard Time" | ||
|
||
- name: Install poetry | ||
run: | | ||
pip install poetry | ||
echo "Poetry version: $(poetry --version)" | ||
- name: Cache dependencies | ||
uses: actions/cache@v4.1.2 | ||
with: | ||
path: ~/.cache/pypoetry | ||
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
poetry install | ||
echo "Installed dependencies:" | ||
poetry show --tree | ||
- name: Show matrix | ||
shell: bash | ||
run: | | ||
# For non-list case | ||
ghpages_branch="${{ needs.set_variables.outputs.ghpages_branch }}" | ||
# For list case, explicitly enclose the list in “” to make it a string. (Note that it is not ''.) | ||
os='${{ needs.set_variables.outputs.os }}' | ||
versions_python='${{ needs.set_variables.outputs.versions_python }}' | ||
echo "os: $os" | ||
echo "versions_python: ${versions_python}" | ||
echo "ghpages_branch: ${ghpages_branch}" | ||
# For loop case | ||
os_list=$(echo "${os}" | jq -r '.[]' | tr '\n' ' ' | sed 's/ $//') | ||
python_versions_list=$(echo "${versions_python}" | jq -r '.[]' | tr '\n' ' ' | sed 's/ $//') | ||
for current_os in ${os_list}; do | ||
for version in ${python_versions_list}; do | ||
echo "Current OS: ${current_os}, Current Python Version: ${version}" | ||
done | ||
done | ||
- name: Run pytest | ||
id: pytest | ||
shell: bash | ||
run: | | ||
output="$(poetry run pytest)" | ||
echo "${output}" |
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