|
| 1 | +import os |
| 2 | +import pathlib |
| 3 | + |
| 4 | +import yaml |
| 5 | + |
| 6 | +DESCRIPTION = 'description' |
| 7 | +REQUIRED = 'required' |
| 8 | + |
| 9 | +EVENT = os.environ['EVENT'] |
| 10 | +REF = os.environ['REF'] |
| 11 | +REPO = os.environ['REPO'] |
| 12 | + |
| 13 | + |
| 14 | +def set_image(event: str, ref: str, repo: str) -> str: |
| 15 | + if event == 'pull_request' and 'gh-action-pypi-publish' in repo: |
| 16 | + return '../../../Dockerfile' |
| 17 | + docker_ref = ref.replace('/', '-') |
| 18 | + return f'docker://ghcr.io/{repo}:{docker_ref}' |
| 19 | + |
| 20 | + |
| 21 | +image = set_image(EVENT, REF, REPO) |
| 22 | + |
| 23 | +action = { |
| 24 | + 'name': '🏃', |
| 25 | + DESCRIPTION: ( |
| 26 | + 'Run Docker container to upload Python distribution packages to PyPI' |
| 27 | + ), |
| 28 | + 'inputs': { |
| 29 | + 'user': {DESCRIPTION: 'PyPI user', REQUIRED: False}, |
| 30 | + 'password': { |
| 31 | + DESCRIPTION: 'Password for your PyPI user or an access token', |
| 32 | + REQUIRED: False, |
| 33 | + }, |
| 34 | + 'repository-url': { |
| 35 | + DESCRIPTION: 'The repository URL to use', |
| 36 | + REQUIRED: False, |
| 37 | + }, |
| 38 | + 'packages-dir': { |
| 39 | + DESCRIPTION: 'The target directory for distribution', |
| 40 | + REQUIRED: False, |
| 41 | + }, |
| 42 | + 'verify-metadata': { |
| 43 | + DESCRIPTION: 'Check metadata before uploading', |
| 44 | + REQUIRED: False, |
| 45 | + }, |
| 46 | + 'skip-existing': { |
| 47 | + DESCRIPTION: ( |
| 48 | + 'Do not fail if a Python package distribution' |
| 49 | + ' exists in the target package index' |
| 50 | + ), |
| 51 | + REQUIRED: False, |
| 52 | + }, |
| 53 | + 'verbose': {DESCRIPTION: 'Show verbose output.', REQUIRED: False}, |
| 54 | + 'print-hash': { |
| 55 | + DESCRIPTION: 'Show hash values of files to be uploaded', |
| 56 | + REQUIRED: False, |
| 57 | + }, |
| 58 | + 'attestations': { |
| 59 | + DESCRIPTION: ( |
| 60 | + '[EXPERIMENTAL]' |
| 61 | + ' Enable experimental support for PEP 740 attestations.' |
| 62 | + ' Only works with PyPI and TestPyPI via Trusted Publishing.' |
| 63 | + ), |
| 64 | + REQUIRED: False, |
| 65 | + } |
| 66 | + }, |
| 67 | + 'runs': { |
| 68 | + 'using': 'docker', |
| 69 | + 'image': image, |
| 70 | + 'args': [ |
| 71 | + '${{ inputs.user }}', |
| 72 | + '${{ inputs.password }}', |
| 73 | + '${{ inputs.repository-url }}', |
| 74 | + '${{ inputs.packages-dir }}', |
| 75 | + '${{ inputs.verify-metadata }}', |
| 76 | + '${{ inputs.skip-existing }}', |
| 77 | + '${{ inputs.verbose }}', |
| 78 | + '${{ inputs.print-hash }}', |
| 79 | + '${{ inputs.attestations }}', |
| 80 | + ], |
| 81 | + }, |
| 82 | +} |
| 83 | + |
| 84 | +action_path = pathlib.Path('.github/actions/run-docker-container/action.yml') |
| 85 | +action_path.parent.mkdir(parents=True, exist_ok=True) |
| 86 | + |
| 87 | +with action_path.open(mode='w', encoding='utf-8') as file: |
| 88 | + yaml.dump(action, file, allow_unicode=True, sort_keys=False) |
0 commit comments