-
Notifications
You must be signed in to change notification settings - Fork 0
77 lines (67 loc) · 2.06 KB
/
Copy pathpublish.yml
File metadata and controls
77 lines (67 loc) · 2.06 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
name: Publish image
on:
push:
tags: ['v*']
public:
workflow_dispatch:
permissions:
contents: read
packages: write
env:
IMAGE: ghcr.io/action-prediction-lab/pepper-perception
jobs:
publish-tag:
# On a tag push to a public repo: build and push that one tag plus :latest.
# On a private repo: this job is skipped; the tag still exists in git.
if: |
github.event_name == 'push' &&
github.event.repository.private == false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ env.IMAGE }}:${{ github.ref_name }}
${{ env.IMAGE }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
backfill:
# On private->public flip or manual re-run: build every existing v* tag.
if: github.event_name == 'public' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push each existing v* tag
run: |
set -euo pipefail
tags=$(git tag --list 'v*' --sort=creatordate)
if [[ -z "$tags" ]]; then
echo "No v* tags found, nothing to backfill."
exit 0
fi
for tag in $tags; do
echo "::group::$tag"
git checkout "$tag"
docker build -t "$IMAGE:$tag" .
docker push "$IMAGE:$tag"
echo "::endgroup::"
done
latest=$(echo "$tags" | tail -1)
docker tag "$IMAGE:$latest" "$IMAGE:latest"
docker push "$IMAGE:latest"