-
Notifications
You must be signed in to change notification settings - Fork 3.8k
72 lines (64 loc) · 2.19 KB
/
tag-alias.yaml
File metadata and controls
72 lines (64 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
name: Tag Alias
# Retags an existing image in GHCR under a custom name, without rebuilding.
# Uses `docker buildx imagetools create` so the multi-arch manifest is preserved.
# Re-running with the same name updates the alias to point at a different source tag.
on:
workflow_dispatch:
inputs:
name:
description: "Alias name (e.g., potato)"
required: true
source_tag:
description: "Source tag to alias from"
required: false
default: "latest"
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
alias:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Validate alias name
env:
NAME: ${{ inputs.name }}
run: |
if ! [[ "$NAME" =~ ^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$ ]]; then
echo "Invalid alias name '$NAME' (allowed: [A-Za-z0-9_.-], must start with [A-Za-z0-9_], max 128 chars)."
exit 1
fi
if [[ "$NAME" == "latest" || "$NAME" == "main" ]]; then
echo "Alias name '$NAME' is reserved by the build workflow."
exit 1
fi
if [[ "$NAME" =~ ^[0-9]{2}\.[0-9]{2}(\.[0-9]+)?$ ]]; then
echo "Alias name '$NAME' looks like a calver tag — pick a non-version name."
exit 1
fi
- name: Log in to GitHub Package Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Create alias tag
env:
IMAGE: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
NAME: ${{ inputs.name }}
SOURCE_TAG: ${{ inputs.source_tag }}
run: |
SRC="${IMAGE}:${SOURCE_TAG}"
DST="${IMAGE}:${NAME}"
echo "Aliasing $DST -> $SRC"
docker buildx imagetools create -t "$DST" "$SRC"
{
echo "### 🏷️ Tag Alias"
echo ""
echo "- Source: \`$SRC\`"
echo "- Alias: \`$DST\`"
} >> "$GITHUB_STEP_SUMMARY"