coreapp publish, and a Gitea Actions workflow in new apps
coreapp publish builds the release image, pushes image:version to the registry named in coreapp.toml and tags the commit v<version>. It refuses local-only image names (suggesting one from the git remote), uncommitted changes, a version already published and a tag already on another commit. The existence check uses docker buildx imagetools inspect: docker manifest inspect reported "no such manifest" for an image that existed. Any error but "not found" stops the publish. New apps get .gitea/workflows/publish.yml, which does the same on a v* tag, for repositories with a runner that can use Docker (secrets REGISTRY_USER and REGISTRY_TOKEN). Untested: needs a runner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
# Publishes the app when a version tag (v0.1.0, ...) is pushed: builds the
|
||||
# image from that commit and pushes it as image:version (from coreapp.toml).
|
||||
# The same as `coreapp publish`, for repositories with a Gitea Actions
|
||||
# runner whose jobs can use Docker.
|
||||
#
|
||||
# Needs two secrets in the repository (Settings > Actions > Secrets):
|
||||
# REGISTRY_USER the Gitea user that owns the token
|
||||
# REGISTRY_TOKEN a Gitea token with the write:package scope
|
||||
name: Publish
|
||||
|
||||
on:
|
||||
push:
|
||||
tags: ["v*"]
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Read coreapp.toml
|
||||
id: app
|
||||
run: |
|
||||
python3 - >> "$GITHUB_OUTPUT" <<'PY'
|
||||
import tomllib
|
||||
with open("coreapp.toml", "rb") as f:
|
||||
m = tomllib.load(f)
|
||||
print(f"image={m['image']}")
|
||||
print(f"version={m['version']}")
|
||||
print(f"title={m['title']}")
|
||||
PY
|
||||
|
||||
- name: Check the tag and the image name
|
||||
env:
|
||||
IMAGE: ${{ steps.app.outputs.image }}
|
||||
VERSION: ${{ steps.app.outputs.version }}
|
||||
run: |
|
||||
if [ "$GITHUB_REF_NAME" != "v$VERSION" ]; then
|
||||
echo "The tag $GITHUB_REF_NAME doesn't match version = \"$VERSION\" in coreapp.toml."
|
||||
exit 1
|
||||
fi
|
||||
case "$IMAGE" in localhost/*)
|
||||
echo "image = \"$IMAGE\" in coreapp.toml is a local name; set it to the registry, e.g. gitea.example.com/owner/app."
|
||||
exit 1 ;;
|
||||
esac
|
||||
|
||||
- name: Log in to the registry
|
||||
env:
|
||||
IMAGE: ${{ steps.app.outputs.image }}
|
||||
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
||||
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||
run: echo "$REGISTRY_TOKEN" | docker login "${IMAGE%%/*}" -u "$REGISTRY_USER" --password-stdin
|
||||
|
||||
- name: Build and push
|
||||
env:
|
||||
IMAGE: ${{ steps.app.outputs.image }}
|
||||
VERSION: ${{ steps.app.outputs.version }}
|
||||
TITLE: ${{ steps.app.outputs.title }}
|
||||
run: |
|
||||
# Never replace a published version: Cores may have installed it
|
||||
# (only "not found" means it isn't there; any other error stops)
|
||||
if check="$(docker buildx imagetools inspect "$IMAGE:$VERSION" 2>&1)"; then
|
||||
echo "$IMAGE:$VERSION is already published. Raise version in coreapp.toml."
|
||||
exit 1
|
||||
fi
|
||||
case "$check" in
|
||||
*"not found"*|*"manifest unknown"*) ;;
|
||||
*) echo "Couldn't check the registry: $check"; exit 1 ;;
|
||||
esac
|
||||
docker build --platform linux/amd64 \
|
||||
--label "org.opencontainers.image.version=$VERSION" \
|
||||
--label "org.opencontainers.image.revision=$GITHUB_SHA" \
|
||||
--label "org.opencontainers.image.title=$TITLE" \
|
||||
--label "org.opencontainers.image.source=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \
|
||||
-t "$IMAGE:$VERSION" .
|
||||
docker push "$IMAGE:$VERSION"
|
||||
Reference in New Issue
Block a user