User Tools

Site Tools


gitlab-ci-composer-publish

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
gitlab-ci-composer-publish [2020/06/21 11:06] – [Extended config] admingitlab-ci-composer-publish [2020/06/21 23:19] (current) admin
Line 7: Line 7:
  
 <code yaml> <code yaml>
-stages: +# Publishes a tag/branch to Composer Packages of the current project
-    - publish +
 publish: publish:
-    image: curlimages/curl:latest +  image: curlimages/curl:latest 
-    stage: publish +  stage: build 
-    variables: +  variables: 
-        URL: "$CI_SERVER_PROTOCOL://$CI_SERVER_HOST:$CI_SERVER_PORT/api/v4/projects/$CI_PROJECT_ID/packages/composer?job_token=$CI_JOB_TOKEN" +    URL: "$CI_SERVER_PROTOCOL://$CI_SERVER_HOST:$CI_SERVER_PORT/api/v4/projects/$CI_PROJECT_ID/packages/composer?job_token=$CI_JOB_TOKEN" 
-    script: +  script: 
-        - version=$([ -z "$CI_COMMIT_TAG" ] && echo "branch=$CI_COMMIT_REF_NAME" || echo "tag=$CI_COMMIT_TAG"+    - version=$([[ -z "$CI_COMMIT_TAG" ]] && echo "branch=$CI_COMMIT_REF_NAME" || echo "tag=$CI_COMMIT_TAG"
-        - response=$(curl -s -w "\n%{http_code}" --insecure --data $version $URL) +    - insecure=$([ "$CI_SERVER_PROTOCOL" = "http" ] && echo "--insecure"
-        - code=$(echo "$response" | tail -n 1) +    - response=$(curl -s -w "\n%{http_code}" $insecure --data $version $URL) 
-        - body=$(echo "$response" | head -n 1) +    - code=$(echo "$response" | tail -n 1) 
-        # Output state information +    - body=$(echo "$response" | head -n 1) 
-        - if [ $code -eq 201 ]; +    # Output state information 
-            then +    - if [ $code -eq 201 ]; then 
-                echo "Package created - Code $code - $body"; +        echo "Package created - Code $code - $body"; 
-            else +      else 
-                echo "Could not create package - Code $code - $body"; +        echo "Could not create package - Code $code - $body"; 
-                exit 1; +        exit 1; 
-            fi+      fi
 </code> </code>
  
Line 36: Line 34:
 <code yaml> <code yaml>
 stages: stages:
-    - test +  - test 
-    publish+  build
  
 test: test:
-    image: composer:+  image: composer:
-    stage: test +  stage: test 
-    script: +  script: 
-        - composer install +    - composer install 
-        - vendor/bin/codecept run --html +    - vendor/bin/codecept run --html 
-    artifacts: +  artifacts: 
-        paths: +    paths: 
-            - tests/_output/report.html +      - tests/_output/report.html 
-        expire_in: 1 weeks+    expire_in: 1 weeks
  
 +# Publishes a tag/branch to Composer Packages of the current project
 publish: publish:
-    image: curlimages/curl:latest +  image: curlimages/curl:latest 
-    stage: publish +  stage: build 
-    variables: +  variables: 
-        URL: "$CI_SERVER_PROTOCOL://$CI_SERVER_HOST:$CI_SERVER_PORT/api/v4/projects/$CI_PROJECT_ID/packages/composer?job_token=$CI_JOB_TOKEN" +    URL: "$CI_SERVER_PROTOCOL://$CI_SERVER_HOST:$CI_SERVER_PORT/api/v4/projects/$CI_PROJECT_ID/packages/composer?job_token=$CI_JOB_TOKEN" 
-    script: +  script: 
-        - version=$([ -z "$CI_COMMIT_TAG" ] && echo "branch=$CI_COMMIT_REF_NAME" || echo "tag=$CI_COMMIT_TAG"+    - version=$([[ -z "$CI_COMMIT_TAG" ]] && echo "branch=$CI_COMMIT_REF_NAME" || echo "tag=$CI_COMMIT_TAG"
-        - response=$(curl -s -w "\n%{http_code}" --insecure --data $version $URL) +    - insecure=$([ "$CI_SERVER_PROTOCOL" = "http" ] && echo "--insecure"
-        - code=$(echo "$response" | tail -n 1) +    - response=$(curl -s -w "\n%{http_code}" $insecure --data $version $URL) 
-        - body=$(echo "$response" | head -n 1) +    - code=$(echo "$response" | tail -n 1) 
-        # Output state information +    - body=$(echo "$response" | head -n 1) 
-        - if [ $code -eq 201 ]; +    # Output state information 
-            then +    - if [ $code -eq 201 ]; then 
-                echo "Package created - Code $code - $body"; +        echo "Package created - Code $code - $body"; 
-            else +      else 
-                echo "Could not create package - Code $code - $body"; +        echo "Could not create package - Code $code - $body"; 
-                exit 1; +        exit 1; 
-            fi+      fi
 </code> </code>
  
gitlab-ci-composer-publish.1592730416.txt.gz · Last modified: 2020/06/21 11:06 by admin