-
Notifications
You must be signed in to change notification settings - Fork 0
81 lines (78 loc) · 2.46 KB
/
Copy pathpublish-snapshot.yml
File metadata and controls
81 lines (78 loc) · 2.46 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
73
74
75
76
77
78
79
80
81
name: Publish Snapshot
env:
IMAGE_NAME: ghcr.io/anitrend/edge-graphql
CACHE_REF: ghcr.io/anitrend/edge-graphql:cache
on:
workflow_dispatch:
inputs:
branch:
description: "Git ref to build (branch or tag)"
required: true
image-tag:
description: "Override the Docker tag (defaults to sanitized branch)"
required: false
jobs:
build-snapshot:
name: Build Snapshot Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Resolve ref
id: resolve
env:
INPUT_BRANCH: ${{ github.event.inputs.branch }}
WORKFLOW_REF: ${{ github.ref }}
run: |
if [[ -n "$INPUT_BRANCH" ]]; then
ref="$INPUT_BRANCH"
else
ref=$(echo "$WORKFLOW_REF" | sed -E 's#^refs/(heads|tags)/##')
fi
echo "ref=$ref" >> "$GITHUB_OUTPUT"
- name: Derive image tag
id: tag
env:
TAG_OVERRIDE: ${{ github.event.inputs.image-tag }}
SOURCE_REF: ${{ steps.resolve.outputs.ref }}
run: |
if [[ -n "$TAG_OVERRIDE" ]]; then
tag="$TAG_OVERRIDE"
else
base="$SOURCE_REF"
base="${base,,}"
tag=$(echo "$base" | sed -E 's/[^a-z0-9._-]+/-/g' | sed -E 's/^-+|-+$//g')
if [[ -z "$tag" ]]; then
tag="manual-snapshot"
fi
tag=${tag:0:120}
fi
echo "tag=$tag" >> "$GITHUB_OUTPUT"
- name: Checkout code
uses: actions/checkout@v7
with:
ref: ${{ steps.resolve.outputs.ref }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push snapshot image
uses: docker/build-push-action@v7
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
cache-from: type=registry,ref=${{ env.CACHE_REF }}
cache-to: type=registry,ref=${{ env.CACHE_REF }},mode=max
tags: ${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.tag }}
- name: Summarize snapshot
run: |
cat <<SUMMARY >> "$GITHUB_STEP_SUMMARY"
SUMMARY