Skip to content

Commit

Permalink
Merge pull request #24 from 7rikazhexde/dev24-11-6
Browse files Browse the repository at this point in the history
👷Add python test workflow
  • Loading branch information
7rikazhexde authored Nov 5, 2024
2 parents 2544dc5 + 45196db commit 23e359c
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 5 deletions.
113 changes: 113 additions & 0 deletions .github/workflows/python_test.yml
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}"
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# JSON to Variables Setter

[![GitHub Marketplace](https://img.shields.io/badge/Marketplace-JSON%20to%20Variables%20Setter-green?colorA=24292e&colorB=3fb950&logo=github)](https://github.com/marketplace/actions/json-to-variables-setter)

## Overview

**JSON to Variables Setter (json2vars-setter)** is a GitHub Action designed to parse a JSON file and set the resulting variables (such as operating systems, programming language versions, and GitHub Pages branch) as outputs in a GitHub Actions workflow.

## Supported GitHub Actions Matrix Components

[![Python](https://img.shields.io/badge/Python-3776AB?style=for-the-badge&logo=python&logoColor=white)](#example-workflow)
[![Node.js](https://img.shields.io/badge/Node.js-339933?style=for-the-badge&logo=node.js&logoColor=white)](.github/workflows/nodejs_test.yml)
[![Ruby](https://img.shields.io/badge/Ruby-CC342D?style=for-the-badge&logo=ruby&logoColor=white)](.github/workflows/ruby_test.yml)
[![Go](https://img.shields.io/badge/Go-00ADD8?style=for-the-badge&logo=go&logoColor=white)](.github/workflows/go_test.yml)
[![Rust](https://img.shields.io/badge/Rust-000000?style=for-the-badge&logo=rust&logoColor=white)](.github/workflows/rust_test.yml)
| Languages | Test Status |
|-------|-------|
| [![Python](https://img.shields.io/badge/Python-3776AB?style=flat&logo=python&logoColor=white)](.github/workflows/python_test.yml) | [![Python Test](https://github.com/7rikazhexde/json2vars-setter/actions/workflows/python_test.yml/badge.svg)](https://github.com/7rikazhexde/json2vars-setter/actions/workflows/python_test.yml) |
| [![Node.js](https://img.shields.io/badge/Node.js-339933?style=flat&logo=node.js&logoColor=white)](.github/workflows/nodejs_test.yml) | [![Node.js Test](https://github.com/7rikazhexde/json2vars-setter/actions/workflows/nodejs_test.yml/badge.svg)](https://github.com/7rikazhexde/json2vars-setter/actions/workflows/nodejs_test.yml) |
| [![Ruby](https://img.shields.io/badge/Ruby-CC342D?style=flat&logo=ruby&logoColor=white)](.github/workflows/ruby_test.yml) | [![Ruby Test](https://github.com/7rikazhexde/json2vars-setter/actions/workflows/ruby_test.yml/badge.svg)](https://github.com/7rikazhexde/json2vars-setter/actions/workflows/ruby_test.yml) |
| [![Go](https://img.shields.io/badge/Go-00ADD8?style=flat&logo=go&logoColor=white)](.github/workflows/go_test.yml) | [![Go Test](https://github.com/7rikazhexde/json2vars-setter/actions/workflows/go_test.yml/badge.svg)](https://github.com/7rikazhexde/json2vars-setter/actions/workflows/go_test.yml) |
| [![Rust](https://img.shields.io/badge/Rust-000000?style=flat&logo=rust&logoColor=white)](.github/workflows/rust_test.yml) | [![Rust Test](https://github.com/7rikazhexde/json2vars-setter/actions/workflows/rust_test.yml/badge.svg)](https://github.com/7rikazhexde/json2vars-setter/actions/workflows/rust_test.yml) |

## Table of contents

Expand Down

0 comments on commit 23e359c

Please sign in to comment.