Gitlab CI create release

Example to create a PHP archive (phar) and link the generated artifact to the release if a Release Note is set.

Required to create a private token and set as environment variable $GITLAB_PRIVATE_TOKEN

Example:

.gitlab-ci.yml
variables:
  PHAR_FILE_NAME: "typo3-composer-installer.phar"
  PHAR_ARTIFACT_NAME: "typo3-composer-installer"

stages:
  - publish
  - release

create_version:
  image: zeroseven07/docker-surf:php74
  stage: publish
  only:
    - tags
  script:
    - composer install
    - php -d phar.readonly=off ./vendor/bin/phar-composer -vvv build
    # Save variable for later use
    - echo 'JOB_ARTIFACT_ID='$CI_JOB_ID > build.env
  artifacts:
    name: $PHAR_ARTIFACT_NAME
    paths:
      - $PHAR_FILE_NAME
      # Add .env file to artifacts
      - build.env
    expire_in: 1000 year

release:
  image: curlimages/curl:latest
  stage: release
  dependencies: 
    - create_version
  when: on_success
  only:
    - tags
  script:
    # Get variables saved as artifacts in `.phar` template
    - export $(xargs <build.env)
    # Create release if a 'Release Note' was set while creating a tag
    - 'curl --request POST --header "PRIVATE-TOKEN: $GITLAB_PRIVATE_TOKEN"
      --data name="$PHAR_ARTIFACT_NAME-$CI_COMMIT_TAG.phar" 
      --data url="$CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/jobs/$JOB_ARTIFACT_ID/artifacts/$PHAR_FILE_NAME" 
      $CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/releases/$CI_COMMIT_TAG/assets/links'