Skip to content

Commit

Permalink
update workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
LeiShi1313 committed Nov 25, 2023
1 parent c688e1e commit aaf054e
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 25 deletions.
37 changes: 13 additions & 24 deletions .github/workflows/release-gcsim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -71,30 +74,16 @@ 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 <me@leishi.io>']
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

# 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 }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
gcsim/
gcsim_pypi/bin/*
gcsim_pypi/*.json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
gcsim binary build from [gcsim](https://github.com/genshinsim/gcsim)
[gcsim](https://github.com/genshinsim/gcsim) binary for pypi
49 changes: 49 additions & 0 deletions gcsim_pypi/scripts.py
Original file line number Diff line number Diff line change
@@ -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,
)
8 changes: 8 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[tool.poetry]
name = "gcsim-pypi"
version = "0.0.0"
description = "gcsim binary for pypi"
authors = ["Lei Shi <me@leishi.io>"]
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"
Empty file removed tests/__init__.py
Empty file.

0 comments on commit aaf054e

Please sign in to comment.