|
| 1 | +name: Publish |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + release: |
| 6 | + types: |
| 7 | + - published |
| 8 | + |
| 9 | +jobs: |
| 10 | + version: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + outputs: |
| 13 | + version: ${{ steps.set_output.outputs.version }} |
| 14 | + upload_url: ${{ steps.set_output.outputs.upload_url }} |
| 15 | + env: |
| 16 | + VERSION: "" |
| 17 | + UPLOAD_URL: "" |
| 18 | + steps: |
| 19 | + - name: Get version and upload url from release |
| 20 | + if: github.event_name == 'release' |
| 21 | + run: | |
| 22 | + echo "VERSION=${{ github.event.release.tag_name }}" >> $GITHUB_ENV |
| 23 | + echo "UPLOAD_URL=${{ github.event.release.upload_url }}" >> $GITHUB_ENV |
| 24 | +
|
| 25 | + - name: Get release from API |
| 26 | + if: github.event_name == 'workflow_dispatch' |
| 27 | + id: release_api |
| 28 | + |
| 29 | + with: |
| 30 | + route: GET /repos/${{ github.repository }}/releases/latest |
| 31 | + env: |
| 32 | + GITHUB_TOKEN: ${{ secrets.PAT }} |
| 33 | + |
| 34 | + - name: Parse API response |
| 35 | + if: github.event_name == 'workflow_dispatch' |
| 36 | + run: | |
| 37 | + echo "VERSION=${{ fromJson(steps.release_api.outputs.data).tag_name }}" >> $GITHUB_ENV |
| 38 | + echo "UPLOAD_URL=${{ fromJson(steps.release_api.outputs.data).upload_url }}" >> $GITHUB_ENV |
| 39 | +
|
| 40 | + - name: Log version and upload URL |
| 41 | + run: | |
| 42 | + echo "Version: $VERSION" |
| 43 | + echo "Upload URL: $UPLOAD_URL" |
| 44 | +
|
| 45 | + - name: Fail if no version or no upload URL |
| 46 | + run: | |
| 47 | + if [[ -z "$VERSION" || -z "$UPLOAD_URL" ]]; then |
| 48 | + echo "Missing version or upload URL" |
| 49 | + exit 1 |
| 50 | + fi |
| 51 | +
|
| 52 | + - name: Set outputs |
| 53 | + id: set_output |
| 54 | + run: | |
| 55 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 56 | + echo "upload_url=$UPLOAD_URL" >> $GITHUB_OUTPUT |
| 57 | +
|
| 58 | + package: |
| 59 | + needs: version |
| 60 | + runs-on: ubuntu-latest |
| 61 | + steps: |
| 62 | + - name: Checkout code |
| 63 | + uses: actions/checkout@v4 |
| 64 | + |
| 65 | + - name: Set up Python |
| 66 | + uses: actions/setup-python@v4 |
| 67 | + with: |
| 68 | + python-version: "3.11" |
| 69 | + |
| 70 | + - name: Load cached Poetry installation |
| 71 | + id: cached-poetry |
| 72 | + uses: actions/cache@v3 |
| 73 | + with: |
| 74 | + path: ~/.local |
| 75 | + key: poetry-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }} |
| 76 | + |
| 77 | + - name: Install Poetry |
| 78 | + if: steps.cached-poetry.outputs.cache-hit != 'true' |
| 79 | + uses: snok/install-poetry@v1 |
| 80 | + with: |
| 81 | + virtualenvs-create: true |
| 82 | + virtualenvs-in-project: true |
| 83 | + |
| 84 | + - name: Load cached Poetry venv |
| 85 | + id: cached-poetry-venv |
| 86 | + uses: actions/cache@v3 |
| 87 | + with: |
| 88 | + path: .venv |
| 89 | + key: poetry-venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }} |
| 90 | + |
| 91 | + - name: Install dependencies |
| 92 | + if: steps.cached-poetry-venv.outputs.cache-hit != 'true' |
| 93 | + run: poetry install --no-interaction --no-root |
| 94 | + |
| 95 | + - name: Install package |
| 96 | + run: poetry install --no-interaction |
| 97 | + |
| 98 | + - name: Set package version |
| 99 | + run: | |
| 100 | + poetry version ${{ needs.version.outputs.version }} |
| 101 | +
|
| 102 | + - name: Build package |
| 103 | + run: | |
| 104 | + poetry build |
| 105 | +
|
| 106 | + - name: Upload package to pyPI |
| 107 | + run: | |
| 108 | + poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }} |
| 109 | + poetry publish |
| 110 | +
|
| 111 | + - name: Upload package to release |
| 112 | + uses: actions/upload-release-asset@v1 |
| 113 | + env: |
| 114 | + GITHUB_TOKEN: ${{ secrets.PAT }} |
| 115 | + with: |
| 116 | + upload_url: ${{ needs.version.outputs.upload_url }} |
| 117 | + asset_path: ./dist/eq3btsmart-${{ needs.version.outputs.version }}.tar.gz |
| 118 | + asset_name: eq3btsmart-${{ needs.version.outputs.version }}.tar.gz |
| 119 | + asset_content_type: application/gzip |
| 120 | + |
| 121 | + - name: Upload wheel to release |
| 122 | + uses: actions/upload-release-asset@v1 |
| 123 | + env: |
| 124 | + GITHUB_TOKEN: ${{ secrets.PAT }} |
| 125 | + with: |
| 126 | + upload_url: ${{ needs.version.outputs.upload_url }} |
| 127 | + asset_path: ./dist/eq3btsmart-${{ needs.version.outputs.version }}-py3-none-any.whl |
| 128 | + asset_name: eq3btsmart-${{ needs.version.outputs.version }}-py3-none-any.whl |
| 129 | + asset_content_type: application/zip |
0 commit comments