-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86086c2
commit 6ade446
Showing
2 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
name: Reusable conda package builder | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
package_name: | ||
description: "Name of Python package name being built" | ||
required: true | ||
type: string | ||
version: | ||
description: "Version to be packaged and uploaded" | ||
required: false | ||
type: string | ||
default: ${{ github.ref_name }} | ||
secrets: | ||
TEST_PYPI_API_TOKEN: | ||
required: true | ||
|
||
defaults: | ||
run: | ||
shell: bash -l {0} | ||
|
||
jobs: | ||
pip-build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: check if TEST_PYPI_API_TOKEN exists | ||
env: | ||
# cannot use secrets directly in conditionals | ||
# see https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#using-secrets-in-a-workflow | ||
test_pypi_token: ${{ secrets.TEST_PYPI_API_TOKEN }} | ||
if: env.test_pypi_token == '' | ||
run: | | ||
echo "the secret \"TEST_PYPI_API_TOKEN\" is not available, so the pypi package cannot be uploaded to the test index site." | ||
echo "Please go to \"settings \> secrets \> actions\" to create it before trying to build the pip package." | ||
exit 1 | ||
- uses: actions/checkout@v3 | ||
- uses: mamba-org/setup-micromamba@v1 | ||
with: | ||
micromamba-version: latest | ||
environment-name: pipbuild | ||
create-args: >- | ||
python=3.11 | ||
pip | ||
build | ||
post-cleanup: all | ||
cache-environment: true | ||
|
||
- name: Build package | ||
run: python -m build | ||
|
||
- name: Publish distribution 📦 to TestPyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
password: ${{ secrets.TEST_PYPI_API_TOKEN }} | ||
repository-url: https://test.pypi.org/legacy/ | ||
|
||
- name: Get version without the v | ||
run: | | ||
TAG=${{ inputs.version }} | ||
echo "VERSION=${TAG#v}" >> $GITHUB_ENV | ||
- name: try installing from TestPyPI | ||
run: | | ||
cd ${{ runner.temp }} | ||
pip install -i https://test.pypi.org/simple/ --no-deps ${{ inputs.package_name }}==${{ env.VERSION }} | ||
- name: Create built package artifact ready for upload on release | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: pip-build-${{ inputs.package_name }}-${{ inputs.version }} | ||
path: dist/* | ||
retention-days: 7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
on: | ||
workflow_call: | ||
inputs: | ||
package_name: | ||
description: "Name of Python package name being uploaded" | ||
required: true | ||
type: string | ||
build_workflow: | ||
description: "Name of workflow file used to build the package initially, if different from current workflow" | ||
required: false | ||
type: string | ||
default: "" | ||
version: | ||
description: "Version to be packaged and uploaded" | ||
required: false | ||
type: string | ||
default: ${{ github.ref_name }} | ||
secrets: | ||
PYPI_API_TOKEN: | ||
required: true | ||
|
||
defaults: | ||
run: | ||
shell: bash -l {0} | ||
|
||
jobs: | ||
pip-publish: | ||
runs-on: ubuntu-latest | ||
env: | ||
PACKAGENAME: "pip-build-${{ inputs.package_name }}-${{ inputs.version }}" | ||
|
||
steps: | ||
- name: check if PYPI_API_TOKEN exists | ||
env: | ||
# cannot use secrets directly in conditionals | ||
# see https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#using-secrets-in-a-workflow | ||
pypi_token: ${{ secrets.PYPI_API_TOKEN }} | ||
if: env.pypi_token == '' | ||
run: | | ||
echo "the secret \"PYPI_API_TOKEN\" is not available, so the pypi package cannot be uploaded to the test index site." | ||
echo "Please go to \"settings \> secrets \> actions\" to create it before trying to build the pip package." | ||
exit 1 | ||
- name: Download built package from another workflow | ||
if: inputs.build_workflow != '' | ||
uses: dawidd6/action-download-artifact@v2 | ||
with: | ||
name: ${{ env.PACKAGENAME }} | ||
workflow: ${{ inputs.build_workflow }} | ||
path: dist/ | ||
|
||
- name: Download built package from same workflow | ||
if: inputs.build_workflow == '' | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: ${{ env.PACKAGENAME }} | ||
path: dist/ | ||
|
||
- name: Publish distribution 📦 to PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
password: ${{ secrets.PYPI_API_TOKEN }} |