|
| 1 | +# SPDX-FileCopyrightText: 2024 Ledger SAS |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +name: Upload Python Package to jfrog |
| 6 | + |
| 7 | +on: |
| 8 | + workflow_call: |
| 9 | + inputs: |
| 10 | + environment: |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + runner: |
| 14 | + required: true |
| 15 | + type: string |
| 16 | + python-version: |
| 17 | + required: true |
| 18 | + type: string |
| 19 | + build-name: |
| 20 | + required: true |
| 21 | + type: string |
| 22 | + module-name: |
| 23 | + required: true |
| 24 | + type: string |
| 25 | + repo-name: |
| 26 | + required: true |
| 27 | + type: string |
| 28 | + virtual-repo-name: |
| 29 | + required: true |
| 30 | + type: string |
| 31 | +defaults: |
| 32 | + run: |
| 33 | + shell: bash |
| 34 | + |
| 35 | +jobs: |
| 36 | + deploy: |
| 37 | + runs-on: ${{ inputs.runner }} |
| 38 | + environment: ${{ inputs.environment }} |
| 39 | + |
| 40 | + permissions: |
| 41 | + id-token: write |
| 42 | + contents: read |
| 43 | + attestations: write |
| 44 | + |
| 45 | + steps: |
| 46 | + - name: Set up Python |
| 47 | + uses: actions/setup-python@v5 |
| 48 | + with: |
| 49 | + python-version: ${{ inputs.python-version }} |
| 50 | + - name: Install build basics |
| 51 | + run: | |
| 52 | + pip install build wheel-filename blob |
| 53 | + - name: Checkout code |
| 54 | + uses: actions/checkout@v4 |
| 55 | + with: |
| 56 | + fetch-depth: 0 |
| 57 | + fetch-tags: true |
| 58 | + - name: build package |
| 59 | + run: python3 -m build . --sdist --wheel |
| 60 | + - name: get back local build version |
| 61 | + id: get_pkg_version |
| 62 | + run: | |
| 63 | + from wheel_filename import parse_wheel_filename |
| 64 | + import glob |
| 65 | + import os |
| 66 | + from random import choices |
| 67 | + from string import ascii_letters |
| 68 | +
|
| 69 | + whl = str(glob.glob('dist/*.whl')[0]); |
| 70 | + pwf = parse_wheel_filename('dist/' + whl); |
| 71 | + with open(os.environ["GITHUB_OUTPUT"], "a") as gh_output: |
| 72 | + delimiter = "".join(choices(ascii_letters, k=16)) |
| 73 | + gh_output.writelines([ |
| 74 | + f"pkg_version<<{delimiter}\n", |
| 75 | + f"{pwf.version}\n", |
| 76 | + delimiter + "\n", |
| 77 | + ]) |
| 78 | + shell: python |
| 79 | + - name: Login to JFrog Ledger |
| 80 | + uses: LedgerHQ/actions-security/actions/jfrog-login@actions/jfrog-login-1 |
| 81 | + - name: upload package |
| 82 | + run: jf rt u --build-name=${{ inputs.build-name }} --build-number=1 --module=${{ inputs.module-name }} 'dist/*.tar.gz' ${{ inputs.repo-name }}/${{ inputs.repo-name }}/ |
| 83 | + - name: Attest |
| 84 | + id: attest |
| 85 | + uses: LedgerHQ/actions-security/actions/attest@actions/attest-1 |
| 86 | + with: |
| 87 | + subject-path: 'dist/*.tar.gz' |
| 88 | + push-to-registry: false |
| 89 | + - name: set jfrog Repo URL |
| 90 | + run: jf pipc --global --repo-resolve=${{ inputs.virtual-repo-name }} |
| 91 | + - name: test install from jfrog |
| 92 | + run: | |
| 93 | + jf pip install ${{ inputs.module-name }}==${{ steps.get_pkg_version.outputs.pkg_version }} |
| 94 | + pip show ${{ inputs.module-name }} |
0 commit comments