Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pdm): detect libraries and JFrog support to avoid failures #260

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pdm/init/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ jobs:
| `has_docker` | Whether the project a Docker image (aka. a `Dockerfile` present at root) |
| `has_src` | Whether the project is using a `src` layout or not |
| `has_backstage` | Whether the project is exposing Backstage catalog infos |
| `is_distribution` | Whether the project is a distribution or not |
| `is_pr` | Is the current workflow run a pull-request |
| `branch` | The branch from which workflow has been triggered |
| `has_jfrog` | Whether this project uses JFrog Artifactory or not |
| `jfrog-domain` | Base domain of Ledger's JFrog platform if authenticated |
| `jfrog-url` | Base URL of Ledger's JFrog platform if authenticated |
| `jfrog-user` | Username extracted from the OIDC token if authenticated |
Expand Down
19 changes: 18 additions & 1 deletion pdm/init/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,18 @@ outputs:
has_backstage:
description: Whether the project is exposing Backstage catalog infos
value: ${{ steps.meta.outputs.has_backstage }}
is_distribution:
description: Whether the project is a distribution or not
value: ${{ steps.meta.outputs.is_distribution }}
is_pr:
description: Is the current workflow run a pull-request
value: ${{ steps.meta.outputs.is_pr }}
branch:
description: The branch from which workflow has been triggered
value: ${{ steps.meta.outputs.branch }}
has_jfrog:
description: Whether this project uses JFrog Artifactory or not
value: ${{ steps.detect-jfrog.outputs.has_jfrog }}
jfrog-domain:
description: Base domain of Ledger's JFrog platform if authenticated
value: ${{ steps.jfrog-login.outputs.jfrog-domain }}
Expand Down Expand Up @@ -88,9 +94,17 @@ runs:
git config user.email [email protected]
shell: bash

- name: detect-jfrog
id: detect-jfrog
run: |
: Detect JFrog requirement
HAS_JFROG=$(grep "jfrog" pyproject.toml > /dev/null && echo "true" || echo "false")
echo "has_jfrog=${HAS_JFROG}" >> $GITHUB_OUTPUT
shell: bash

- name: Authenticate against JFrog Artifactory
id: jfrog-login
if: env.JFROG_REPOSITORY
if: steps.detect-jfrog.outputs.has_jfrog == 'true' || env.JFROG_REPOSITORY
uses: LedgerHQ/actions-security/actions/jfrog-login@actions/jfrog-login-1

- name: Set up Python and PDM
Expand Down Expand Up @@ -155,6 +169,9 @@ runs:

IS_PR="${{ github.event_name == 'pull_request' }}"
echo "is_pr=${IS_PR}" >> $GITHUB_OUTPUT

IS_DIST==$(grep -E "distribution\s*=\s*true" pyproject.toml > /dev/null && echo "true" || echo "false")
echo "is_distribution=${IS_DIST}" >> $GITHUB_OUTPUT
env:
PYPI_DEPLOY_TOKEN: ${{ inputs.pypi-token }}
shell: bash
6 changes: 3 additions & 3 deletions pdm/release/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ jobs:

| Input | Description | Default | Required |
|-------|-------------|---------|----------|
| `kind` | Kind of project to release (lib/app) | `app` | `true` |
| `kind` | DEPRECATED (Set `tool.pdm.distribution=true` on libraries) | `app` | `false` |
| `pypi-token` | A Token to publish on PyPI (private or public) | `""` | `false` |
| `github-token` | A Github token with proper permissions | `""` | `true` |
| `increment` | Kind of increment (optional: `MAJOR\|MINOR\|PATCH`) | `""` | `false` |
| `group` | Dependency group(s) to install | `docs` | `false` |
| `exclude-group` | Dependency group(s) to exclude from install | `""` | `false` |
| `public` | Is it a public library ? | `false` | `false` |
| `dgoss-args` | `dgoss` extra docker parameters | `""` | `false` |
| `artifactory-repository` | Artifactory repository to publish to (deprecated for `JFROG_REPOSITORY`) | `""` | `false` |
| `artifactory-repository` | DEPRECATED (Use `JFROG_REPOSITORY` environment variable) | `""` | `false` |
| `docker-name` | Optionally override the docker image name (default to the repository name) | `""` | `false` |
| `extra-docker` | An optional extra docker image to build | `""` | `false` |

## Environment variables

| Variable | Description |
|--------|-------------|
| `JFROG_REPOSITORY` | JFrog repository used to fetch internal dependencies (triggers authentication) |
| `JFROG_REPOSITORY` | JFrog repository to publish libraries on (triggers authentication and publication) |
| `JFROG_DOCKER_REPOSITORY` | JFrog repository to publish images to (triggers authentication and publication) |

## Outputs
Expand Down
22 changes: 10 additions & 12 deletions pdm/release/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ description: |

inputs:
kind:
description: Kind of project to release (lib/app)
required: true
default: app
description: DEPRECATED (Set `tool.pdm.distribution=true` on libraries)
default: ""
pypi-token:
description: A Token to publish on PyPI (private or public)
required: false
Expand All @@ -38,7 +37,7 @@ inputs:
description: "`dgoss` extra docker parameters"
default: ""
artifactory-repository:
description: Artifactory repository to publish to (deprecated for `JFROG_REPOSITORY`)
description: DEPRECATED (Use `JFROG_REPOSITORY` environment variable)
default: ""
docker-name:
description: Optionally override the docker image name (default to the repository name)
Expand Down Expand Up @@ -76,6 +75,9 @@ runs:
echo "⚠️ \`artifactory-repository\` input is deprecated, use the \`JFROG_REPOSITORY\` environment variable"
echo "JFROG_REPOSITORY=${{ inputs.artifactory-repository }}" >> $GITHUB_ENV
fi
if [ "${{ inputs.kind }}" != "" ]; then
echo "⚠️ \`input\` input is deprecated, set \`tool.pdm.distribution=true\` in \`pyproject.toml\` instead"
fi
shell: bash
- name: Clone and install dependencies
uses: LedgerHQ/actions/pdm/init@main
Expand Down Expand Up @@ -108,7 +110,7 @@ runs:

# Build once to publish the same package on every repository
- name: Build distribution
if: inputs.kind == 'lib'
if: inputs.kind == 'lib' || steps.meta.outputs.is_distribution == 'true'
run: |
: Build distribution
pdm build
Expand All @@ -126,7 +128,7 @@ runs:

- name: Push to GemFury
id: gemfury
if: inputs.kind == 'lib' && inputs.public != 'true' && env.PDM_PUBLISH_USERNAME != null
if: (inputs.kind == 'lib' || steps.meta.outputs.is_distribution == 'true') && inputs.public != 'true' && env.PDM_PUBLISH_USERNAME != null
env:
PDM_PUBLISH_REPO: https://push.fury.io/ledger
PDM_PUBLISH_USERNAME: ${{ inputs.pypi-token }}
Expand All @@ -137,13 +139,9 @@ runs:
pdm publish --no-build
shell: bash

- name: Login to JFrog Ledger
if: inputs.kind == 'lib' && inputs.public != 'true'
uses: LedgerHQ/actions-security/actions/jfrog-login@actions/jfrog-login-1

- name: Push to our internal JFrog Artifactory
id: artifactory
if: inputs.kind == 'lib' && inputs.public != 'true' && env.JFROG_URL
if: (inputs.kind == 'lib' || steps.meta.outputs.is_distribution == 'true') && inputs.public != 'true' && env.JFROG_REPOSITORY
env:
PDM_PUBLISH_REPO: ${{ env.JFROG_URL }}/artifactory/api/pypi/${{ env.JFROG_REPOSITORY }}
PDM_PUBLISH_USERNAME: ${{ env.JFROG_USER }}
Expand All @@ -168,7 +166,7 @@ runs:

- name: Push to PyPI
id: pypi
if: inputs.kind == 'lib' && inputs.public == 'true' && env.PDM_PUBLISH_PASSWORD != null
if: (inputs.kind == 'lib' || steps.meta.outputs.is_distribution == 'true') && inputs.public == 'true' && env.PDM_PUBLISH_PASSWORD != null
env:
PDM_PUBLISH_PASSWORD: ${{ inputs.pypi-token }}
FORCE_COLOR: 'true'
Expand Down
Loading