Skip to content

Commit

Permalink
Merge branch 'maintenance/kebab-case-inputs' into unstable/v1
Browse files Browse the repository at this point in the history
This patch normalizes the action inputs to be kebab-case while keeping
the old snake_case fallbacks working.
  • Loading branch information
webknjaz committed Mar 11, 2023
2 parents 32b5e93 + f131721 commit 7104b6e
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/self-smoke-test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
with:
user: ${{ env.devpi-username }}
password: ${{ env.devpi-password }}
repository_url: >-
repository-url: >-
http://devpi:${{ env.devpi-port }}/${{ env.devpi-username }}/public/
...
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ project's specific needs.
For example, you could implement a parallel workflow that
pushes every commit to TestPyPI or your own index server,
like `devpi`. For this, you'd need to (1) specify a custom
`repository_url` value and (2) generate a unique version
`repository-url` value and (2) generate a unique version
number for each upload so that they'd not create a conflict.
The latter is possible if you use `setuptools_scm` package but
you could also invent your own solution based on the distance
Expand All @@ -114,7 +114,7 @@ The action invocation in this case would look like:
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
repository-url: https://test.pypi.org/legacy/
```

### Customizing target package dists directory
Expand All @@ -128,7 +128,7 @@ would now look like:
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
packages_dir: custom-dir/
packages-dir: custom-dir/
```

### Disabling metadata verification
Expand All @@ -139,7 +139,7 @@ check with:

```yml
with:
verify_metadata: false
verify-metadata: false
```

### Tolerating release package file duplicates
Expand All @@ -149,12 +149,12 @@ may hit race conditions. For example, when publishing from multiple CIs
or even having workflows with the same steps triggered within GitHub
Actions CI/CD for different events concerning the same high-level act.

To facilitate this use-case, you may use `skip_existing` (disabled by
To facilitate this use-case, you may use `skip-existing` (disabled by
default) setting as follows:

```yml
with:
skip_existing: true
skip-existing: true
```

> **Pro tip**: try to avoid enabling this setting where possible. If you
Expand All @@ -177,7 +177,7 @@ It will show SHA256, MD5, BLAKE2-256 values of files to be uploaded.

```yml
with:
print_hash: true
print-hash: true
```

### Specifying a different username
Expand Down
65 changes: 55 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,76 @@ inputs:
password:
description: Password for your PyPI user or an access token
required: true
repository_url:
repository-url: # Canonical alias for `repository_url`
description: The repository URL to use
required: false
packages_dir:
repository_url: # DEPRECATED ALIAS; TODO: Remove in v3+
description: >-
[DEPRECATED]
The repository URL to use
deprecationMessage: >-
The inputs have been normalized to use kebab-case.
Use `repository-url` instead.
required: false
packages-dir: # Canonical alias for `packages_dir`
description: The target directory for distribution
required: false
default: dist
verify_metadata:
packages_dir: # DEPRECATED ALIAS; TODO: Remove in v3+
description: >-
[DEPRECATED]
The target directory for distribution
deprecationMessage: >-
The inputs have been normalized to use kebab-case.
Use `packages-dir` instead.
required: false
default: dist
verify-metadata: # Canonical alias for `verify_metadata`
description: Check metadata before uploading
required: false
default: 'true'
skip_existing:
verify_metadata: # DEPRECATED ALIAS; TODO: Remove in v3+
description: >-
[DEPRECATED]
Check metadata before uploading
deprecationMessage: >-
The inputs have been normalized to use kebab-case.
Use `verify-metadata` instead.
required: false
default: 'true'
skip-existing: # Canonical alias for `skip_existing`
description: >-
Do not fail if a Python package distribution
exists in the target package index
required: false
default: 'false'
skip_existing: # DEPRECATED ALIAS; TODO: Remove in v3+
description: >-
[DEPRECATED]
Do not fail if a Python package distribution
exists in the target package index
deprecationMessage: >-
The inputs have been normalized to use kebab-case.
Use `skip-existing` instead.
required: false
default: 'false'
verbose:
description: Show verbose output.
required: false
default: 'false'
print_hash:
print-hash: # Canonical alias for `print_hash`
description: Show hash values of files to be uploaded
required: false
default: 'false'
print_hash: # DEPRECATED ALIAS; TODO: Remove in v3+
description: >-
[DEPRECATED]
Show hash values of files to be uploaded
deprecationMessage: >-
The inputs have been normalized to use kebab-case.
Use `print-hash` instead.
required: false
default: 'false'
branding:
color: yellow
icon: upload-cloud
Expand All @@ -43,9 +88,9 @@ runs:
args:
- ${{ inputs.user }}
- ${{ inputs.password }}
- ${{ inputs.repository_url }}
- ${{ inputs.packages_dir }}
- ${{ inputs.verify_metadata }}
- ${{ inputs.skip_existing }}
- ${{ inputs.repository-url }}
- ${{ inputs.packages-dir }}
- ${{ inputs.verify-metadata }}
- ${{ inputs.skip-existing }}
- ${{ inputs.verbose }}
- ${{ inputs.print_hash }}
- ${{ inputs.print-hash }}
20 changes: 20 additions & 0 deletions twine-upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,26 @@ export PATH="$(python -m site --user-base)/bin:${PATH}"
export PYTHONPATH="$(python -m site --user-site):${PYTHONPATH}"


function get-normalized-input() {
local var_name=${1}
python -c \
'
from os import getenv
from sys import argv
envvar_name = f"INPUT_{argv[1].upper()}"
print(getenv(envvar_name, getenv(envvar_name.replace("-", "_"), "")), end="")
' \
"${var_name}"
}


INPUT_REPOSITORY_URL="$(get-normalized-input 'repository-url')"
INPUT_PACKAGES_DIR="$(get-normalized-input 'packages-dir')"
INPUT_VERIFY_METADATA="$(get-normalized-input 'verify-metadata')"
INPUT_SKIP_EXISTING="$(get-normalized-input 'skip-existing')"
INPUT_PRINT_HASH="$(get-normalized-input 'print-hash')"


if [[
"$INPUT_USER" == "__token__" &&
! "$INPUT_PASSWORD" =~ ^pypi-
Expand Down

0 comments on commit 7104b6e

Please sign in to comment.