diff --git a/.gitea/workflows/backend-image.yml b/.gitea/workflows/backend-image.yml index 184498a..7d7c7c4 100644 --- a/.gitea/workflows/backend-image.yml +++ b/.gitea/workflows/backend-image.yml @@ -45,3 +45,31 @@ jobs: docker tag "$image:$IMAGE_TAG" "$image:latest" docker push "$image:latest" fi + + - name: Link package to repository + env: + GITEA_API: https://git.ipao.vip/api/v1 + GITEA_OWNER: ${{ github.repository_owner }} + PACKAGE_NAME: ${{ github.event.repository.name }} + PACKAGE_VERSION: ${{ github.sha }} + REPOSITORY_NAME: ${{ github.event.repository.name }} + GITEA_TOKEN: ${{ secrets.REGISTRY_TOKEN }} + run: | + set -eu + test -n "$GITEA_TOKEN" + expected_repo="$GITEA_OWNER/$REPOSITORY_NAME" + package_json="$(curl -fsS \ + --header "Authorization: token $GITEA_TOKEN" \ + "$GITEA_API/packages/$GITEA_OWNER/container/$PACKAGE_NAME/$PACKAGE_VERSION")" + linked_repo="$(printf '%s' "$package_json" | jq -r '.repository.full_name // empty')" + if [ -n "$linked_repo" ]; then + if [ "$linked_repo" != "$expected_repo" ]; then + echo "package is already linked to $linked_repo" >&2 + exit 1 + fi + echo "package already linked to $linked_repo" + exit 0 + fi + curl -fsS -X POST \ + --header "Authorization: token $GITEA_TOKEN" \ + "$GITEA_API/packages/$GITEA_OWNER/container/$PACKAGE_NAME/-/link/$REPOSITORY_NAME"