|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + merge_group: |
| 5 | + pull_request: |
| 6 | + push: |
| 7 | + # We need to explicitly include tags because otherwise when adding |
| 8 | + # `branches-ignore` it will only trigger on branches. |
| 9 | + tags: |
| 10 | + - '*' |
| 11 | + branches-ignore: |
| 12 | + # Ignore pushes to merge queues. |
| 13 | + # We only want to test the merge commit (`merge_group` event), the hashes |
| 14 | + # in the push were already tested by the PR checks |
| 15 | + - 'gh-readonly-queue/**' |
| 16 | + workflow_dispatch: |
| 17 | + |
| 18 | +env: |
| 19 | + DEFAULT_PYTHON_VERSION: '3.11' |
| 20 | + DEFAULT_UBUNTU_VERSION: '20.04' |
| 21 | + |
| 22 | +jobs: |
| 23 | + nox: |
| 24 | + name: Test with nox |
| 25 | + strategy: |
| 26 | + fail-fast: false |
| 27 | + matrix: |
| 28 | + os: |
| 29 | + - ubuntu-{{'${{ env.DEFAULT_UBUNTU_VERSION }}'}} |
| 30 | + python: |
| 31 | + - "{{'${{ env.DEFAULT_PYTHON_VERSION }}'}}" |
| 32 | + runs-on: {{'${{ matrix.os }}'}} |
| 33 | + |
| 34 | + steps: |
| 35 | + - name: Fetch sources |
| 36 | + uses: actions/checkout@v3 |
| 37 | + |
| 38 | + - name: Set up Python |
| 39 | + uses: actions/setup-python@v4 |
| 40 | + with: |
| 41 | + python-version: {{'${{ matrix.python }}'}} |
| 42 | + cache: 'pip' |
| 43 | + |
| 44 | + - name: Install required Python packages |
| 45 | + run: | |
| 46 | + python -m pip install --upgrade pip |
| 47 | + python -m pip install -e .[dev-noxfile] |
| 48 | +
|
| 49 | + - name: Run nox |
| 50 | + run: nox |
| 51 | + timeout-minutes: 10 |
| 52 | + |
| 53 | + build: |
| 54 | + name: Build distribution packages |
| 55 | + runs-on: ubuntu-{{'${{ env.DEFAULT_UBUNTU_VERSION }}'}} |
| 56 | + steps: |
| 57 | + - name: Fetch sources |
| 58 | + uses: actions/checkout@v3 |
| 59 | + |
| 60 | + - name: Set up Python |
| 61 | + uses: actions/setup-python@v4 |
| 62 | + with: |
| 63 | + python-version: {{'${{ env.DEFAULT_PYTHON_VERSION }}'}} |
| 64 | + cache: 'pip' |
| 65 | + |
| 66 | + - name: Install required Python packages |
| 67 | + run: | |
| 68 | + python -m pip install -U pip |
| 69 | + python -m pip install -U build |
| 70 | +
|
| 71 | + - name: Build the source and binary distribution |
| 72 | + run: python -m build |
| 73 | + |
| 74 | + - name: Upload distribution files |
| 75 | + uses: actions/upload-artifact@v3 |
| 76 | + with: |
| 77 | + name: dist-packages |
| 78 | + path: dist/ |
| 79 | + if-no-files-found: error |
| 80 | + |
| 81 | + create-github-release: |
| 82 | + name: Create GitHub release |
| 83 | + needs: ["publish-docs"] |
| 84 | + # Create a release only on tags creation |
| 85 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') |
| 86 | + permissions: |
| 87 | + # We need write permissions on contents to create GitHub releases and on |
| 88 | + # discussions to create the release announcement in the discussion forums |
| 89 | + contents: write |
| 90 | + discussions: write |
| 91 | + runs-on: ubuntu-{{'${{ env.DEFAULT_UBUNTU_VERSION }}'}} |
| 92 | + steps: |
| 93 | + - name: Download distribution files |
| 94 | + uses: actions/download-artifact@v3 |
| 95 | + with: |
| 96 | + name: dist-packages |
| 97 | + path: dist |
| 98 | + |
| 99 | + - name: Download RELEASE_NOTES.md |
| 100 | + run: | |
| 101 | + set -ux |
| 102 | + gh api \ |
| 103 | + -X GET \ |
| 104 | + -f ref=$REF \ |
| 105 | + -H "Accept: application/vnd.github.raw" \ |
| 106 | + "/repos/$REPOSITORY/contents/RELEASE_NOTES.md" \ |
| 107 | + > RELEASE_NOTES.md |
| 108 | + env: |
| 109 | + REF: {{'${{ github.ref }}'}} |
| 110 | + REPOSITORY: {{'${{ github.repository }}'}} |
| 111 | + GH_TOKEN: {{'${{ secrets.GITHUB_TOKEN }}'}} |
| 112 | + |
| 113 | + - name: Create GitHub release |
| 114 | + run: | |
| 115 | + set -ux |
| 116 | + extra_opts= |
| 117 | + if echo "$REF_NAME" | grep -- -; then extra_opts=" --prerelease"; fi |
| 118 | + gh release create \ |
| 119 | + -R "$REPOSITORY" \ |
| 120 | + --notes-file RELEASE_NOTES.md \ |
| 121 | + --generate-notes \ |
| 122 | + $extra_opts \ |
| 123 | + $REF_NAME \ |
| 124 | + dist/* |
| 125 | + env: |
| 126 | + REF_NAME: {{'${{ github.ref_name }}'}} |
| 127 | + REPOSITORY: {{'${{ github.repository }}'}} |
| 128 | + GH_TOKEN: {{'${{ secrets.GITHUB_TOKEN }}'}} |
| 129 | + |
| 130 | + publish-to-pypi: |
| 131 | + name: Publish packages to PyPI |
| 132 | + needs: ["create-github-release"] |
| 133 | + runs-on: ubuntu-{{'${{ env.DEFAULT_UBUNTU_VERSION }}'}} |
| 134 | + permissions: |
| 135 | + # For trusted publishing. See: |
| 136 | + # https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/ |
| 137 | + id-token: write |
| 138 | + steps: |
| 139 | + - name: Download distribution files |
| 140 | + uses: actions/download-artifact@v3 |
| 141 | + with: |
| 142 | + name: dist-packages |
| 143 | + path: dist |
| 144 | + |
| 145 | + - name: Publish the Python distribution to PyPI |
| 146 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments