Adapt release workflow to also act as a test suite (#18)
This commit is contained in:
parent
1429b8f466
commit
e528f48e1d
@ -1,4 +1,4 @@
|
||||
name: "Create release"
|
||||
name: "Test and publish release"
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
@ -6,34 +6,51 @@ on:
|
||||
release_version:
|
||||
description: 'Release version number'
|
||||
required: true
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- '*'
|
||||
|
||||
env:
|
||||
PY_COLORS: "1"
|
||||
|
||||
jobs:
|
||||
create-release:
|
||||
test-and-publish-release:
|
||||
runs-on: windows-2019
|
||||
# Only create the release if workflow is run manually. (This allows the other steps in the workflow to test PRs.)
|
||||
if: github.event_name == 'workflow_dispatch'
|
||||
steps:
|
||||
# The GitHub Actions bot email was taken from: https://github.community/t/github-actions-bot-email-address/17204/6
|
||||
- name: Set bot user data for commits
|
||||
run: |
|
||||
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||
git config --global user.name "GitHub Actions Bot"
|
||||
|
||||
- name: Checkout tja2fumen (main branch)
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
ref: ${{ env.MAIN_BRANCH }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.8.x'
|
||||
|
||||
- name: Install dependencies
|
||||
- name: Install test dependencies
|
||||
run: |
|
||||
pip install pytest
|
||||
pip install -e .
|
||||
|
||||
- name: Run tests (Python API)
|
||||
run: |
|
||||
pytest testing --entry-point python-api
|
||||
|
||||
- name: Install build dependencies
|
||||
run: pip install toml-cli build twine pyinstaller
|
||||
|
||||
# The GitHub Actions bot email was taken from: https://github.community/t/github-actions-bot-email-address/17204/6
|
||||
- name: Set bot user data for commits
|
||||
# Only set git user data if workflow is run manually. (This allows the other steps in the workflow to test PRs.)
|
||||
if: github.event_name == 'workflow_dispatch'
|
||||
run: |
|
||||
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||
git config --global user.name "GitHub Actions Bot"
|
||||
|
||||
- name: Update pyproject.toml version (for release)
|
||||
# Only update the version number if workflow is run manually. (This allows the other steps in the workflow to test PRs.)
|
||||
if: github.event_name == 'workflow_dispatch'
|
||||
run: |
|
||||
toml set --toml-path pyproject.toml project.version "${{ github.event.inputs.release_version }}"
|
||||
git add pyproject.toml
|
||||
@ -42,16 +59,32 @@ jobs:
|
||||
- name: Build wheel/sdist
|
||||
run: python -m build
|
||||
|
||||
- name: Uninstall editable tja2fumen and install built wheel
|
||||
shell: bash
|
||||
run: |
|
||||
pip uninstall tja2fumen -y
|
||||
pip install dist/*.whl
|
||||
|
||||
- name: Run tests (installed wheel)
|
||||
run: pytest testing --entry-point python-cli
|
||||
|
||||
- name: Build pyinstaller executable
|
||||
run: |
|
||||
pyinstaller src\tja2fumen\__init__.py --name tja2fumen-${{ github.event.inputs.release_version }} --add-data="src\tja2fumen\soulgauge_LUTs\*.csv;tja2fumen\soulgauge_LUTs" --onefile
|
||||
|
||||
- name: Run tests (installed wheel)
|
||||
run: pytest testing --entry-point exe
|
||||
|
||||
- name: Push release changes
|
||||
# Only push the new tags if workflow is run manually. (This allows the other steps in the workflow to test PRs.)
|
||||
if: github.event_name == 'workflow_dispatch'
|
||||
run: |
|
||||
git tag ${{ github.event.inputs.release_version }}
|
||||
git push --tags
|
||||
|
||||
- uses: ncipollo/release-action@v1
|
||||
# Only create release if workflow is run manually. (This allows the other steps in the workflow to test PRs.)
|
||||
if: github.event_name == 'workflow_dispatch'
|
||||
name: Create release
|
||||
id: create_release
|
||||
with:
|
||||
@ -63,4 +96,6 @@ jobs:
|
||||
draft: true
|
||||
|
||||
- name: Publish distribution to PyPI
|
||||
# Only publish distribution if workflow is run manually. (This allows the other steps in the workflow to test PRs.)
|
||||
if: github.event_name == 'workflow_dispatch'
|
||||
run: twine upload dist/*.whl dist/*.tar.gz --username __token__ --password ${{ secrets.PYPI_API_TOKEN }}
|
@ -21,4 +21,8 @@ tja2fumen = "tja2fumen:main"
|
||||
build = ["pyinstaller"]
|
||||
|
||||
[tool.setuptools.packages.find]
|
||||
where = ["src"]
|
||||
where = ["src"]
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
addopts = "-v --tb=short"
|
||||
console_output_style = "count"
|
11
testing/conftest.py
Normal file
11
testing/conftest.py
Normal file
@ -0,0 +1,11 @@
|
||||
import pytest
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption("--entry-point", action="store", default="python-api")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def entry_point(request):
|
||||
return request.config.getoption("--entry-point")
|
||||
|
@ -2,6 +2,7 @@ import os
|
||||
import shutil
|
||||
import zipfile
|
||||
import re
|
||||
import glob
|
||||
|
||||
import pytest
|
||||
|
||||
@ -30,7 +31,7 @@ def assert_song_property(obj1, obj2, prop, measure=None, branch=None, note=None,
|
||||
|
||||
|
||||
@pytest.mark.parametrize('id_song', ['mikdp'])
|
||||
def test_converted_tja_vs_cached_fumen(id_song, tmp_path):
|
||||
def test_converted_tja_vs_cached_fumen(id_song, tmp_path, entry_point):
|
||||
# Define the testing directory
|
||||
path_test = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
@ -44,7 +45,17 @@ def test_converted_tja_vs_cached_fumen(id_song, tmp_path):
|
||||
shutil.copy(path_tja, path_tja_tmp)
|
||||
|
||||
# Convert TJA file to fumen files
|
||||
_, _, paths_out = convert(argv=[path_tja_tmp])
|
||||
if entry_point == "python-api":
|
||||
convert(argv=[path_tja_tmp])
|
||||
elif entry_point == "python-cli":
|
||||
os.system(f"tja2fumen {path_tja_tmp}")
|
||||
elif entry_point == "exe":
|
||||
exe_path = glob.glob(os.path.join(os.path.split(path_test)[0], "dist", "*.exe"))[0]
|
||||
os.system(f"{exe_path} {path_tja_tmp}")
|
||||
|
||||
# Fetch output fumen paths
|
||||
paths_out = glob.glob(os.path.join(path_temp, "*.bin"))
|
||||
assert paths_out, f"No bin files generated in {path_temp}"
|
||||
|
||||
# Extract cached fumen files to working directory
|
||||
path_binzip = os.path.join(path_test, "data", f"{id_song}.zip")
|
||||
|
Loading…
x
Reference in New Issue
Block a user