Skip to content

Commit fe38e2d

Browse files
committed
Use docker for notifying packagist
1 parent 5509eea commit fe38e2d

File tree

3 files changed

+122
-38
lines changed

3 files changed

+122
-38
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ To release, say `3.3.0` [Packagist](https://packagist.org/packages/transloadit/p
9292
1. Commit: `git add CHANGELOG.md composer.json && git commit -m "Release v3.3.0"`
9393
1. Tag: `git tag v3.3.0`
9494
1. Push: `git push --tags`
95-
1. Notify Packagist: `source .env && ./scripts/notify-packagist.sh`
95+
1. Notify Packagist (runs via Docker): `VERSION=3.3.0 ./scripts/notify-registry.sh`
9696
1. Publish a GitHub release (include the changelog). This triggers the release workflow. (via the GitHub UI, `gh release creates v3.3.0 --title "v3.3.0" --notes-file <(cat CHANGELOG.md section)`)
9797

98+
The notify script reuses the same Docker image as `./scripts/test-in-docker.sh`, so Docker is the only requirement on your workstation.
99+
98100
This project implements the [Semantic Versioning](http://semver.org/) guidelines.

scripts/notify-packagist.sh

Lines changed: 0 additions & 37 deletions
This file was deleted.

scripts/notify-registry.sh

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
set -o errtrace
4+
# set -o xtrace
5+
6+
IMAGE_NAME=${IMAGE_NAME:-transloadit-php-sdk-dev}
7+
CACHE_DIR=.docker-cache
8+
9+
ensure_docker() {
10+
if ! command -v docker >/dev/null 2>&1; then
11+
echo "Docker is required to run this script." >&2
12+
exit 1
13+
fi
14+
15+
if ! docker info >/dev/null 2>&1; then
16+
if [[ -z "${DOCKER_HOST:-}" && -S "$HOME/.colima/default/docker.sock" ]]; then
17+
export DOCKER_HOST="unix://$HOME/.colima/default/docker.sock"
18+
fi
19+
fi
20+
21+
if ! docker info >/dev/null 2>&1; then
22+
echo "Docker daemon is not reachable. Start Docker (or Colima) and retry." >&2
23+
exit 1
24+
fi
25+
}
26+
27+
configure_platform() {
28+
if [[ -z "${DOCKER_PLATFORM:-}" ]]; then
29+
local arch
30+
arch=$(uname -m)
31+
if [[ "$arch" == "arm64" || "$arch" == "aarch64" ]]; then
32+
DOCKER_PLATFORM=linux/amd64
33+
fi
34+
fi
35+
}
36+
37+
if [[ "${1:-}" != "--inside-container" ]]; then
38+
ensure_docker
39+
configure_platform
40+
41+
mkdir -p "$CACHE_DIR/composer-cache" "$CACHE_DIR/npm-cache" "$CACHE_DIR/composer-home"
42+
43+
BUILD_ARGS=()
44+
if [[ -n "${DOCKER_PLATFORM:-}" ]]; then
45+
BUILD_ARGS+=(--platform "$DOCKER_PLATFORM")
46+
fi
47+
BUILD_ARGS+=(-t "$IMAGE_NAME" -f Dockerfile .)
48+
49+
docker build "${BUILD_ARGS[@]}"
50+
51+
DOCKER_ARGS=(
52+
--rm
53+
--user "$(id -u):$(id -g)"
54+
-e HOME=/workspace
55+
-e COMPOSER_HOME=/workspace/$CACHE_DIR/composer-home
56+
-e COMPOSER_CACHE_DIR=/workspace/$CACHE_DIR/composer-cache
57+
-e npm_config_cache=/workspace/$CACHE_DIR/npm-cache
58+
-v "$PWD":/workspace
59+
-w /workspace
60+
)
61+
62+
if [[ -n "${DOCKER_PLATFORM:-}" ]]; then
63+
DOCKER_ARGS+=(--platform "$DOCKER_PLATFORM")
64+
fi
65+
66+
if [[ -f .env ]]; then
67+
DOCKER_ARGS+=(--env-file "$PWD/.env")
68+
fi
69+
70+
if [[ -n "${PACKAGIST_TOKEN:-}" ]]; then
71+
DOCKER_ARGS+=(-e "PACKAGIST_TOKEN=${PACKAGIST_TOKEN}")
72+
fi
73+
74+
if [[ -n "${VERSION:-}" ]]; then
75+
DOCKER_ARGS+=(-e "VERSION=${VERSION}")
76+
fi
77+
78+
exec docker run "${DOCKER_ARGS[@]}" "$IMAGE_NAME" bash -lc "./scripts/notify-registry.sh --inside-container"
79+
fi
80+
81+
shift
82+
83+
if [[ -z "${PACKAGIST_TOKEN:-}" ]]; then
84+
if [[ -f .env ]]; then
85+
# shellcheck disable=SC1091
86+
source .env || {
87+
echo "Failed to source .env"
88+
exit 1
89+
}
90+
fi
91+
if [[ -z "${PACKAGIST_TOKEN:-}" ]]; then
92+
echo "PACKAGIST_TOKEN is not set"
93+
exit 1
94+
fi
95+
fi
96+
97+
if [[ -z "${VERSION:-}" ]]; then
98+
echo "VERSION is not set"
99+
exit 1
100+
fi
101+
102+
if ! grep "${VERSION}" composer.json > /dev/null 2>&1; then
103+
echo "First add '${VERSION}' to composer.json please"
104+
exit 1
105+
fi
106+
if ! grep "${VERSION}" CHANGELOG.md > /dev/null 2>&1; then
107+
echo "First add '${VERSION}' to CHANGELOG.md please"
108+
exit 1
109+
fi
110+
if [[ -n "$(git status --porcelain)" ]]; then
111+
echo "Git working tree not clean. First commit all your work please."
112+
exit 1
113+
fi
114+
115+
curl \
116+
-X POST \
117+
-H 'Content-Type: application/json' \
118+
-d '{"repository":{"url":"https://github.com/transloadit/php-sdk"}}' \
119+
"https://packagist.org/api/update-package?username=kvz&apiToken=${PACKAGIST_TOKEN}"

0 commit comments

Comments
 (0)