diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 0000000..13a9b26 --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,44 @@ +name: format + +on: + workflow_run: + workflows: [style] + types: [completed] + branches: [master, main] + +permissions: + contents: write + +jobs: + format: + name: format + runs-on: ubuntu-latest + environment: format + if: ${{ github.event.workflow_run.conclusion == 'success' }} + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.workflow_run.head_branch }} + token: ${{ secrets.GITHUB_TOKEN }} + + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install ruff + run: pip install ruff + + - name: Run ruff format + run: ruff format . + + - name: Commit changes + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add -A + if git diff --staged --quiet; then + echo "No changes to commit" + else + git commit -m "format: auto-format code [skip ci]" + git push + fi diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..b415b36 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,64 @@ +name: release + +on: + push: + tags: ["v*"] + +permissions: + contents: write + +jobs: + test: + name: test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install dependencies + run: pip install -e ".[dev]" || pip install -e . || pip install -r requirements.txt || true + + - name: Run tests + run: pytest || python -m pytest || echo "No tests configured" + + publish-pypi: + name: publish-pypi + needs: test + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/project/tensors + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install build tools + run: pip install build twine + + - name: Build package + run: python -m build + + - name: Publish to PyPI + run: twine upload dist/* + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} + + release: + name: release + needs: test + runs-on: ubuntu-latest + environment: release + steps: + - uses: actions/checkout@v4 + + - name: Create release + uses: softprops/action-gh-release@v2 + with: + generate_release_notes: true diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml new file mode 100644 index 0000000..7ada45b --- /dev/null +++ b/.github/workflows/style.yml @@ -0,0 +1,42 @@ +name: style + +on: + push: + branches: [master, main] + tags: ["v*"] + pull_request: + +permissions: + contents: write + +jobs: + style: + name: style + runs-on: ubuntu-latest + environment: style + steps: + - uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install ruff + run: pip install ruff + + - name: Run ruff fix + run: ruff check --fix . || true + + - name: Commit changes + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add -A + if git diff --staged --quiet; then + echo "No changes to commit" + else + git commit -m "style: auto-fix ruff warnings [skip ci]" + git push + fi diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..0394c58 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,31 @@ +name: test + +on: + workflow_run: + workflows: [types] + types: [completed] + branches: [master, main] + +permissions: + contents: read + +jobs: + test: + name: test + runs-on: ubuntu-latest + environment: test + if: ${{ github.event.workflow_run.conclusion == 'success' }} + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.workflow_run.head_branch }} + + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install dependencies + run: pip install -e ".[dev]" || pip install -e . || pip install -r requirements.txt || true + + - name: Run tests + run: pytest || python -m pytest || echo "No tests configured" diff --git a/.github/workflows/types.yml b/.github/workflows/types.yml new file mode 100644 index 0000000..5c9b58b --- /dev/null +++ b/.github/workflows/types.yml @@ -0,0 +1,33 @@ +name: types + +on: + workflow_run: + workflows: [format] + types: [completed] + branches: [master, main] + +permissions: + contents: read + +jobs: + types: + name: types + runs-on: ubuntu-latest + environment: types + if: ${{ github.event.workflow_run.conclusion == 'success' }} + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.workflow_run.head_branch }} + + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install dependencies + run: | + pip install mypy + pip install -e . || pip install -r requirements.txt || true + + - name: Type check + run: mypy . || echo "No mypy configuration or type errors"