From 76f10777b504ff0abac359c85db1d0bc6c1a84c5 Mon Sep 17 00:00:00 2001
From: Bryan Brancotte <bryan.brancotte@pasteur.fr>
Date: Tue, 25 Apr 2023 14:56:13 +0200
Subject: [PATCH] only main can publish main tagged images

---
 .gitlab-ci.yml | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 2357a67..60f9178 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -49,10 +49,13 @@ build:
     - docker push "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG:latest"
     # push image tagged with its sha
     - docker push "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA"
-    # push image tagged with its versions
-    - docker push "$CI_REGISTRY_IMAGE:$VERSIONS_TAG"
-    # push image tagged with its versions and the commit sha (debug purpose)
-    - docker push "$CI_REGISTRY_IMAGE:$VERSIONS_TAG--$CI_COMMIT_SHORT_SHA"
+    - |
+      if [ "main" == "${CI_COMMIT_REF_SLUG}" ]; then
+        # push image tagged with its versions
+        docker push "$CI_REGISTRY_IMAGE:$VERSIONS_TAG"
+        # push image tagged with its versions and the commit sha (debug purpose)
+        docker push "$CI_REGISTRY_IMAGE:$VERSIONS_TAG--$CI_COMMIT_SHORT_SHA"
+      fi
   parallel:
     matrix:
       - R_VERSION: ["latest"]
-- 
GitLab