forked from DataDog/integrations-core
-
Notifications
You must be signed in to change notification settings - Fork 1
106 lines (88 loc) · 3.27 KB
/
Copy pathclaim-pypi-name.yaml
File metadata and controls
106 lines (88 loc) · 3.27 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
# This workflow claims package names on PyPI for our integrations by publishing empty packages.
# The working packages can be found here:
# https://dd-integrations-core-wheels-build-stable.datadoghq.com/targets/simple/index.html
# This is a work-around until PyPI adds support for namespaces and we claim an entire namespace for Datadog.
name: Build Placeholder PyPI Packages
on:
schedule:
# At 3AM UTC
# Running this every night strikes a good balance between claiming names fast without spamming PyPI with requests.
- cron: "0 3 * * *"
env:
PYTHON_VERSION: "3.13"
defaults:
run:
shell: bash
jobs:
find-new-integrations:
name: Find unclaimed PyPI packages
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
packages: ${{ steps.find.outputs.packages }}
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Set up Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: "${{ env.PYTHON_VERSION }}"
- name: Find unclaimed packages
id: find
run: |
packages=()
shopt -s nullglob
for pyproject in */pyproject.toml; do
pkg=$(python -c "import tomllib, pathlib; data = tomllib.loads(pathlib.Path('${pyproject}').read_text()); print(data['project']['name'])")
status=$(curl -s -o /dev/null -w "%{http_code}" "https://pypi.org/pypi/${pkg}/json")
if [ "$status" = "404" ]; then
packages+=("\"${pkg}\"")
elif [ "$status" != "200" ]; then
echo "PyPI returned unexpected HTTP status ${status} for package ${pkg}. Please re-run this job." >&2
exit 1
fi
done
echo "packages=[$(IFS=,; echo "${packages[*]}")]" >> "$GITHUB_OUTPUT"
publish:
name: Publish ${{ matrix.package }}
needs: find-new-integrations
if: needs.find-new-integrations.outputs.packages != '[]'
runs-on: ubuntu-latest
environment: publish-pypi
permissions:
id-token: write
strategy:
matrix:
package: ${{ fromJson(needs.find-new-integrations.outputs.packages) }}
steps:
- name: Set up Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: "${{ env.PYTHON_VERSION }}"
- name: Install Build Deps
run: pip install -U build[virtualenv] hatchling
- name: Build Package
env:
PACKAGE_NAME: ${{ matrix.package }}
run: |
mkdir -p dist pkg_placeholder
cat > pkg_placeholder/pyproject.toml << EOF
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "${PACKAGE_NAME}"
version = "0.0.1"
[tool.hatch.build.targets.wheel]
bypass-selection = true
EOF
python -m build --no-isolation --wheel pkg_placeholder
mv pkg_placeholder/dist/* dist/
- name: Push Python artifacts to PyPI
uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2
with:
# We don't mind invalid metadata, we only want to claim the package name.
verify-metadata: false
verbose: true
skip-existing: true