|
| 1 | +name: Test and deploy |
| 2 | + |
| 3 | +on: [push] |
| 4 | + |
| 5 | +jobs: |
| 6 | + |
| 7 | + build: |
| 8 | + name: ${{ matrix.os }} python ${{ matrix.python-version }} |
| 9 | + |
| 10 | + runs-on: ${{ matrix.os }} |
| 11 | + |
| 12 | + if: >- |
| 13 | + !contains(github.event.head_commit.message, '[skip ci]') |
| 14 | + && !contains(github.event.head_commit.message, '[skip tests]') |
| 15 | +
|
| 16 | + strategy: |
| 17 | + fail-fast: false |
| 18 | + matrix: |
| 19 | + os: [ubuntu-latest, macos-latest] |
| 20 | + python-version: ['3.8', '3.10'] |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Skip replicates on main branch |
| 24 | + env: |
| 25 | + skip_replicates: ${{ github.ref == 'refs/heads/main' && (matrix.os != 'ubuntu-latest' || matrix.python-version != '3.10') }} |
| 26 | + shell: bash |
| 27 | + run: | |
| 28 | + echo "skipping_build_and_test_replicate=${skip_replicates}" >> $GITHUB_ENV |
| 29 | + # echo "skipping_build_and_test_replicate='false'" >> $GITHUB_ENV |
| 30 | +
|
| 31 | + - name: Check out code |
| 32 | + if: ${{ env.skipping_build_and_test_replicate != 'true' }} |
| 33 | + uses: actions/checkout@v2 |
| 34 | + |
| 35 | + - name: Set up python ${{ matrix.python-version }} |
| 36 | + if: ${{ env.skipping_build_and_test_replicate != 'true' }} |
| 37 | + uses: actions/setup-python@v2 |
| 38 | + with: |
| 39 | + python-version: ${{ matrix.python-version }} |
| 40 | + |
| 41 | + - name: Install poetry |
| 42 | + if: ${{ env.skipping_build_and_test_replicate != 'true' }} |
| 43 | + shell: bash |
| 44 | + run: | |
| 45 | + curl -fsS -o get-poetry.py https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py |
| 46 | + python get-poetry.py -y |
| 47 | + echo "$HOME/.poetry/bin" >> $GITHUB_PATH |
| 48 | +
|
| 49 | + - name: Build and install with poetry |
| 50 | + if: ${{ env.skipping_build_and_test_replicate != 'true' }} |
| 51 | + shell: bash |
| 52 | + run: | |
| 53 | + poetry run python -m pip install --upgrade pip |
| 54 | + poetry env info |
| 55 | + rm poetry.lock |
| 56 | + poetry update |
| 57 | + poetry build |
| 58 | + poetry install --no-interaction |
| 59 | +
|
| 60 | + - name: Run tests |
| 61 | + if: ${{ env.skipping_build_and_test_replicate != 'true' }} |
| 62 | + shell: bash |
| 63 | + run: | |
| 64 | + poetry run pytest -s --cov=scri --cov-branch --cov-report=xml --durations=0 |
| 65 | +
|
| 66 | + - name: Upload coverage |
| 67 | + if: "matrix.python-version == '3.10' && matrix.os == 'ubuntu-latest'" |
| 68 | + uses: codecov/codecov-action@v2 |
| 69 | + |
| 70 | + |
| 71 | + release: |
| 72 | + name: Create release and send to PyPI |
| 73 | + needs: build |
| 74 | + runs-on: ubuntu-latest |
| 75 | + if: >- |
| 76 | + github.ref == 'refs/heads/main' |
| 77 | + && !contains(github.event.head_commit.message, '[no release]') |
| 78 | + && (success() || contains(github.event.head_commit.message, '[skip tests]')) |
| 79 | +
|
| 80 | + steps: |
| 81 | + - name: Check out code |
| 82 | + uses: actions/checkout@v2 |
| 83 | + |
| 84 | + - name: Set up python ${{ matrix.python-version }} |
| 85 | + uses: actions/setup-python@v2 |
| 86 | + with: |
| 87 | + python-version: '3.10' |
| 88 | + |
| 89 | + - name: Install toml |
| 90 | + if: ${{ env.skipping_build_and_test_replicate != 'true' }} |
| 91 | + shell: bash |
| 92 | + run: | |
| 93 | + python -m pip install --upgrade pip toml |
| 94 | +
|
| 95 | + - name: Install poetry |
| 96 | + if: ${{ env.skipping_build_and_test_replicate != 'true' }} |
| 97 | + shell: bash |
| 98 | + run: | |
| 99 | + curl -fsS -o get-poetry.py https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py |
| 100 | + python get-poetry.py -y |
| 101 | +
|
| 102 | + - name: Build and install with poetry |
| 103 | + if: ${{ env.skipping_build_and_test_replicate != 'true' }} |
| 104 | + shell: bash |
| 105 | + run: | |
| 106 | + $HOME/.poetry/bin/poetry run python -m pip install --upgrade pip |
| 107 | + $HOME/.poetry/bin/poetry env info |
| 108 | + rm poetry.lock |
| 109 | + $HOME/.poetry/bin/poetry update |
| 110 | + $HOME/.poetry/bin/poetry build |
| 111 | + $HOME/.poetry/bin/poetry install --no-interaction --no-dev |
| 112 | +
|
| 113 | + - name: Bump version |
| 114 | + shell: bash |
| 115 | + env: |
| 116 | + github_event_head_commit_message: ${{ github.event.head_commit.message }} |
| 117 | + run: | |
| 118 | + # Note: The following line reads the HEAD commit message to look for an indication of how |
| 119 | + # to bump the version number. Specifically, if `#patch`, `#minor`, or `#major` is present |
| 120 | + # in the commit message, it bumps the corresponding version number. Those can also be |
| 121 | + # prepended as `#premajor`, etc., to add/bump the prerelease modifier. If none of those |
| 122 | + # are present, `#patch` is assumed — that is, the lowest-significance number is |
| 123 | + # incremented. See the documentation of the `poetry version` command for details. |
| 124 | + export version_bump_rule=$(python .github/scripts/parse_bump_rule.py) |
| 125 | + echo "version_bump_rule: '${version_bump_rule}'" |
| 126 | + $HOME/.poetry/bin/poetry version "${version_bump_rule}" |
| 127 | + export new_version=$(python .github/scripts/parse_version.py pyproject.toml) |
| 128 | + echo "new_version: '${new_version}'" |
| 129 | + echo "new_version=${new_version}" >> $GITHUB_ENV # Save env variable for later steps |
| 130 | +
|
| 131 | + - name: Tag and push new version |
| 132 | + shell: bash |
| 133 | + run: | |
| 134 | + git config user.name github-actions |
| 135 | + git config user.email github-actions@github.com |
| 136 | + git add pyproject.toml |
| 137 | + git commit -m "Bump version to v${new_version}" |
| 138 | + git tag -a "v${new_version}" -m "Version ${new_version}" |
| 139 | + git status |
| 140 | + git push --follow-tags # Will not trigger new workflow because it uses GITHUB_TOKEN |
| 141 | +
|
| 142 | + - name: Create release |
| 143 | + if: "!contains(github.event.head_commit.message, '[no release]')" |
| 144 | + id: create_release |
| 145 | + uses: actions/create-release@latest |
| 146 | + env: |
| 147 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 148 | + with: |
| 149 | + tag_name: v${{ env.new_version }} |
| 150 | + release_name: Release v${{ env.new_version }} |
| 151 | + draft: false |
| 152 | + prerelease: false |
| 153 | + |
| 154 | + - name: Publish to PyPI |
| 155 | + if: "!contains(github.event.head_commit.message, '[no pypi]')" |
| 156 | + env: |
| 157 | + # 1) Get key from https://pypi.org/manage/account/token/ |
| 158 | + # 2) Copy it to Github > repo > Settings > Secrets |
| 159 | + POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }} |
| 160 | + shell: bash |
| 161 | + run: | |
| 162 | + # Do these first two steps again to ensure the version is right |
| 163 | + $HOME/.poetry/bin/poetry build |
| 164 | + $HOME/.poetry/bin/poetry install --no-interaction --no-dev |
| 165 | + $HOME/.poetry/bin/poetry publish |
0 commit comments