@@ -3,23 +3,25 @@ name: Build, check and deploy an package on pypi.org or test.pypi.org
3
3
on :
4
4
workflow_call :
5
5
inputs :
6
- stable_deployment :
7
- description : If the package is to be deployed on pypiorg (true) or test.pypi.org (false)
6
+ package_name :
7
+ description : The name of the package.
8
8
required : true
9
- type : boolean
9
+ type : string
10
10
package_directory :
11
- description : The directory where the Python package lies (where the setup.py or setup.cfg or pyproject.toml can be found)
12
- required : true
11
+ description : The directory where the Python package lies (where the setup.py or setup.cfg or
12
+ pyproject.toml can be found)
13
13
type : string
14
- check_changelog_version :
15
- description : If true, a CHANGELOG.md file is expected in the `package_directory`. The workflow will check that its latest
16
- version matches the Python package version.
17
- required : true
18
- type : boolean
14
+ default : .
19
15
publish :
20
- description : Whether the package should be published (on pypi.org or test.pypi.org depending on `stable_deployment`) or not
16
+ description : Whether the package should be published or not
21
17
required : true
22
18
type : boolean
19
+ jfrog_deployment :
20
+ description : If the Python package should be pushed on Ledger Jfrog or not.
21
+ Ignored if `publish` is `false`.
22
+ type : boolean
23
+ required : false
24
+ default : true
23
25
secrets :
24
26
pypi_token :
25
27
description : A token enabling to push a package on pypi.org or test.pypi.org
29
31
jobs :
30
32
package_and_deploy :
31
33
name : Build and deploy a Python Package
32
- runs-on : ubuntu-22.04
34
+ runs-on : public-ledgerhq-shared-small
35
+ permissions :
36
+ id-token : write
37
+ attestations : write
38
+ contents : write
33
39
steps :
34
40
35
41
- name : Clone
36
42
uses : actions/checkout@v4
37
43
with :
38
44
fetch-depth : 0
39
45
40
- - name : Configure target deploiement repository
41
- run : |
42
- if [ "${{ inputs.stable_deployment }}" = "true" ];
43
- then
44
- echo "DEPLOYMENT_TARGET=https://pypi.org/simple/" >> "$GITHUB_ENV";
45
- else
46
- echo "DEPLOYMENT_TARGET=https://test.pypi.org/simple/" >> "$GITHUB_ENV";
47
- fi
48
-
49
- - name : Display current parameters
50
- run : |
51
- echo "Parameters are:"
52
- echo "- Stable deployment: ${{ inputs.stable_deployment }}"
53
- echo "- Will be deployed: ${{ inputs.publish }}"
54
- echo "- If deployed, will be on ${{ env.DEPLOYMENT_TARGET }}"
55
-
56
- - name : Check Python package dependencies and local install
46
+ - name : Build Python package
57
47
run : |
48
+ # Needed to workaround this bug https://github.com/pypa/setuptools/issues/4759
49
+ # To be removed when it's fixed
50
+ pip install -U packaging
51
+ pip install --upgrade pip build twine
58
52
cd ${{ inputs.package_directory }}
59
- pip install -v --extra-index-url ${{ env.DEPLOYMENT_TARGET }} .
53
+ python -m build
54
+ pip install .
55
+ python -m twine check dist/*
56
+ echo "TAG_VERSION=$(python -c 'from ${{ inputs.package_name }} import __version__; print(__version__)')" >> "$GITHUB_ENV"
60
57
61
- # Fetching dependencies from test.pypi,org or pypi.org depending on the package destination:
62
- # tag -> pypi.org, not tag -> test.pypi.org
63
- - name : Build and check Python package
58
+ - name : Display current status
64
59
run : |
65
- cd ${{ inputs.package_directory }}
66
- pip install --upgrade pip build twine
67
- PIP_EXTRA_INDEX_URL=${{ env.DEPLOYMENT_TARGET }} python -m build
68
- python -m twine check dist/*
60
+ echo "- Tag version: ${{ env.TAG_VERSION }}"
69
61
70
62
- name : Check version against CHANGELOG
71
- if : inputs.check_changelog_version
63
+ if : ${{ success() && inputs.publish }}
72
64
run : |
73
- PACKAGE_VERSION=$(find "${{ inputs.package_directory }}/dist" -name *.tar.gz | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')
74
- CHANGELOG_VERSION=$(grep -Po '(?<=## \[)(\d+\.)+[^\]]' "${{ inputs.package_directory }}/CHANGELOG.md" | head -n 1)
75
- if [ "${PACKAGE_VERSION}" = "${CHANGELOG_VERSION}" ];
65
+ CHANGELOG_VERSION=$(grep -Po '(?<=## \[)(\d+\.)+[^\]]' CHANGELOG.md | head -n 1)
66
+ if [ "${{ env.TAG_VERSION }}" == "${CHANGELOG_VERSION}" ]
76
67
then
77
- exit 0;
78
- else
79
- echo "Tag '${PACKAGE_VERSION}' and CHANGELOG '${CHANGELOG_VERSION}' versions mismatch!";
80
- exit 1;
68
+ exit 0
81
69
fi
70
+ echo "Tag '${{ env.TAG_VERSION }}' and CHANGELOG '${CHANGELOG_VERSION}' versions mismatch!"
71
+ exit 1
82
72
83
- - name : Publish Python package on pypi.org or test.pypi.org
84
- if : inputs.publish
85
- run : |
86
- cd ${{ inputs.package_directory }}
87
- if [ "${{ inputs.stable_deployment }}" = "true" ];
88
- then
89
- python -m twine upload dist/*;
90
- else
91
- python -m twine upload --repository testpypi dist/*;
92
- fi
73
+ - name : Publish Python package on pypi.org
74
+ if : ${{ success() && inputs.publish }}
75
+ run : python -m twine upload ${{ inputs.package_directory }}/dist/*
93
76
env :
94
77
TWINE_USERNAME : __token__
95
- TWINE_PASSWORD : ${{ secrets.pypi_token }}
78
+ TWINE_PASSWORD : ${{ secrets.pypi_token }}
96
79
TWINE_NON_INTERACTIVE : 1
80
+
81
+ - name : Login to Ledger Artifactory
82
+ if : ${{ success() && inputs.publish && inputs.jfrog_deployment }}
83
+ timeout-minutes : 10
84
+ id : jfrog-login
85
+ uses : LedgerHQ/actions-security/actions/jfrog-login@actions/jfrog-login-1
86
+
87
+ - name : Publish Python package on Ledger Artifactory
88
+ if : ${{ success() && inputs.publish && inputs.jfrog_deployment }}
89
+ run : python -m twine upload ${{ inputs.package_directory }}/dist/*
90
+ env :
91
+ TWINE_REPOSITORY_URL : https://jfrog.ledgerlabs.net/artifactory/api/pypi/embedded-apps-pypi-prod-green
92
+ TWINE_USERNAME : ${{ steps.jfrog-login.outputs.oidc-user }}
93
+ TWINE_PASSWORD : ${{ steps.jfrog-login.outputs.oidc-token }}
94
+ TWINE_NON_INTERACTIVE : 1
95
+
96
+ - name : Generate library build attestations
97
+ if : ${{ success() && inputs.publish && inputs.jfrog_deployment }}
98
+ timeout-minutes : 10
99
+ uses : LedgerHQ/actions-security/actions/attest@actions/attest-1
100
+ with :
101
+ subject-path : ${{ inputs.package_directory }}/dist/*
102
+
103
+ - name : Sign library artifacts
104
+ if : ${{ success() && inputs.publish && inputs.jfrog_deployment }}
105
+ timeout-minutes : 10
106
+ uses : LedgerHQ/actions-security/actions/sign-blob@actions/sign-blob-1
107
+ with :
108
+ path : ${{ inputs.package_directory }}/dist
109
+
110
+ - name : Publish a release on the repo
111
+ if : ${{ success() && inputs.publish }}
112
+ uses : " marvinpinto/action-automatic-releases@latest"
113
+ with :
114
+ automatic_release_tag : " v${{ env.TAG_VERSION }}"
115
+ repo_token : " ${{ secrets.GITHUB_TOKEN }}"
116
+ prerelease : false
117
+ files : |
118
+ LICENSE
119
+ CHANGELOG.md
120
+ ${{ inputs.package_directory }}/dist/
0 commit comments