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 revision Previous revision
gitlab-ci-composer-publish [2020/06/21 11:16]
admin [Extended config]
gitlab-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"
-        - insecure=$([ "$CI_SERVER_PROTOCOL" -eq "http"] && echo "--insecure" || echo "") +    - insecure=$([ "$CI_SERVER_PROTOCOL" "http" ] && echo "--insecure"
-        - response=$(curl -s -w "\n%{http_code}" $insecure --data $version $URL) +    - response=$(curl -s -w "\n%{http_code}" $insecure --data $version $URL) 
-        - code=$(echo "$response" | tail -n 1) +    - code=$(echo "$response" | tail -n 1) 
-        - body=$(echo "$response" | head -n 1) +    - body=$(echo "$response" | head -n 1) 
-        # Output state information +    # Output state information 
-        - if [ $code -eq 201 ]; +    - if [ $code -eq 201 ]; then 
-            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 37: 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"
-        - insecure=$([ "$CI_SERVER_PROTOCOL" -eq "http"] && echo "--insecure" || echo "") +    - insecure=$([ "$CI_SERVER_PROTOCOL" "http" ] && echo "--insecure"
-        - response=$(curl -s -w "\n%{http_code}" $insecure --data $version $URL) +    - response=$(curl -s -w "\n%{http_code}" $insecure --data $version $URL) 
-        - code=$(echo "$response" | tail -n 1) +    - code=$(echo "$response" | tail -n 1) 
-        - body=$(echo "$response" | head -n 1) +    - body=$(echo "$response" | head -n 1) 
-        # Output state information +    # Output state information 
-        - if [ $code -eq 201 ]; +    - if [ $code -eq 201 ]; then 
-            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.txt · Last modified: 2020/06/21 23:19 by admin