Fix GitHub Actions workflow: remove invalid github context from inputs, add Docker caching, and cleanup old packages

This commit is contained in:
southseact-3d
2026-02-10 12:07:04 +00:00
parent ec3aa6a6b5
commit 6dda179e7e

View File

@@ -14,7 +14,6 @@ on:
image_name: image_name:
description: "Docker image name (including registry if desired)" description: "Docker image name (including registry if desired)"
required: false required: false
default: "ghcr.io/${{ github.repository_owner }}/shopify-ai-builder"
push_image: push_image:
description: "Push the image to the registry" description: "Push the image to the registry"
type: boolean type: boolean
@@ -23,6 +22,7 @@ on:
permissions: permissions:
contents: read contents: read
packages: write packages: write
actions: read
jobs: jobs:
build-cli: build-cli:
@@ -84,6 +84,18 @@ jobs:
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=moby/buildkit:latest
buildkitd-flags: --debug
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to GHCR - name: Login to GHCR
if: ${{ env.PUSH_IMAGE == 'true' }} if: ${{ env.PUSH_IMAGE == 'true' }}
@@ -98,16 +110,62 @@ jobs:
run: | run: |
docker buildx build \ docker buildx build \
--platform linux/amd64,linux/arm64 \ --platform linux/amd64,linux/arm64 \
--cache-from type=local,src=/tmp/.buildx-cache \
--cache-to type=local,dest=/tmp/.buildx-cache-new,mode=max \
-t "$IMAGE_NAME" \ -t "$IMAGE_NAME" \
--push \ --push \
. .
- name: Move cache
if: ${{ env.PUSH_IMAGE == 'true' }}
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Build image (amd64) and verify CLI - name: Build image (amd64) and verify CLI
if: ${{ env.PUSH_IMAGE != 'true' }} if: ${{ env.PUSH_IMAGE != 'true' }}
run: | run: |
docker buildx build \ docker buildx build \
--platform linux/amd64 \ --platform linux/amd64 \
--cache-from type=local,src=/tmp/.buildx-cache \
--cache-to type=local,dest=/tmp/.buildx-cache-new,mode=max \
-t "$IMAGE_NAME" \ -t "$IMAGE_NAME" \
--load \ --load \
. .
docker run --rm "$IMAGE_NAME" opencode --version docker run --rm "$IMAGE_NAME" opencode --version
- name: Move cache
if: ${{ env.PUSH_IMAGE != 'true' }}
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Cleanup old package versions
if: ${{ env.PUSH_IMAGE == 'true' && github.event_name == 'push' }}
uses: actions/github-script@v7
with:
script: |
const packageName = 'shopify-ai-builder';
const packageType = 'container';
// List all versions of the package
const { data: versions } = await github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({
package_type: packageType,
package_name: packageName,
org: context.repo.owner,
per_page: 100
});
// Keep only the most recent version, delete the rest
if (versions.length > 1) {
const versionsToDelete = versions.slice(1);
for (const version of versionsToDelete) {
await github.rest.packages.deletePackageVersionForOrg({
package_type: packageType,
package_name: packageName,
org: context.repo.owner,
package_version_id: version.id
});
console.log(`Deleted package version ${version.id}`);
}
}