|
1 | 1 | name: frequenz-api-dispatch |
2 | 2 |
|
3 | | -on: [pull_request, push, release] |
| 3 | +on: [pull_request, push] |
4 | 4 |
|
5 | 5 | # Ensure old CI runs still being in progress are cancelled. |
6 | 6 | concurrency: |
|
58 | 58 | python -m pip install .[dev-noxfile] |
59 | 59 | - name: Run nox |
60 | 60 | run: nox |
| 61 | + |
| 62 | + build-dist: |
| 63 | + runs-on: ubuntu-20.04 |
| 64 | + steps: |
| 65 | + - name: Fetch sources |
| 66 | + uses: actions/checkout@v3 |
| 67 | + with: |
| 68 | + submodules: true |
| 69 | + |
| 70 | + - name: Set up Python |
| 71 | + uses: actions/setup-python@v4 |
| 72 | + with: |
| 73 | + python-version: "3.11" |
| 74 | + |
| 75 | + - name: Install build dependencies |
| 76 | + run: | |
| 77 | + python -m pip install -U pip |
| 78 | + python -m pip install -U build |
| 79 | +
|
| 80 | + - name: Build the source and binary distribution |
| 81 | + run: python -m build |
| 82 | + |
| 83 | + - name: Upload dist files |
| 84 | + uses: actions/upload-artifact@v3 |
| 85 | + with: |
| 86 | + name: frequenz-api-dispatch-dist |
| 87 | + path: dist/ |
| 88 | + if-no-files-found: error |
| 89 | + |
| 90 | + create-github-release: |
| 91 | + needs: ["protolint", "gen-docs", "tests", "build-dist"] |
| 92 | + # Create a release only on tags creation |
| 93 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') |
| 94 | + permissions: |
| 95 | + # We need write permissions on contents to create GitHub releases and on |
| 96 | + # discussions to create the release announcement in the discussion forums |
| 97 | + contents: write |
| 98 | + discussions: write |
| 99 | + runs-on: ubuntu-20.04 |
| 100 | + steps: |
| 101 | + - name: Download dist files |
| 102 | + uses: actions/download-artifact@v3 |
| 103 | + with: |
| 104 | + name: frequenz-api-dispatch-dist |
| 105 | + path: dist |
| 106 | + |
| 107 | + - name: Download RELEASE_NOTES.md |
| 108 | + run: | |
| 109 | + set -ux |
| 110 | + gh api \ |
| 111 | + -X GET \ |
| 112 | + -f ref=$REF \ |
| 113 | + -H "Accept: application/vnd.github.raw" \ |
| 114 | + "/repos/$REPOSITORY/contents/RELEASE_NOTES.md" \ |
| 115 | + > RELEASE_NOTES.md |
| 116 | + env: |
| 117 | + REF: ${{ github.ref }} |
| 118 | + REPOSITORY: ${{ github.repository }} |
| 119 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 120 | + |
| 121 | + - name: Create GitHub release |
| 122 | + run: | |
| 123 | + set -ux |
| 124 | + extra_opts= |
| 125 | + if echo "$REF_NAME" | grep -- -; then extra_opts=" --prerelease"; fi |
| 126 | + gh release create \ |
| 127 | + -R "$REPOSITORY" \ |
| 128 | + --discussion-category announcements \ |
| 129 | + --notes-file RELEASE_NOTES.md \ |
| 130 | + --generate-notes \ |
| 131 | + $extra_opts \ |
| 132 | + $REF_NAME \ |
| 133 | + dist/* |
| 134 | + env: |
| 135 | + REF_NAME: ${{ github.ref_name }} |
| 136 | + REPOSITORY: ${{ github.repository }} |
| 137 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 138 | + |
| 139 | + publish-to-pypi: |
| 140 | + needs: ["create-github-release"] |
| 141 | + runs-on: ubuntu-20.04 |
| 142 | + permissions: |
| 143 | + # For trusted publishing. See: |
| 144 | + # https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/ |
| 145 | + id-token: write |
| 146 | + steps: |
| 147 | + - name: Download dist files |
| 148 | + uses: actions/download-artifact@v3 |
| 149 | + with: |
| 150 | + name: frequenz-api-dispatch-dist |
| 151 | + path: dist |
| 152 | + |
| 153 | + - name: Publish the Python distribution to PyPI |
| 154 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments