|
| 1 | +name: Code CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + # Restricting to these branches and tags stops duplicate jobs on internal |
| 7 | + # PRs but stops CI running on internal branches without a PR. Delete the |
| 8 | + # next 5 lines to restore the original behaviour |
| 9 | + - master |
| 10 | + - main |
| 11 | + tags: |
| 12 | + - "*" |
| 13 | + pull_request: |
| 14 | + schedule: |
| 15 | + # Run every Monday at 8am to check latest versions of dependencies |
| 16 | + - cron: '0 8 * * MON' |
| 17 | + |
| 18 | +jobs: |
| 19 | + lint: |
| 20 | + runs-on: "ubuntu-latest" |
| 21 | + steps: |
| 22 | + - name: Run black, flake8, mypy |
| 23 | + uses: dls-controls/pipenv-run-action@v1 |
| 24 | + with: |
| 25 | + pipenv-run: lint |
| 26 | + |
| 27 | + wheel: |
| 28 | + runs-on: "ubuntu-latest" |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@v2 |
| 31 | + with: |
| 32 | + fetch-depth: 0 |
| 33 | + |
| 34 | + - name: Create Sdist and Wheel |
| 35 | + # Set SOURCE_DATE_EPOCH from git commit for reproducible build |
| 36 | + # https://reproducible-builds.org/ |
| 37 | + # Set group writable and umask to do the same to match inside DLS |
| 38 | + run: | |
| 39 | + chmod -R g+w . |
| 40 | + umask 0002 |
| 41 | + SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) pipx run build --sdist --wheel |
| 42 | +
|
| 43 | + - name: Test cli works from the installed wheel |
| 44 | + # Can remove the repository reference after https://github.com/pypa/pipx/pull/733 |
| 45 | + run: pipx run --spec dist/*.whl ${GITHUB_REPOSITORY##*/} --version |
| 46 | + |
| 47 | + - name: Upload Wheel and Sdist as artifacts |
| 48 | + uses: actions/upload-artifact@v2 |
| 49 | + with: |
| 50 | + name: dist |
| 51 | + path: dist/* |
| 52 | + |
| 53 | + test: |
| 54 | + strategy: |
| 55 | + fail-fast: false |
| 56 | + matrix: |
| 57 | + os: ["ubuntu-latest"] # can add windows-latest, macos-latest |
| 58 | + python: ["3.7", "3.8", "3.9"] |
| 59 | + pipenv: ["skip-lock"] |
| 60 | + |
| 61 | + include: |
| 62 | + # Add an extra Python3.7 runner to use the lockfile |
| 63 | + - os: "ubuntu-latest" |
| 64 | + python: "3.7" |
| 65 | + pipenv: "deploy" |
| 66 | + |
| 67 | + runs-on: ${{ matrix.os }} |
| 68 | + env: |
| 69 | + # https://github.com/pytest-dev/pytest/issues/2042 |
| 70 | + PY_IGNORE_IMPORTMISMATCH: "1" |
| 71 | + |
| 72 | + steps: |
| 73 | + - name: Setup repo and test |
| 74 | + uses: dls-controls/pipenv-run-action@v1 |
| 75 | + with: |
| 76 | + python-version: ${{ matrix.python }} |
| 77 | + pipenv-install: --dev --${{ matrix.pipenv }} |
| 78 | + allow-editable-installs: ${{ matrix.pipenv == 'deploy' }} |
| 79 | + pipenv-run: tests |
| 80 | + |
| 81 | + - name: Upload coverage to Codecov |
| 82 | + uses: codecov/codecov-action@v2 |
| 83 | + with: |
| 84 | + name: ${{ matrix.python }}/${{ matrix.os }}/${{ matrix.pipenv }} |
| 85 | + files: cov.xml |
| 86 | + |
| 87 | + release: |
| 88 | + needs: [lint, wheel, test] |
| 89 | + runs-on: ubuntu-latest |
| 90 | + # upload to PyPI and make a release on every tag |
| 91 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') |
| 92 | + steps: |
| 93 | + - uses: actions/download-artifact@v2 |
| 94 | + with: |
| 95 | + name: dist |
| 96 | + path: dist |
| 97 | + |
| 98 | + - name: Github Release |
| 99 | + # We pin to the SHA, not the tag, for security reasons. |
| 100 | + # https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions |
| 101 | + uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5 # v0.1.14 |
| 102 | + with: |
| 103 | + files: dist/* |
| 104 | + generate_release_notes: true |
| 105 | + env: |
| 106 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 107 | + |
| 108 | + - name: Publish to PyPI |
| 109 | + env: |
| 110 | + TWINE_USERNAME: __token__ |
| 111 | + TWINE_PASSWORD: ${{ secrets.pypi_token }} |
| 112 | + run: pipx run twine upload dist/* |
0 commit comments