fix(release): repack zip root-level for the Composer registry #14
No files matched your search
@@ -3,6 +3,10 @@ name: release
|
|||||||
# Plugin-agnostic: owner, repo, host, package name and version come from the `github` context
|
# Plugin-agnostic: owner, repo, host, package name and version come from the `github` context
|
||||||
# and composer.json. shopware-cli runs from its official Docker image, intentionally unpinned (latest).
|
# and composer.json. shopware-cli runs from its official Docker image, intentionally unpinned (latest).
|
||||||
# RELEASE_TOKEN is the single token used for releases, assets and the Composer registry.
|
# RELEASE_TOKEN is the single token used for releases, assets and the Composer registry.
|
||||||
|
#
|
||||||
|
# Every step is idempotent (release/asset reuse, registry 409 = already published), so a failed run can
|
||||||
|
# simply be re-run and picks up where it stopped. There is deliberately no "tag exists -> skip" guard:
|
||||||
|
# it made a half-finished release (tag + release but no registry package) impossible to heal.
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -23,17 +27,17 @@ jobs:
|
|||||||
container:
|
container:
|
||||||
image: ghcr.io/shopware/shopware-cli:latest
|
image: ghcr.io/shopware/shopware-cli:latest
|
||||||
steps:
|
steps:
|
||||||
- name: Ensure helper tools (jq, curl, unzip, git)
|
- name: Ensure helper tools (jq, curl, unzip, zip, git)
|
||||||
run: |
|
run: |
|
||||||
command -v jq >/dev/null && command -v curl >/dev/null && command -v unzip >/dev/null && command -v git >/dev/null && exit 0
|
command -v jq >/dev/null && command -v curl >/dev/null && command -v unzip >/dev/null && command -v zip >/dev/null && command -v git >/dev/null && exit 0
|
||||||
(apt-get update -q && apt-get install -y -q --no-install-recommends jq curl unzip git) || apk add --no-cache jq curl unzip git
|
(apt-get update -q && apt-get install -y -q --no-install-recommends jq curl unzip zip git) || apk add --no-cache jq curl unzip zip git
|
||||||
|
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
token: ${{ secrets.RELEASE_TOKEN }}
|
token: ${{ secrets.RELEASE_TOKEN }}
|
||||||
|
|
||||||
- name: Determine version and guard against re-release
|
- name: Determine version, tag and file names
|
||||||
id: meta
|
id: meta
|
||||||
run: |
|
run: |
|
||||||
set -e
|
set -e
|
||||||
@@ -47,21 +51,13 @@ jobs:
|
|||||||
echo "tag=${TAG}"
|
echo "tag=${TAG}"
|
||||||
echo "zip=${REPO_NAME}-${TAG}.zip"
|
echo "zip=${REPO_NAME}-${TAG}.zip"
|
||||||
} >> "$GITHUB_OUTPUT"
|
} >> "$GITHUB_OUTPUT"
|
||||||
if git ls-remote --tags origin "refs/tags/${TAG}" | grep -q "${TAG}"; then
|
|
||||||
echo "skip=true" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "Tag ${TAG} already exists, nothing to release."
|
|
||||||
else
|
|
||||||
echo "skip=false" >> "$GITHUB_OUTPUT"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Reuse the zip the PR workflow already built and tested for this exact tree.
|
# Reuse the zip the PR workflow already built and tested for this exact tree.
|
||||||
- name: Tree hash of this commit
|
- name: Tree hash of this commit
|
||||||
if: steps.meta.outputs.skip == 'false'
|
|
||||||
id: tree
|
id: tree
|
||||||
run: echo "hash=$(git rev-parse "${GITHUB_SHA}^{tree}")" >> "$GITHUB_OUTPUT"
|
run: echo "hash=$(git rev-parse "${GITHUB_SHA}^{tree}")" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- name: Restore the tested zip from the PR run
|
- name: Restore the tested zip from the PR run
|
||||||
if: steps.meta.outputs.skip == 'false'
|
|
||||||
id: prebuilt
|
id: prebuilt
|
||||||
uses: actions/cache/restore@v4
|
uses: actions/cache/restore@v4
|
||||||
with:
|
with:
|
||||||
@@ -69,18 +65,16 @@ jobs:
|
|||||||
key: plugin-zip-${{ steps.tree.outputs.hash }}
|
key: plugin-zip-${{ steps.tree.outputs.hash }}
|
||||||
|
|
||||||
- name: Name the prebuilt zip
|
- name: Name the prebuilt zip
|
||||||
if: steps.meta.outputs.skip == 'false' && steps.prebuilt.outputs.cache-hit == 'true'
|
if: steps.prebuilt.outputs.cache-hit == 'true'
|
||||||
run: mv .build/package.zip ".build/${{ steps.meta.outputs.zip }}"
|
run: mv .build/package.zip ".build/${{ steps.meta.outputs.zip }}"
|
||||||
|
|
||||||
# Packages only on a cache miss; always validates and asserts what ships (guards a bad cache entry).
|
# Packages only on a cache miss; always validates and asserts what ships (guards a bad cache entry).
|
||||||
- uses: ./.gitea/actions/package
|
- uses: ./.gitea/actions/package
|
||||||
if: steps.meta.outputs.skip == 'false'
|
|
||||||
with:
|
with:
|
||||||
filename: ${{ steps.meta.outputs.zip }}
|
filename: ${{ steps.meta.outputs.zip }}
|
||||||
build: ${{ steps.prebuilt.outputs.cache-hit != 'true' }}
|
build: ${{ steps.prebuilt.outputs.cache-hit != 'true' }}
|
||||||
|
|
||||||
- name: Extract changelog section
|
- name: Extract changelog section
|
||||||
if: steps.meta.outputs.skip == 'false'
|
|
||||||
run: |
|
run: |
|
||||||
awk -v ver="${{ steps.meta.outputs.version }}" '
|
awk -v ver="${{ steps.meta.outputs.version }}" '
|
||||||
BEGIN { found=0 }
|
BEGIN { found=0 }
|
||||||
@@ -93,26 +87,54 @@ jobs:
|
|||||||
cat release-notes.md
|
cat release-notes.md
|
||||||
|
|
||||||
- name: Create Gitea release (creates the tag) and upload the zip
|
- name: Create Gitea release (creates the tag) and upload the zip
|
||||||
if: steps.meta.outputs.skip == 'false'
|
|
||||||
env:
|
env:
|
||||||
TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
set -e
|
set -e
|
||||||
API="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
|
API="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
|
||||||
BODY=$(jq -n --arg tag "${{ steps.meta.outputs.tag }}" --arg sha "$GITHUB_SHA" --rawfile notes release-notes.md \
|
TAG="${{ steps.meta.outputs.tag }}"
|
||||||
|
ZIP="${{ steps.meta.outputs.zip }}"
|
||||||
|
CODE=$(curl -s -o /tmp/release.json -w "%{http_code}" -H "Authorization: token ${TOKEN}" "${API}/releases/tags/${TAG}")
|
||||||
|
if [ "$CODE" = "200" ]; then
|
||||||
|
echo "Release ${TAG} already exists, reusing it."
|
||||||
|
else
|
||||||
|
BODY=$(jq -n --arg tag "$TAG" --arg sha "$GITHUB_SHA" --rawfile notes release-notes.md \
|
||||||
'{tag_name:$tag, target_commitish:$sha, name:$tag, body:$notes}')
|
'{tag_name:$tag, target_commitish:$sha, name:$tag, body:$notes}')
|
||||||
RELEASE_ID=$(curl -sf -H "Authorization: token ${TOKEN}" -H "Content-Type: application/json" -d "$BODY" "${API}/releases" | jq -r .id)
|
curl -sf -H "Authorization: token ${TOKEN}" -H "Content-Type: application/json" -d "$BODY" "${API}/releases" > /tmp/release.json
|
||||||
|
fi
|
||||||
|
RELEASE_ID=$(jq -r .id /tmp/release.json)
|
||||||
echo "release id: ${RELEASE_ID}"
|
echo "release id: ${RELEASE_ID}"
|
||||||
curl -sf -H "Authorization: token ${TOKEN}" \
|
if jq -e --arg n "$ZIP" '.assets[]? | select(.name == $n)' /tmp/release.json > /dev/null; then
|
||||||
-F "attachment=@.build/${{ steps.meta.outputs.zip }}" \
|
echo "Asset ${ZIP} already uploaded."
|
||||||
"${API}/releases/${RELEASE_ID}/assets?name=${{ steps.meta.outputs.zip }}" > /dev/null
|
else
|
||||||
|
curl -sf -H "Authorization: token ${TOKEN}" -F "attachment=@.build/${ZIP}" \
|
||||||
|
"${API}/releases/${RELEASE_ID}/assets?name=${ZIP}" > /dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Publish the same zip to the Composer registry
|
# Gitea's Composer registry needs composer.json at the zip root, but shopware-cli zips wrap
|
||||||
if: steps.meta.outputs.skip == 'false'
|
# everything in one top-level folder (the registry answers 400 "composer.json file is missing").
|
||||||
|
# Same prebuilt content, repacked root-level.
|
||||||
|
- name: Repack the zip for the Composer registry
|
||||||
|
run: |
|
||||||
|
set -e
|
||||||
|
rm -rf /tmp/repack && mkdir /tmp/repack
|
||||||
|
unzip -q ".build/${{ steps.meta.outputs.zip }}" -d /tmp/repack
|
||||||
|
if [ -f /tmp/repack/composer.json ]; then
|
||||||
|
ROOT=/tmp/repack
|
||||||
|
else
|
||||||
|
ROOT=$(find /tmp/repack -mindepth 1 -maxdepth 1 -type d | head -1)
|
||||||
|
fi
|
||||||
|
test -f "$ROOT/composer.json" || { echo "::error::no composer.json found in the packaged zip"; exit 1; }
|
||||||
|
OUT="$PWD/.build/composer-${{ steps.meta.outputs.zip }}"
|
||||||
|
(cd "$ROOT" && zip -qr "$OUT" .)
|
||||||
|
unzip -l "$OUT" | grep -E ' composer\.json$' > /dev/null || { echo "::error::repacked zip has no root-level composer.json"; exit 1; }
|
||||||
|
echo "repacked: $OUT"
|
||||||
|
|
||||||
|
- name: Publish to the Composer registry
|
||||||
run: |
|
run: |
|
||||||
STATUS=$(curl -s -o /tmp/composer-publish.log -w "%{http_code}" \
|
STATUS=$(curl -s -o /tmp/composer-publish.log -w "%{http_code}" \
|
||||||
-u "${GITHUB_REPOSITORY_OWNER}:${{ secrets.RELEASE_TOKEN }}" \
|
-u "${GITHUB_REPOSITORY_OWNER}:${{ secrets.RELEASE_TOKEN }}" \
|
||||||
-T ".build/${{ steps.meta.outputs.zip }}" \
|
-T ".build/composer-${{ steps.meta.outputs.zip }}" \
|
||||||
"${GITHUB_SERVER_URL}/api/packages/${GITHUB_REPOSITORY_OWNER}/composer")
|
"${GITHUB_SERVER_URL}/api/packages/${GITHUB_REPOSITORY_OWNER}/composer")
|
||||||
cat /tmp/composer-publish.log
|
cat /tmp/composer-publish.log
|
||||||
if [ "$STATUS" != "201" ] && [ "$STATUS" != "409" ]; then
|
if [ "$STATUS" != "201" ] && [ "$STATUS" != "409" ]; then
|
||||||
@@ -121,7 +143,6 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Link Composer package to this repository
|
- name: Link Composer package to this repository
|
||||||
if: steps.meta.outputs.skip == 'false'
|
|
||||||
run: |
|
run: |
|
||||||
ENCODED_NAME=$(printf '%s' "${{ steps.meta.outputs.package_name }}" | sed 's#/#%2F#g')
|
ENCODED_NAME=$(printf '%s' "${{ steps.meta.outputs.package_name }}" | sed 's#/#%2F#g')
|
||||||
STATUS=$(curl -s -o /dev/null -w "%{http_code}" -u "${GITHUB_REPOSITORY_OWNER}:${{ secrets.RELEASE_TOKEN }}" -X POST \
|
STATUS=$(curl -s -o /dev/null -w "%{http_code}" -u "${GITHUB_REPOSITORY_OWNER}:${{ secrets.RELEASE_TOKEN }}" -X POST \
|
||||||
|
|||||||
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [0.1.1] - 2026-10-04
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Release pipeline: the Composer registry rejected the packaged zip (`composer.json file is missing`) because `shopware-cli` zips wrap everything in a top-level folder. The same prebuilt content is now repacked root-level for the registry upload.
|
||||||
|
- Release steps are idempotent (existing release and asset are reused, registry 409 counts as published) and the "tag exists -> skip" guard is gone, so a failed release can be re-run to completion.
|
||||||
|
|
||||||
## [0.1.0] - 2026-10-03
|
## [0.1.0] - 2026-10-03
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
"description": "Export database dumps for Shopware 6 environments.",
|
"description": "Export database dumps for Shopware 6 environments.",
|
||||||
"type": "shopware-platform-plugin",
|
"type": "shopware-platform-plugin",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"shopware",
|
"shopware",
|
||||||
"shopware6",
|
"shopware6",
|
||||||
|
|||||||
Reference in new issue
Block a user