Improved hooks and small fixes. #31
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Check, Build and Publish Package | |
| on: push | |
| jobs: | |
| check-and-build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.10" | |
| - name: Install Poetry | |
| uses: abatilo/actions-poetry@v4 | |
| with: | |
| poetry-version: "latest" | |
| - name: Setup a local virtual environment | |
| run: | | |
| export PATH="~/.local/bin:$PATH" | |
| poetry config virtualenvs.create true --local | |
| poetry config virtualenvs.in-project true --local | |
| - uses: actions/cache@v3 | |
| name: Define a cache for poetry | |
| with: | |
| path: ./.venv | |
| key: venv-${{ hashFiles('poetry.lock') }} | |
| - name: Install the project dependencies | |
| run: | | |
| export PATH="~/.local/bin:$PATH" | |
| poetry install | |
| - name: Activate Virtual Env | |
| run: | | |
| export PATH="~/.local/bin:$PATH" | |
| poetry env activate | |
| - name: Run MyPy | |
| run: | | |
| export PATH="~/.local/bin:$PATH" | |
| poetry run mypy . --strict | |
| - name: Run the Formatter checks | |
| run: | | |
| export PATH="~/.local/bin:$PATH" | |
| poetry run black . --check | |
| - name: Run the Tests | |
| run: | | |
| export PATH="~/.local/bin:$PATH" | |
| poetry run pytest . -v | |
| - name: Check Package | |
| run: | | |
| export PATH="~/.local/bin:$PATH" | |
| poetry check | |
| - name: Build Package | |
| run: | | |
| export PATH="~/.local/bin:$PATH" | |
| poetry build | |
| - name: Upload the Package Build as Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: FFLib | |
| path: ./dist | |
| test-examples: | |
| needs: check-and-build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.10" | |
| - name: Install Poetry | |
| uses: abatilo/actions-poetry@v4 | |
| with: | |
| poetry-version: "latest" | |
| - name: Setup a local virtual environment | |
| run: | | |
| export PATH="~/.local/bin:$PATH" | |
| poetry config virtualenvs.create true --local | |
| poetry config virtualenvs.in-project true --local | |
| - uses: actions/cache/restore@v4 | |
| name: Restore the cache for poetry | |
| with: | |
| path: ./.venv | |
| key: venv-${{ hashFiles('poetry.lock') }} | |
| - name: Activate Virtual Env | |
| run: | | |
| export PATH="~/.local/bin:$PATH" | |
| poetry env activate | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: FFLib | |
| path: ./dist | |
| - name: Install FFLib | |
| run: | | |
| export PATH="~/.local/bin:$PATH" | |
| whl_file=$(ls ./dist/fflib-*.whl) | |
| poetry run pip install "$whl_file" | |
| - name: Test Minimal Examples | |
| run: | | |
| set -e | |
| export PATH="~/.local/bin:$PATH" | |
| mkdir ./models | |
| # Run the examples | |
| poetry run python ./examples/ff_net_mnist.py -e 1 -u 0.01 | |
| poetry run python ./examples/ff_c_mnist.py -e 1 -u 0.01 | |
| poetry run python ./examples/ff_rnn_mnist.py -e 1 -u 0.01 | |
| poetry run python ./examples/bp_mnist.py -e 1 -u 0.01 | |
| publish: | |
| needs: check-and-build | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write # 🚀 Grants permission to push tags | |
| if: startsWith(github.ref, 'refs/tags/v') # Ensure it only runs on version tags | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.10" | |
| - name: Install Twine | |
| run: python -m pip install --upgrade twine | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: FFLib | |
| path: ./dist | |
| - name: Publish package to PyPI | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
| run: twine upload dist/* | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ github.ref_name }} | |
| name: Release ${{ github.ref_name }} | |
| body: "New release of the FFLib! 📦🚀" | |
| draft: false | |
| prerelease: false | |
| files: dist/* | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |