diff --git a/.github/workflows/release-gcsim.yml b/.github/workflows/release-gcsim.yml index 146e085..0a3ea7c 100644 --- a/.github/workflows/release-gcsim.yml +++ b/.github/workflows/release-gcsim.yml @@ -3,13 +3,16 @@ name: Build gcsim and Release to PyPI on: schedule: - cron: "0 0 * * 0" + release: + types: [published] workflow_dispatch: jobs: check: runs-on: ubuntu-latest outputs: - tag: ${{ steps.gcsim-latest-tag.outputs.release }} + version: ${{ github.event.release.tag_name || steps.get-latest-tag.outputs.tag }} + gcsim-version: ${{ steps.gcsim-latest-tag.outputs.release }} version-exists: ${{ steps.check-pypi-version.outputs.exists }} steps: # Fetch the latest release tag from gcsim @@ -22,8 +25,8 @@ jobs: - name: Check if Version Exists on PyPI id: check-pypi-version run: | - VERSION_EXISTS=$(curl -s https://pypi.org/pypi/gcsim_pypi/json | jq -r '.releases | has("${{ steps.get-latest-tag.outputs.tag }}")') - echo "::set-output name=exists::$VERSION_EXISTS" + VERSION_EXISTS=$(curl -s https://pypi.org/pypi/gcsim_pypi/json | jq -r '.releases | has("${{ github.event.release.tag_name || steps.get-latest-tag.outputs.tag }}")') + echo "{exists}={$VERSION_EXISTS}" >> $GITHUB_OUTPUT build-and-release: runs-on: ubuntu-latest @@ -33,14 +36,14 @@ jobs: steps: # Checkout your repository - name: Checkout Repo - uses: actions/checkout@v2 + uses: actions/checkout@v4 # Clone the other repository - name: Checkout gcsim - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: repository: 'genshinsim/gcsim' - ref: ${{ needs.check.outputs.tag }} + ref: ${{ needs.check.outputs.gcsim-version }} path: 'gcsim' # Set up Go environment @@ -71,24 +74,8 @@ jobs: - name: Install Poetry run: pip install poetry - - name: Create pyproject.toml - run: | - cat << EOF > pyproject.toml - [tool.poetry] - name = 'gcsim-pypi' - version = '${{ needs.check.outputs.tag }}' - description = 'gcsim binary for PyPI' - readme = 'README.md' - authors = ['Lei Shi '] - packages = [{include = 'gcsim_pypi'}] - - [tool.poetry.dependencies] - python = '^3.6' - - [build-system] - requires = ['poetry-core'] - build-backend = 'poetry.core.masonry.api' - EOF + - name: Generate available characters/artifacts/weapons + run: poetry run python gcsim_pypi/scripts.py - name: Add git safe directory run: git config --global --add safe.directory /github/workspace @@ -96,5 +83,7 @@ jobs: # Upload to PyPI - name: Build and publish to pypi uses: JRubics/poetry-publish@v1.17 + env: + POETRY_DYNAMIC_VERSIONING_BYPASS: ${{ needs.check.outputs.version }} with: pypi_token: ${{ secrets.PYPI_API_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d352e0d --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +dist/ +gcsim/ +gcsim_pypi/bin/* +gcsim_pypi/*.json \ No newline at end of file diff --git a/README.md b/README.md index 12ef328..e29ffc9 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -gcsim binary build from [gcsim](https://github.com/genshinsim/gcsim) \ No newline at end of file +[gcsim](https://github.com/genshinsim/gcsim) binary for pypi \ No newline at end of file diff --git a/gcsim_pypi/scripts.py b/gcsim_pypi/scripts.py new file mode 100644 index 0000000..8de1447 --- /dev/null +++ b/gcsim_pypi/scripts.py @@ -0,0 +1,49 @@ +import json +from pathlib import Path + +with open(Path(__file__).parent.joinpath("available_characters.json"), "w") as f: + json.dump( + [ + f.stem + for f in ( + Path(__file__) + .parent.parent.joinpath("gcsim") + .joinpath("internal") + .joinpath("characters") + ).iterdir() + if f.is_dir() + ], + f, + ) + +with open(Path(__file__).parent.joinpath("available_artifacts.json"), "w") as f: + json.dump( + [ + f.stem + for f in ( + Path(__file__) + .parent.parent.joinpath("gcsim") + .joinpath("internal") + .joinpath("artifacts") + ).iterdir() + if f.is_dir() + ], + f, + ) + +with open(Path(__file__).parent.joinpath("available_weapons.json"), "w") as f: + json.dump( + [ + ff.stem + for f in ( + Path(__file__) + .parent.parent.joinpath("gcsim") + .joinpath("internal") + .joinpath("weapons") + ).iterdir() + if f.is_dir() + and f.stem in ("sword", "claymore", "spear", "catalyst", "bow") + for ff in f.iterdir() + ], + f, + ) diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..10a1741 --- /dev/null +++ b/poetry.lock @@ -0,0 +1,8 @@ +package = [] + +[metadata] +lock-version = "1.1" +python-versions = "^3.6" +content-hash = "de7600acb56ad9a67b77fd08bb5acd96ae59d0bbc6d538e5682444b7d4b1cc16" + +[metadata.files] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..8ecc6db --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,22 @@ +[tool.poetry] +name = "gcsim-pypi" +version = "0.0.0" +description = "gcsim binary for pypi" +authors = ["Lei Shi "] +license = "MIT" +readme = "README.md" +packages = [{include = "gcsim_pypi"}] +include = [ + { path = "gcsim_pypi/bin/*", format = ["sdist", "wheel"] }, + { path = "gcsim_pypi/*.json", format = ["sdist", "wheel"] } +] + +[tool.poetry.dependencies] +python = "^3.6" + +[tool.poetry-dynamic-versioning] +enable = true + +[build-system] +requires = ["poetry-core", "poetry-dynamic-versioning>=1.0.0,<2.0.0"] +build-backend = "poetry_dynamic_versioning.backend" diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29..0000000