-
Notifications
You must be signed in to change notification settings - Fork 1
59 lines (50 loc) · 1.74 KB
/
release-version.yml
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
name: Tag a docker image release
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
on:
push:
tags: [ '*.*.*' ]
workflow_dispatch: {}
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
jobs:
retag_docker_image:
name: Create version tag for existing docker image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create version tag for existing docker image
run: |
git_sha=sha-$(git rev-parse --short HEAD)
git_tag=$(basename ${GITHUB_REF})
# wait for image to be available
max_tries=60 # max_tries times every 10 seconds
echo "waiting for docker image '${REGISTRY}/${IMAGE_NAME}:${git_sha}' to be available"
for _ in $(seq 1 120)
do
sleep 10
echo "."
docker pull ${REGISTRY}/${IMAGE_NAME}:${git_sha} &>/dev/null && break
done
echo " ✅"
echo "tagging and pushing docker image"
(set -ex;
docker tag ${REGISTRY}/${IMAGE_NAME}:${git_sha} ${REGISTRY}/${IMAGE_NAME}:${git_tag}
docker push ${REGISTRY}/${IMAGE_NAME}:${git_tag}
)