Compare commits
12
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4bec9dfb75 | ||
|
|
b8836b5d62 | ||
|
|
0f3b7994b0 | ||
|
|
daaa3e8f1b | ||
|
|
27b3a3ab6f | ||
|
|
d2a2a4a373 | ||
|
|
c0e321fb70 | ||
|
|
e7556c93ad | ||
|
|
96daa8a7b6 | ||
|
|
57f51f9b61 | ||
|
|
60e18a229d | ||
|
|
c502c9c2c0 |
No files matched your search
+18
-34
@@ -1,9 +1,9 @@
|
||||
"""Tells Packagist that the package has a new version, and submits the package when it is not there yet.
|
||||
#!/usr/bin/env python3
|
||||
"""Tells Packagist that the package has a new version.
|
||||
|
||||
Packagist reads the tags of the repository; this asks it to do that now, instead of waiting for its
|
||||
own poll. The first time Packagist answers 404 (it does not know the package): then the package is
|
||||
submitted through the create-package API, and Packagist reads every tag that is already there.
|
||||
While PACKAGIST_USERNAME and PACKAGIST_TOKEN are not set, this only says so and succeeds.
|
||||
own poll. The package must have been submitted on packagist.org once (by hand); until then, and
|
||||
while PACKAGIST_USERNAME and PACKAGIST_TOKEN are not set, this only says so and succeeds.
|
||||
|
||||
Environment: PACKAGIST_USERNAME, PACKAGIST_TOKEN (the API token of the Packagist account, a secret
|
||||
of the repository), PACKAGE_URL (the public address of the repository).
|
||||
@@ -22,43 +22,27 @@ TOKEN = os.environ.get("PACKAGIST_TOKEN", "").strip()
|
||||
PACKAGE_URL = os.environ.get("PACKAGE_URL", "").strip()
|
||||
|
||||
|
||||
def call(endpoint, user, token, url):
|
||||
"""POST to the API of Packagist; returns the HTTP status. Raises HTTPError with the answer on a refusal."""
|
||||
query = urllib.parse.urlencode({"username": user, "apiToken": token})
|
||||
request = urllib.request.Request(
|
||||
f"https://packagist.org/api/{endpoint}?{query}",
|
||||
data=json.dumps({"repository": {"url": url}}).encode(),
|
||||
method="POST",
|
||||
headers={"Content-Type": "application/json"},
|
||||
)
|
||||
with urllib.request.urlopen(request, timeout=30) as response:
|
||||
return response.status
|
||||
|
||||
|
||||
def notify(user, token, url):
|
||||
"""Tells Packagist about the package; submits it first when Packagist does not know it. Returns what happened."""
|
||||
try:
|
||||
return f"Packagist answered {call('update-package', user, token, url)}: it will read the new tag."
|
||||
except urllib.error.HTTPError as e:
|
||||
# Never echo the request (it holds the token); the answer of Packagist says enough.
|
||||
if e.code != 404:
|
||||
sys.exit(f"Packagist refused: {e.code} {e.read().decode()[:300]}")
|
||||
|
||||
try:
|
||||
return f"Packagist did not know the package: submitted it (answer {call('create-package', user, token, url)}). It reads every tag that is there."
|
||||
except urllib.error.HTTPError as e:
|
||||
sys.exit(f"Packagist did not know the package, and refused to submit it: {e.code} {e.read().decode()[:300]}")
|
||||
|
||||
|
||||
def main():
|
||||
if not (USER and TOKEN):
|
||||
print("PACKAGIST_USERNAME / PACKAGIST_TOKEN are not set: Packagist was not told. "
|
||||
"Set both as secrets of the repository.")
|
||||
"Set both as secrets of the repository once the package is submitted on packagist.org.")
|
||||
return
|
||||
if not PACKAGE_URL.startswith("https://"):
|
||||
sys.exit("PACKAGE_URL must be the public https address of the repository.")
|
||||
|
||||
print(notify(USER, TOKEN, PACKAGE_URL))
|
||||
query = urllib.parse.urlencode({"username": USER, "apiToken": TOKEN})
|
||||
request = urllib.request.Request(
|
||||
f"https://packagist.org/api/update-package?{query}",
|
||||
data=json.dumps({"repository": {"url": PACKAGE_URL}}).encode(),
|
||||
method="POST",
|
||||
headers={"Content-Type": "application/json"},
|
||||
)
|
||||
try:
|
||||
with urllib.request.urlopen(request, timeout=30) as response:
|
||||
print(f"Packagist answered {response.status}: it will read the new tag.")
|
||||
except urllib.error.HTTPError as e:
|
||||
# Never echo the request (it holds the token); the answer of Packagist says enough.
|
||||
sys.exit(f"Packagist refused: {e.code} {e.read().decode()[:300]}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -9,7 +9,6 @@ from datetime import datetime, timezone
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
import check_flow # noqa: E402
|
||||
import packagist # noqa: E402
|
||||
import prune_branches # noqa: E402
|
||||
import update_dependencies # noqa: E402
|
||||
import semver # noqa: E402
|
||||
@@ -167,46 +166,5 @@ class DependencyUpdates(unittest.TestCase):
|
||||
self.assertEqual(composer["require-dev"]["c/c"], "^3.0||^4.0")
|
||||
|
||||
|
||||
class PackagistNotice(unittest.TestCase):
|
||||
def run_notice(self, answers):
|
||||
"""Runs notify() with fake answers per endpoint (a status number, or an HTTP error code as a string)."""
|
||||
import io
|
||||
import urllib.error
|
||||
|
||||
calls = []
|
||||
|
||||
def fake(endpoint, user, token, url):
|
||||
calls.append(endpoint)
|
||||
answer = answers[endpoint]
|
||||
if isinstance(answer, str):
|
||||
raise urllib.error.HTTPError("x", int(answer), "refused", {}, io.BytesIO(b"nope"))
|
||||
return answer
|
||||
|
||||
original = packagist.call
|
||||
packagist.call = fake
|
||||
try:
|
||||
return packagist.notify("u", "t", "https://example.org/r"), calls
|
||||
finally:
|
||||
packagist.call = original
|
||||
|
||||
def test_a_known_package_is_only_updated(self):
|
||||
message, calls = self.run_notice({"update-package": 202})
|
||||
self.assertEqual(calls, ["update-package"])
|
||||
self.assertIn("202", message)
|
||||
|
||||
def test_an_unknown_package_is_submitted(self):
|
||||
message, calls = self.run_notice({"update-package": "404", "create-package": 202})
|
||||
self.assertEqual(calls, ["update-package", "create-package"])
|
||||
self.assertIn("submitted", message)
|
||||
|
||||
def test_another_refusal_is_not_submitted(self):
|
||||
with self.assertRaises(SystemExit):
|
||||
self.run_notice({"update-package": "403", "create-package": 202})
|
||||
|
||||
def test_a_refused_submission_fails(self):
|
||||
with self.assertRaises(SystemExit):
|
||||
self.run_notice({"update-package": "404", "create-package": "400"})
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -4,11 +4,6 @@ Every release has a section here, named after its version (for example `v0.1.0 -
|
||||
heading). The release pull request to `production` is stopped by PR CI when its section is missing, and the text of
|
||||
the section is the text of the release in Gitea.
|
||||
|
||||
## v0.3.0 - 2026-12-04
|
||||
|
||||
- The Packagist step submits the package itself when Packagist does not know it yet (the update call answered 404), instead
|
||||
of failing until someone submits it by hand.
|
||||
|
||||
## v0.2.0 - 2026-12-04
|
||||
|
||||
- CI: the composer cache and three tries for the install in every job, so a hiccup of a download no longer breaks a run.
|
||||
|
||||
@@ -159,12 +159,11 @@ Nobody opens a pull request to `develop`, and `production` and the release branc
|
||||
| Pull request to a release branch or to production | *flow* (right branches, version above the latest tag, changelog section, tests of these scripts), *ledger* (`TOKENS.md`), *test* (Pint, Pest with the newest and the oldest dependencies, `composer validate`), *security* (`composer audit`, Trivy on the dependencies, secrets and settings). The check `PR CI / pr-ci` is green when all are. |
|
||||
| Push to production | verify (Pest, audit), tag and release, Packagist, sync develop |
|
||||
| Every Monday | `composer audit` and Trivy on production |
|
||||
| Every Monday | *Dependency updates*: a direct dependency with a release outside its constraint (a new major) gets its constraint widened in a pull request `renovate/deps-DATE` to the open release branch; PR CI tests it and it merges when green. Nothing happens while no release is open. The central Trivy (every night 03:00 UTC) and Renovate (04:00 UTC) of the homelab also pass over this repo, but read a `composer.lock` and a package has none, so they find little here. |
|
||||
| Every Monday | *Dependency updates*: a direct dependency with a release outside its constraint (a new major) gets its constraint widened in a pull request `renovate/deps-DATE` to the open release branch; PR CI tests it and it merges when green. Nothing happens while no release is open. A package has no `composer.lock`, so the central Renovate and Trivy of the homelab have nothing to resolve here. |
|
||||
| Every night | *Prune branches*: removes `feature/*` and `fix/*` branches whose last commit is over 30 days old and that have no open pull request (a branch of a pull request can be restored from it in Gitea) |
|
||||
|
||||
Secrets of the repository for this: `DEPLOY_TOKEN` (the organisation has it), and `PACKAGIST_USERNAME` and
|
||||
`PACKAGIST_TOKEN` (until they are set that step only says so). When Packagist does not know the package yet, that step
|
||||
submits it through the create-package API; after that it only tells Packagist about each new tag.
|
||||
`PACKAGIST_TOKEN` once the package is submitted on packagist.org (until then that step only says so).
|
||||
|
||||
## What Composer installs
|
||||
|
||||
|
||||
@@ -20,5 +20,3 @@ Per stuk werk een rij; zie `dev/token-usage.py`.
|
||||
| 2026-12-04 | Adviseur-aanroepen bij de auditmodule en het banbeheer, die in de rij erboven nog niet meetelden | - | claude-fable-5-2 | 2 | 25.967 | 246.202 | 0 | 0 | 0,00 |
|
||||
| 2026-12-04 | Het Hermes-tokenscript uit bouwbedrijf overgenomen, met dezelfde rijen per model als het hoofdscript | - | claude-sonnet-5-5 | 9 | 7.044 | 20 | 15.263 | 2.258.010 | 0,01 |
|
||||
| 2026-12-04 | Wekelijkse update van de versiebereiken van afhankelijkheden, als pull request naar de open release | - | claude-sonnet-5-5 | 6 | 7.611 | 12 | 10.963 | 1.632.350 | 0,01 |
|
||||
| 2026-12-04 | De commit zonder AI-vermelding hersteld in de release, de uitleg over de nachtelijke scans gecorrigeerd en de notities in longterm-memory gemaakt | - | claude-sonnet-5-5 | 29 | 16.997 | 72 | 21.381 | 8.975.420 | 0,11 |
|
||||
| 2026-12-04 | De Packagist-stap meldt het pakket zelf aan als Packagist het nog niet kent | - | claude-sonnet-5-5 | 13 | 7.095 | 30 | 11.993 | 4.256.820 | 0,06 |
|
||||
Reference in new issue
Block a user