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