|
1 | 1 | name: frequenz-channels-python |
2 | 2 |
|
3 | | -on: |
4 | | - push: |
5 | | - branches: [ v0.x.x ] |
6 | | - |
7 | | - pull_request: |
8 | | - |
9 | | - workflow_dispatch: |
| 3 | +on: [pull_request, push, workflow_dispatch] |
10 | 4 |
|
11 | 5 | jobs: |
12 | 6 | test: |
13 | | - runs-on: ubuntu-20.04 |
| 7 | + strategy: |
| 8 | + matrix: |
| 9 | + os: |
| 10 | + - ubuntu-20.04 |
| 11 | + python-version: |
| 12 | + - "3.8" |
| 13 | + - "3.9" |
| 14 | + - "3.10" |
| 15 | + runs-on: ${{ matrix.os }} |
14 | 16 |
|
15 | 17 | steps: |
16 | 18 | - name: Fetch sources |
17 | | - uses: actions/checkout@v2 |
| 19 | + uses: actions/checkout@v3 |
18 | 20 | with: |
19 | 21 | submodules: true |
20 | 22 |
|
21 | 23 | - name: Set up Python |
22 | | - uses: actions/setup-python@v2 |
| 24 | + uses: actions/setup-python@v4 |
23 | 25 | with: |
24 | | - python-version: "3.8" |
| 26 | + python-version: ${{ matrix.python-version }} |
25 | 27 |
|
26 | | - - uses: actions/cache@v2 |
| 28 | + - uses: actions/cache@v3 |
27 | 29 | with: |
28 | 30 | path: ~/.cache/pip |
29 | | - key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.cfg') }} |
| 31 | + key: ${{ runner.os }}-${{ matrix.python-version }}-pip-${{ hashFiles('pyproject.toml') }} |
30 | 32 | restore-keys: | |
31 | | - ${{ runner.os }}-pip- |
| 33 | + ${{ runner.os }}-${{ matrix.python-version }}-pip- |
32 | 34 |
|
33 | 35 | - name: Install required Python packages |
34 | 36 | run: | |
|
38 | 40 | - name: run nox |
39 | 41 | run: nox |
40 | 42 | timeout-minutes: 10 |
| 43 | + |
| 44 | + build-dist: |
| 45 | + runs-on: ubuntu-20.04 |
| 46 | + steps: |
| 47 | + - name: Fetch sources |
| 48 | + uses: actions/checkout@v3 |
| 49 | + with: |
| 50 | + submodules: true |
| 51 | + |
| 52 | + - name: Set up Python |
| 53 | + uses: actions/setup-python@v4 |
| 54 | + with: |
| 55 | + python-version: "3.10" |
| 56 | + |
| 57 | + - name: Install build dependencies |
| 58 | + run: | |
| 59 | + python -m pip install -U pip |
| 60 | + python -m pip install -U build |
| 61 | +
|
| 62 | + - name: Build the source and binary distribution |
| 63 | + run: python -m build |
| 64 | + |
| 65 | + - name: Upload dist files |
| 66 | + uses: actions/upload-artifact@v3 |
| 67 | + with: |
| 68 | + name: frequenz-channels-python-dist |
| 69 | + path: dist/ |
| 70 | + if-no-files-found: error |
| 71 | + |
| 72 | + create-github-release: |
| 73 | + needs: ["test", "build-dist"] |
| 74 | + # Create a release only on tags creation |
| 75 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') |
| 76 | + permissions: |
| 77 | + # We need write permissions on contents to create GitHub releases and on |
| 78 | + # discussions to create the release announcement in the discussion forums |
| 79 | + contents: write |
| 80 | + discussions: write |
| 81 | + runs-on: ubuntu-20.04 |
| 82 | + steps: |
| 83 | + - name: Download dist files |
| 84 | + uses: actions/download-artifact@v3 |
| 85 | + with: |
| 86 | + name: frequenz-channels-python-dist |
| 87 | + path: dist |
| 88 | + |
| 89 | + - name: Download RELEASE_NOTES.md |
| 90 | + run: | |
| 91 | + set -ux |
| 92 | + gh api \ |
| 93 | + -X GET \ |
| 94 | + -f ref=$REF \ |
| 95 | + -H "Accept: application/vnd.github.raw" \ |
| 96 | + "/repos/$REPOSITORY/contents/RELEASE_NOTES.md" \ |
| 97 | + > RELEASE_NOTES.md |
| 98 | + env: |
| 99 | + REF: ${{ github.ref }} |
| 100 | + REPOSITORY: ${{ github.repository }} |
| 101 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 102 | + |
| 103 | + - name: Create GitHub release |
| 104 | + run: | |
| 105 | + set -ux |
| 106 | + extra_opts= |
| 107 | + if echo "$REF_NAME" | grep -- -; then extra_opts=" --prerelease"; fi |
| 108 | + gh release create \ |
| 109 | + -R "$REPOSITORY" \ |
| 110 | + --discussion-category announcements \ |
| 111 | + --notes-file RELEASE_NOTES.md \ |
| 112 | + --generate-notes \ |
| 113 | + $extra_opts \ |
| 114 | + $REF_NAME \ |
| 115 | + dist/* |
| 116 | + env: |
| 117 | + REF_NAME: ${{ github.ref_name }} |
| 118 | + REPOSITORY: ${{ github.repository }} |
| 119 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 120 | + |
| 121 | + publish-to-pypi: |
| 122 | + needs: ["create-github-release"] |
| 123 | + runs-on: ubuntu-20.04 |
| 124 | + steps: |
| 125 | + - name: Download dist files |
| 126 | + uses: actions/download-artifact@v3 |
| 127 | + with: |
| 128 | + name: frequenz-channels-python-dist |
| 129 | + path: dist |
| 130 | + |
| 131 | + - name: Publish the Python distribution to PyPI |
| 132 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 133 | + with: |
| 134 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 135 | + skip_existing: true |
0 commit comments