15
15
branches :
16
16
- master
17
17
paths : ['.github/workflows/docker.yml', '.devops/*.Dockerfile', '**/CMakeLists.txt', '**/Makefile', '**/*.h', '**/*.hpp', '**/*.c', '**/*.cpp', '**/*.cu', '**/*.cuh', '**/*.swift', '**/*.m', '**/*.metal']
18
+ workflow_dispatch : # allows manual triggering, useful for debugging
18
19
19
20
concurrency :
20
21
group : ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }}
21
22
cancel-in-progress : true
22
23
24
+ # Fine-grant permission
25
+ # https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token
26
+ permissions :
27
+ packages : write
28
+
23
29
jobs :
24
30
push_to_registry :
25
31
name : Push Docker image to Docker Hub
46
52
steps :
47
53
- name : Check out the repo
48
54
uses : actions/checkout@v4
55
+ with :
56
+ fetch-depth : 0 # preserve git history, so we can determine the build number
49
57
50
58
- name : Set up QEMU
51
59
uses : docker/setup-qemu-action@v2
60
68
username : ${{ github.repository_owner }}
61
69
password : ${{ secrets.GITHUB_TOKEN }}
62
70
71
+ - name : Determine tag name
72
+ id : tag
73
+ shell : bash
74
+ run : |
75
+ BUILD_NUMBER="$(git rev-list --count HEAD)"
76
+ SHORT_HASH="$(git rev-parse --short=7 HEAD)"
77
+ REPO_OWNER="${GITHUB_REPOSITORY_OWNER@L}" # to lower case
78
+ REPO_NAME="${{ github.event.repository.name }}"
79
+
80
+ # determine tag name postfix (build number, commit hash)
81
+ if [[ "${{ env.GITHUB_BRANCH_NAME }}" == "master" ]]; then
82
+ TAG_POSTFIX="b${BUILD_NUMBER}"
83
+ else
84
+ SAFE_NAME=$(echo "${{ env.GITHUB_BRANCH_NAME }}" | tr '/' '-')
85
+ TAG_POSTFIX="${SAFE_NAME}-${SHORT_HASH}"
86
+ fi
87
+
88
+ # list all tags possible
89
+ TAGS=""
90
+ TAGS="${TAGS}ghcr.io/${REPO_OWNER}/${REPO_NAME}:${{ matrix.config.tag }},"
91
+ TAGS="${TAGS}ghcr.io/${REPO_OWNER}/${REPO_NAME}:${{ matrix.config.tag }}-${TAG_POSTFIX}"
92
+
93
+ echo "output_tags=$TAGS" >> $GITHUB_OUTPUT
94
+ echo "output_tags=$TAGS" # print out for debugging
95
+ env :
96
+ GITHUB_BRANCH_NAME : ${{ github.head_ref || github.ref_name }}
97
+ GITHUB_REPOSITORY_OWNER : ' ${{ github.repository_owner }}'
98
+
63
99
# https://github.com/jlumbroso/free-disk-space/tree/54081f138730dfa15788a46383842cd2f914a1be#example
64
100
- name : Free Disk Space (Ubuntu)
65
101
uses : jlumbroso/free-disk-space@main
@@ -77,31 +113,13 @@ jobs:
77
113
docker-images : true
78
114
swap-storage : true
79
115
80
- - name : Determine tag name
81
- id : tag
82
- shell : bash
83
- run : |
84
- BUILD_NUMBER="$(git rev-list --count HEAD)"
85
- SHORT_HASH="$(git rev-parse --short=7 HEAD)"
86
- if [[ "${{ env.BRANCH_NAME }}" == "master" ]]; then
87
- echo "name=b${BUILD_NUMBER}" >> $GITHUB_OUTPUT
88
- else
89
- SAFE_NAME=$(echo "${{ env.BRANCH_NAME }}" | tr '/' '-')
90
- echo "name=${SAFE_NAME}-b${BUILD_NUMBER}-${SHORT_HASH}" >> $GITHUB_OUTPUT
91
- fi
92
-
93
- - name : Downcase github.repository_owner
94
- run : |
95
- echo "repository_owner_lowercase=${GITHUB_REPOSITORY_OWNER@L}" >> $GITHUB_ENV
96
- env :
97
- GITHUB_REPOSITORY_OWNER : ' ${{ github.repository_owner }}'
98
-
99
116
- name : Build and push Docker image (tagged + versioned)
100
117
if : github.event_name == 'push'
101
118
uses : docker/build-push-action@v6
102
119
with :
103
120
context : .
104
121
push : true
105
122
platforms : ${{ matrix.config.platforms }}
106
- tags : " ghcr.io/${{ env.repository_owner_lowercase }}/llama.cpp:${{ matrix.config.tag }}-${{ env.COMMIT_SHA }},ghcr.io/${{ env.repository_owner_lowercase }}/llama.cpp:${{ matrix.config.tag }},ghcr.io/${{ env.repository_owner_lowercase }}/llama.cpp:${{ matrix.config.tag }}-${{ steps.tag.outputs.name }}"
123
+ # tag list is generated from step above
124
+ tags : ${{ steps.tag.outputs.output_tags }}
107
125
file : ${{ matrix.config.dockerfile }}
0 commit comments