⬆️ Bump the dependencies group with 11 updates #162
Workflow file for this run
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
name: Test on PR by matrix.json (Except Dependabot) | |
on: | |
pull_request: | |
branches: | |
- main | |
jobs: | |
set_variables: | |
if: github.actor != 'dependabot[bot]' && !startsWith(github.event.pull_request.title, 'Bump version') | |
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 | |
- name: Debug output values | |
run: | | |
echo "os: ${{ steps.json2vars.outputs.os }}" | |
echo "os[0]: ${{ fromJson(steps.json2vars.outputs.os)[0] }}" | |
echo "os[1]: ${{ fromJson(steps.json2vars.outputs.os)[1] }}" | |
echo "os[2]: ${{ fromJson(steps.json2vars.outputs.os)[2] }}" | |
echo "versions_python: ${{ steps.json2vars.outputs.versions_python }}" | |
echo "versions_python[0]: ${{ fromJson(steps.json2vars.outputs.versions_python)[0] }}" | |
echo "versions_python[1]: ${{ fromJson(steps.json2vars.outputs.versions_python)[1] }}" | |
echo "versions_python[2]: ${{ fromJson(steps.json2vars.outputs.versions_python)[2] }}" | |
echo "versions_python[3]: ${{ fromJson(steps.json2vars.outputs.versions_python)[3] }}" | |
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 }} | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4.2.2 | |
with: | |
fetch-depth: 0 | |
- name: Set up Python | |
uses: actions/setup-python@v5.4.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.2.1 | |
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 }}' | |
# For list index case | |
os_0="${{ fromJson(needs.set_variables.outputs.os)[0] }}" | |
os_1="${{ fromJson(needs.set_variables.outputs.os)[1] }}" | |
os_2="${{ fromJson(needs.set_variables.outputs.os)[2] }}" | |
versions_python_0="${{ fromJson(needs.set_variables.outputs.versions_python)[0] }}" | |
versions_python_1="${{ fromJson(needs.set_variables.outputs.versions_python)[1] }}" | |
versions_python_2="${{ fromJson(needs.set_variables.outputs.versions_python)[2] }}" | |
versions_python_3="${{ fromJson(needs.set_variables.outputs.versions_python)[3] }}" | |
echo "os: ${os}" | |
echo "os_0: ${os_0}" | |
echo "os_1: ${os_1}" | |
echo "os_2: ${os_2}" | |
echo "versions_python: ${versions_python}" | |
echo "versions_python_0: ${versions_python_0}" | |
echo "versions_python_1: ${versions_python_1}" | |
echo "versions_python_2: ${versions_python_2}" | |
echo "versions_python_3: ${versions_python_3}" | |
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 test | |
shell: bash | |
id: pytest | |
# Mac / Linux | |
# run: poetry run pytest --durations=0 --junitxml=pytest.xml --cov-report xml:coverage.xml --cov=project_a tests/ | tee pytest-coverage.txt | |
# Windowss | |
# run: poetry run pytest --durations=0 --junitxml=pytest.xml --cov-report xml:coverage.xml --cov=project_a tests/ | Tee-Object -FilePath pytest-coverage.txt | |
run: | | |
poetry run task test_ci_xml | |
coverage_percentage=$(poetry run coverage report | grep TOTAL | awk '{print $NF}' | sed 's/%//') | |
echo "Current coverage: $coverage_percentage%" | |
echo "COVERAGE=$coverage_percentage" >> "$GITHUB_ENV" | |
- name: Check coverage | |
shell: bash | |
run: | | |
if [[ ! "$COVERAGE" =~ ^[0-9]+$ ]]; then | |
echo "Error: Invalid coverage value: ${COVERAGE}" | |
elif [ "$COVERAGE" -lt 90 ]; then | |
echo "Test coverage is below 90%. Current coverage: ${COVERAGE}%" | |
else | |
echo "Test coverage is above or equal to 90%. Current coverage: $COVERAGE%" | |
fi | |
- name: Pytest coverage comment | |
id: coverageComment | |
uses: MishaKav/pytest-coverage-comment@v1.1.53 | |
with: | |
pytest-coverage-path: ./pytest-coverage.txt | |
pytest-xml-coverage-path: ./coverage.xml | |
title: Coverage Report (${{ matrix.os }} / Python ${{ matrix.python-version }}) | |
badge-title: coverage | |
hide-badge: false | |
hide-report: false | |
create-new-comment: true | |
hide-comment: false | |
report-only-changed-files: false | |
remove-link-from-badge: false | |
junitxml-path: ./pytest.xml | |
junitxml-title: "Pytest Result Summary (os: ${{ matrix.os }} / python-version: ${{ matrix.python-version }})" | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Check test results | |
if: steps.pytest.outcome == 'failure' | |
run: | | |
echo "Tests failed. This will be reported in the workflow summary." | |
echo "::warning::Tests failed on ${{ matrix.os }} with Python ${{ matrix.python-version }}" | |
- name: Write job summary | |
id: check_status | |
shell: bash | |
run: | | |
echo -e ${{ steps.coverageComment.outputs.summaryReport }} >> "$GITHUB_STEP_SUMMARY" | |
check_all_tests: | |
needs: [set_variables, run_tests] | |
#runs-on: ubuntu-latest | |
runs-on: ${{ fromJson(needs.set_variables.outputs.os)[0] }} | |
steps: | |
- name: Check test results | |
if: contains(needs.run_tests.result, 'failure') | |
run: | | |
echo "Some tests failed. Please check the test results and fix any issues before merging." | |
exit 1 | |
send_notification: | |
needs: [set_variables, run_tests, check_all_tests] | |
#runs-on: ubuntu-latest | |
runs-on: ${{ fromJson(needs.set_variables.outputs.os)[0] }} | |
steps: | |
# https://docs.github.com/ja/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-an-environment | |
- name: Send LINE Notify | |
env: | |
LINE_NOTIFY_TOKEN: ${{ secrets.LINE_NOTIFY_TOKEN }} | |
run: | | |
status="${{ contains(needs.run_tests.result, 'failure') && 'FAILED' || 'SUCCESS' }}" | |
message="'dependabot_prch' workflow completed with status: $status | |
Check URL: | |
https://github.com/7rikazhexde/json2vars-setter/actions/workflows/dependabot_prch.yml" | |
curl -X POST https://notify-api.line.me/api/notify \ | |
-H "Authorization: Bearer $LINE_NOTIFY_TOKEN" \ | |
-F "message=${message}" |