Fundamentals docs (#81) #526
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
| # GitHub Actions configuration **EXAMPLE**, | |
| # MODIFY IT ACCORDING TO YOUR NEEDS! | |
| # Reference: https://docs.github.com/en/actions | |
| name: tests | |
| on: | |
| push: | |
| # Avoid using all the resources/limits available by checking only | |
| # relevant branches and tags. Other branches can be checked via PRs. | |
| branches: [main] | |
| tags: ['v[0-9]*', '[0-9]+.[0-9]+*'] # Match tags that resemble a version | |
| pull_request: | |
| types: [opened, synchronize, reopened, labeled, unlabeled] | |
| workflow_dispatch: # Allow manually triggering the workflow | |
| permissions: | |
| id-token: write | |
| contents: write | |
| pull-requests: write | |
| concurrency: | |
| group: >- | |
| ${{ github.workflow }}-${{ github.ref_type }}- | |
| ${{ github.event.pull_request.number || github.sha }} | |
| cancel-in-progress: true | |
| jobs: | |
| prepare: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| wheel-distribution: ${{ steps.wheel-distribution.outputs.path }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: {fetch-depth: 0} # deep clone for setuptools-scm | |
| - uses: actions/setup-python@v5 | |
| id: setup-python | |
| with: {python-version: "3.11"} | |
| - name: Run static analysis and format checkers | |
| run: pipx run pre-commit run --all-files --show-diff-on-failure | |
| - name: Build package distribution files | |
| run: >- | |
| pipx run --python '${{ steps.setup-python.outputs.python-path }}' | |
| tox -e clean,build | |
| - name: Record the path of wheel distribution | |
| id: wheel-distribution | |
| run: echo "path=$(ls dist/*.whl)" >> $GITHUB_OUTPUT | |
| - name: Store the distribution files for use in other stages | |
| # `tests` and `publish` will use the same pre-built distributions, | |
| # so we make sure to release the exact same package that was tested | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: python-distribution-files | |
| path: dist/ | |
| retention-days: 1 | |
| test: | |
| needs: prepare | |
| strategy: | |
| matrix: | |
| python: | |
| - "3.9" # oldest Python supported by PSF | |
| - "3.11" # newest Python that is stable | |
| platform: | |
| - ubuntu-latest | |
| - macos-15 | |
| - windows-latest | |
| runs-on: ${{ matrix.platform }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| id: setup-python | |
| with: | |
| python-version: ${{ matrix.python }} | |
| - name: Retrieve pre-built distribution files | |
| uses: actions/download-artifact@v4 | |
| with: {name: python-distribution-files, path: dist/} | |
| - name: Run tests | |
| run: >- | |
| pipx run --python '${{ steps.setup-python.outputs.python-path }}' | |
| tox --installpkg '${{ needs.prepare.outputs.wheel-distribution }}' | |
| -- -rFEx --durations 10 --color yes # pytest args | |
| - name: Generate coverage report | |
| run: pipx run coverage lcov -o coverage.lcov | |
| # - name: Upload partial coverage report | |
| # uses: coverallsapp/github-action@main | |
| # if: ${{ matrix.platform != 'macos-12' }} | |
| # with: | |
| # path-to-lcov: coverage.lcov | |
| # github-token: ${{ secrets.GITHUB_TOKEN }} | |
| # flag-name: ${{ matrix.platform }} - py${{ matrix.python }} | |
| # parallel: true | |
| - name: Save coverage report | |
| if: ${{ matrix.platform == 'ubuntu-latest' && matrix.python == '3.11' }} | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage | |
| path: htmlcov | |
| finalize: | |
| needs: test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - run: |- | |
| echo "Mock" | |
| # - name: Finalize coverage report | |
| # uses: coverallsapp/github-action@main | |
| # with: | |
| # github-token: ${{ secrets.GITHUB_TOKEN }} | |
| # parallel-finished: true | |
| benchmark: | |
| needs: finalize | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/create-github-app-token@v1 | |
| id: github-app-checkout | |
| with: | |
| app-id: ${{ secrets.BOT_GITHUB_APP_ID }} | |
| private-key: ${{ secrets.BOT_GITHUB_APP_PRIVATE_KEY }} | |
| owner: ${{ github.repository_owner }} | |
| repositories: | | |
| foapy-asv-results | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/checkout@v4 | |
| with: | |
| repository: intervals-mining-lab/foapy-asv-results | |
| path: benchmarks/results | |
| ref: main | |
| token: ${{ steps.github-app-checkout.outputs.token }} | |
| persist-credentials: false | |
| - uses: actions/setup-python@v5 | |
| id: setup-python | |
| with: {python-version: "3.11"} | |
| - name: Install ASV | |
| run: |- | |
| pipx install --python '${{ steps.setup-python.outputs.python-path }}' asv virtualenv build | |
| - name: Context | |
| id: context | |
| uses: cloudposse/github-action-yaml-config-query@v1 | |
| with: | |
| query: ."${{ github.event_name }}" | |
| config: |- | |
| push: | |
| branch: ${{ github.ref_name }} | |
| head: ${{ github.sha }} | |
| base: HEAD~1 | |
| pull_request: | |
| branch: ${{ github.event.pull_request.head.ref }} | |
| head: ${{ github.event.pull_request.head.sha }} | |
| base: ${{ github.event.pull_request.base.sha }} | |
| - name: Checkout benchmark results | |
| run: |- | |
| cd ./benchmarks/results | |
| git pull | |
| git checkout ${{ steps.context.outputs.branch }} || true | |
| git checkout -b ${{ steps.context.outputs.branch }} --track origin/${{ steps.context.outputs.branch }} || true | |
| - name: Run benchmark | |
| id: benchmark | |
| if: false | |
| env: | |
| QUICK_BENCHMARK: ${{ ! contains( github.event.pull_request.labels.*.name, 'benchmark') }} | |
| run: |- | |
| cd ./benchmarks | |
| asv machine --machine gh-runner --yes || true | |
| asv setup -v || true | |
| asv run ALL --skip-existing --append-samples --machine gh-runner || true | |
| asv publish | |
| REPORT=$(asv compare --machine gh-runner ${{ steps.context.outputs.base }} HEAD --split --only-changed) | |
| echo "${REPORT}" >> $GITHUB_STEP_SUMMARY | |
| REPORT="${REPORT}" | |
| echo 'REPORT_RESULT<<EOF' >> $GITHUB_ENV | |
| echo "${REPORT}" >> $GITHUB_ENV | |
| echo 'EOF' >> $GITHUB_ENV | |
| cd ./results | |
| git pull | |
| git config user.email "ci-bot@example.com" | |
| git config user.name "ci-bot" | |
| git add . | |
| git commit -m "Update benchmark results" || true | |
| - uses: actions/create-github-app-token@v1 | |
| id: github-app-push | |
| with: | |
| app-id: ${{ secrets.BOT_GITHUB_APP_ID }} | |
| private-key: ${{ secrets.BOT_GITHUB_APP_PRIVATE_KEY }} | |
| owner: ${{ github.repository_owner }} | |
| repositories: | | |
| foapy-asv-results | |
| - name: Push changes | |
| uses: ad-m/github-push-action@master | |
| with: | |
| github_token: ${{ steps.github-app-push.outputs.token }} | |
| repository: intervals-mining-lab/foapy-asv-results | |
| branch: ${{ steps.context.outputs.branch }} | |
| directory: benchmarks/results | |
| - uses: mshick/add-pr-comment@v2 | |
| if: ${{ env.REPORT_RESULT != '' }} | |
| with: | |
| message: |- | |
| ${{ env.REPORT_RESULT }} | |
| - name: Save benchmark report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: benchmark | |
| path: benchmarks/html | |
| docs: | |
| needs: benchmark | |
| runs-on: ubuntu-latest | |
| env: | |
| GIT_COMMITTER_NAME: ci-bot | |
| GIT_COMMITTER_EMAIL: ci-bot@example.com | |
| steps: | |
| - name: Context | |
| id: context | |
| uses: cloudposse/github-action-yaml-config-query@v1 | |
| with: | |
| query: ."${{ github.event_name }}" | |
| config: |- | |
| push: | |
| branch: ${{ github.ref_name }} | |
| pull_request: | |
| branch: ${{ github.event.pull_request.head.ref }} | |
| - uses: actions/checkout@v4 | |
| with: {fetch-depth: 0} # deep clone for setuptools-scm | |
| - uses: actions/setup-python@v5 | |
| id: setup-python | |
| with: {python-version: "3.11"} | |
| - name: Retrieve coverage report | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: coverage | |
| path: htmlcov | |
| - name: Retrieve benchmark report | |
| if: false | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: benchmark | |
| path: benchmarks/html | |
| - name: Setup Pages | |
| uses: actions/configure-pages@v5 | |
| - name: Build package distribution files | |
| run: | | |
| pipx run --python '${{ steps.setup-python.outputs.python-path }}' tox -e docs | |
| pipx run --python '${{ steps.setup-python.outputs.python-path }}' tox -e docs-deploy -- ${{ steps.context.outputs.branch }} | |
| - name: Set default documentation branch | |
| if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }} | |
| run: | | |
| pipx run --python '${{ steps.setup-python.outputs.python-path }}' tox -e docs-default -- ${{ steps.context.outputs.branch }} | |
| publish: | |
| needs: finalize | |
| if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }} | |
| runs-on: ubuntu-latest | |
| environment: release | |
| permissions: | |
| id-token: write | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: {python-version: "3.11"} | |
| - name: Retrieve pre-built distribution files | |
| uses: actions/download-artifact@v4 | |
| with: {name: python-distribution-files, path: dist/} | |
| - name: Publish package distributions to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 |