-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
206 lines (169 loc) · 7.07 KB
/
Copy pathaction.yml
File metadata and controls
206 lines (169 loc) · 7.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
name: 'Publish to GitLab PyPI Package Registry'
description: >
Uploads Python distributions (wheels and/or sdists) from a GitHub Actions
runner to a GitLab PyPI Package Registry endpoint via twine. Packages
uploaded here are pip-discoverable through the /packages/pypi/simple
index — unlike the Generic Package Registry, which cannot be consumed
by pip.
inputs:
# ── Required ────────────────────────────────────────────────────────────────
gitlab-username:
description: >
Username for basic auth against the GitLab PyPI endpoint. For a
deploy token this is the token name (e.g.
"gitlab+deploy-token-12345"). For a personal access token use
"__token__" (or any placeholder).
required: true
gitlab-token:
description: >
GitLab authentication token used as the password for basic auth.
Use a Personal Access Token (scope: api) or a Deploy Token (scope:
write_package_registry). Store as a GitHub Actions secret; never
hard-code.
required: true
gitlab-project-id:
description: >
Numeric ID of the target GitLab project (Settings → General →
Project ID).
required: true
# files is a newline-separated list of glob patterns resolved by the runner.
files:
description: >
Newline-separated list of file paths (or globs) to upload. Each
matched file is uploaded as a separate PyPI distribution. Example:
files: |
dist/*.whl
dist/*.tar.gz
required: true
# ── Optional ────────────────────────────────────────────────────────────────
gitlab-host:
description: >
Base URL of the GitLab instance. Override for self-hosted GitLab.
required: false
default: 'https://gitlab.com'
skip-existing:
description: >
When "true", pass --skip-existing to twine so files that already
exist in the registry are silently skipped instead of failing the
upload. Default "false".
required: false
default: 'false'
twine-version:
description: >
Pin a specific twine version for reproducibility. Passed to
`uvx --from twine==<ver>`. Leave empty to use the latest.
required: false
default: ''
outputs:
registry-url:
description: >
URL of the PyPI package listing in the GitLab UI.
value: >-
${{ inputs.gitlab-host }}/-/packages
uploaded-files:
description: Newline-separated list of files that twine successfully uploaded.
value: ${{ steps.upload.outputs.uploaded_files }}
runs:
using: 'composite'
steps:
# ── 1. Validate inputs ───────────────────────────────────────────────────
- name: Validate inputs
shell: bash
run: |
echo "::group::Validating inputs"
error=0
if [[ -z "${{ inputs.gitlab-username }}" ]]; then
echo "::error::Input 'gitlab-username' must not be empty."
error=1
fi
if [[ -z "${{ inputs.gitlab-token }}" ]]; then
echo "::error::Input 'gitlab-token' must not be empty."
error=1
fi
if [[ ! "${{ inputs.gitlab-project-id }}" =~ ^[0-9]+$ ]]; then
echo "::error::Input 'gitlab-project-id' must be a numeric project ID."
error=1
fi
SKIP_EXISTING="${{ inputs.skip-existing }}"
if [[ "$SKIP_EXISTING" != "true" && "$SKIP_EXISTING" != "false" ]]; then
echo "::error::Input 'skip-existing' must be 'true' or 'false'. Got: $SKIP_EXISTING"
error=1
fi
if [[ $error -eq 1 ]]; then
echo "::endgroup::"
exit 1
fi
echo "All inputs validated successfully."
echo "::endgroup::"
# ── 2. Ensure uv is available (provides uvx for one-shot twine runs) ─────
- name: Set up uv
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
with:
enable-cache: false
# ── 3. Resolve globs and upload via twine ────────────────────────────────
- name: Upload files
id: upload
shell: bash
env:
TWINE_USERNAME: ${{ inputs.gitlab-username }}
TWINE_PASSWORD: ${{ inputs.gitlab-token }}
TWINE_REPOSITORY_URL: ${{ inputs.gitlab-host }}/api/v4/projects/${{ inputs.gitlab-project-id }}/packages/pypi
TWINE_NON_INTERACTIVE: '1'
run: |
echo "::group::Resolving file globs"
matched_files=()
while IFS= read -r pattern; do
[[ -z "$pattern" ]] && continue
expanded=( $pattern )
if [[ ${#expanded[@]} -eq 0 ]] || [[ ! -e "${expanded[0]}" ]]; then
echo "::warning::Pattern '${pattern}' did not match any files — skipping."
continue
fi
for filepath in "${expanded[@]}"; do
if [[ ! -f "$filepath" ]]; then
echo "::warning::'${filepath}' is not a regular file — skipping."
continue
fi
matched_files+=("$filepath")
done
done <<< "${{ inputs.files }}"
if [[ ${#matched_files[@]} -eq 0 ]]; then
echo "::error::No files matched the provided globs; nothing to upload."
echo "::endgroup::"
exit 1
fi
printf 'Matched %d file(s):\n' "${#matched_files[@]}"
printf ' %s\n' "${matched_files[@]}"
echo "::endgroup::"
echo "::group::Uploading via twine"
twine_from='twine'
if [[ -n "${{ inputs.twine-version }}" ]]; then
twine_from="twine==${{ inputs.twine-version }}"
fi
skip_flag=''
if [[ "${{ inputs.skip-existing }}" == 'true' ]]; then
skip_flag='--skip-existing'
fi
uvx --from "$twine_from" twine upload \
--disable-progress-bar \
$skip_flag \
"${matched_files[@]}"
echo "::endgroup::"
# Emit uploaded_files output
{
echo "uploaded_files<<EOF"
printf '%s\n' "${matched_files[@]}"
echo "EOF"
} >> "$GITHUB_OUTPUT"
# ── 4. Annotate the workflow run summary ─────────────────────────────────
- name: Print registry URL
shell: bash
run: |
echo "### GitLab PyPI Package Registry" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "**Registry endpoint:** \`${{ inputs.gitlab-host }}/api/v4/projects/${{ inputs.gitlab-project-id }}/packages/pypi\`" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "**Uploaded files:**" >> "$GITHUB_STEP_SUMMARY"
while IFS= read -r f; do
[[ -n "$f" ]] && echo "- \`$f\`" >> "$GITHUB_STEP_SUMMARY"
done <<< "${{ steps.upload.outputs.uploaded_files }}"