👷 Run all tests only on PR, 1 otherwise #44
This file contains 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
# This workflow will install Python dependencies, run tests and lint with a single version of Python | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python | |
name: "CI & CD" | |
on: | |
push: | |
branches: [ "master", "development" ] | |
pull_request: | |
branches: [ "master", "development" ] | |
permissions: | |
contents: write | |
id-token: write | |
jobs: | |
setup: | |
runs-on: ubuntu-latest | |
outputs: | |
os: ${{ steps.setup-matrix.outputs.os }} | |
python-version: ${{ steps.setup-matrix.outputs.python-version }} | |
steps: | |
- name: Determine event type and set matrix | |
id: setup-matrix | |
run: | | |
if [ "${{ github.event_name }}" == "push" ]; then | |
echo "os=['ubuntu-latest']" >> "$GITHUB_OUTPUT" | |
echo "python-version=['3.10']" >> "$GITHUB_OUTPUT" | |
elif [ "${{ github.event_name }}" == "pull_request" ]; then | |
echo "os=['ubuntu-latest','macos-latest','windows-latest']" >> "$GITHUB_OUTPUT" | |
echo "python-version=['3.10','3.11','3.x']" >> "$GITHUB_OUTPUT" | |
fi | |
CI: | |
needs: setup | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: ${{ fromJSON(needs.setup.outputs.os) }} | |
python-version: ${{ fromJSON(needs.setup.outputs.python-version) }} | |
include: | |
- os: ubuntu-latest | |
python-version: "3.10" | |
representative: True | |
defaults: | |
run: | |
shell: bash | |
steps: | |
- name: Check-out repository | |
uses: actions/checkout@v4 | |
- name: apparently we are lost | |
run: echo $(ls) | |
- name: Run tests, linting, coverage, docs check | |
uses: ./.github/actions/tests | |
with: | |
python-version: ${{ matrix.python-version }} | |
representative: ${{ matrix.representative }} | |
CD: | |
# Only run this job if the "CI" job passes | |
needs: CI | |
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} | |
# Set up operating system | |
runs-on: ubuntu-latest | |
# Define job steps | |
steps: | |
- name: Set up Python 3.10 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.10" | |
- name: Downgrade pip to version before 24.1 | |
run: pip install "pip<24.1" --force-reinstall # Rm when hikari 0.2.4 is out | |
- name: Check-out repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
ssh-key: ${{ secrets.CONTINUOUS_DEPLOYMENT_KEY }} | |
- name: Use Python Semantic Release to prepare release | |
id: release | |
uses: python-semantic-release/python-semantic-release@v9 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Publish to TestPyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
if: steps.release.outputs.released == 'true' | |
with: | |
repository-url: https://test.pypi.org/legacy/ | |
password: ${{ secrets.TEST_PYPI_PICOMETER_API_TOKEN }} | |
- name: Test install from TestPyPI | |
run: | | |
pip install \ | |
--index-url https://test.pypi.org/simple/ \ | |
--extra-index-url https://pypi.org/simple \ | |
picometer | |
- name: Publish to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
if: steps.release.outputs.released == 'true' | |
with: | |
password: ${{ secrets.PYPI_PICOMETER_API_TOKEN }} | |
- name: Publish package distributions to GitHub Releases | |
uses: python-semantic-release/publish-action@v9 | |
if: steps.release.outputs.released == 'true' | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} |