Skip to content

Workflow file for this run

name: Build gcsim and Release to PyPI
on:
release:
types: [published]
workflow_dispatch:
jobs:
check:
runs-on: ubuntu-latest
outputs:
version: ${{ github.event.release.tag_name || steps.gcsim-latest-tag.outputs.release }}
gcsim-version: ${{ steps.gcsim-latest-tag.outputs.release }}
version-exists: ${{ steps.check-pypi-version.outputs.exists }}
steps:
# Fetch the latest release tag from gcsim
- id: gcsim-latest-tag
uses: pozetroninc/github-action-get-latest-release@master
with:
repository: 'genshinsim/gcsim'
# Check if version already exists on PyPI
- 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("${{ github.event.release.tag_name || steps.gcsim-latest-tag.outputs.release }}")')
echo "exists=$VERSION_EXISTS" >> $GITHUB_OUTPUT
build-and-release:
runs-on: ubuntu-latest
needs: check
if: needs.check.outputs.version-exists == 'false'
steps:
# Checkout your repository
- name: Checkout Repo
uses: actions/checkout@v4
# Clone the other repository
- name: Checkout gcsim
uses: actions/checkout@v4
with:
repository: 'genshinsim/gcsim'
ref: ${{ needs.check.outputs.gcsim-version }}
path: 'gcsim'
# Set up Go environment
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "^1.19.3"
# Build your Go project
- name: Build Go Project
run: |
pushd gcsim/cmd/gcsim
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o gcsim
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -o gcsim.arm64
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -o gcsim.darwin
GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -o gcsim.darwin.arm64
GOOS=windows GOARCH=amd64 go build -o gcsim.exe
popd
# Package the binary in a Python package structure
- name: Package Binary
run: |
mkdir -p gcsim_pypi/bin
cp gcsim/cmd/gcsim/gcsim gcsim_pypi/bin/
cp gcsim/cmd/gcsim/gcsim* gcsim_pypi/bin/
# Set up Python and dependencies for PyPI upload
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '^3.10'
- name: Install Poetry
run: pip install poetry
- name: Generate available characters/artifacts/weapons
run: poetry run python scripts.py
- name: Add git safe directory
run: git config --global --add safe.directory /github/workspace
- name: Update version
run: sed -i 's/^version = .*/version = "'"${{ needs.check.outputs.version }}"'"/' pyproject.toml
# Upload to PyPI
- name: Build and publish to pypi
uses: JRubics/[email protected]
env:
POETRY_DYNAMIC_VERSIONING_BYPASS: ${{ needs.check.outputs.version }}
with:
pypi_token: ${{ secrets.PYPI_API_TOKEN }}