Tech Evaluation: Upload assets to the generic package registry before creating a release
The objective is ti figure out how much work it needs to be done on the release-cli in order to upload binary assets to the generic package registry introduced in gitlab#235492 (closed).
Proposal
- Generate binaries in a job previous to
releaseand save them to the CI artifactsartifacts:paths - Require artifacts in the
releasejob so that they are made available to therelease-cli - Add a flag to the
release-clito indicate it should upload a directory before creating a release, for example--upload-dir=/path/to/artifacts -
release-cliwill upload the files to the generic package registry using the API, may need to use a feature branch - Once files are uploaded,
release-clishould create a release attaching permanent links to the release
Sample .gitlab-ci.yml configuration
build:
script:
- make build # output goes to bin/binary_*_.ext
artifacts:
paths:
- bin
release:
image: registry.gitlab.com/gitlab-org/release-cli
needs:
- job: build
artifacts: true
script:
- echo "upload binaries and create release"
- >
release-cli --name "Release $CI_COMMIT_TAG" --tag-name $CI_COMMIT_TAG --upload-dir=bin/
Considerations
- We depend on a previous job to be executed first, meaning the files will be uploaded to the artifacts storage, downloaded into the job runner and uploaded again to the package registry
- maybe it can be done in the same step as
releasewhere we have the script run beforerelease-cliis called🤔 - If gitlab#17838 (comment 406384884) is on the table then we might just need to add the
-upload-dirflag to therelease-cli
Results from !59 (closed)
Following the Generic Packages API format /api/v4/:project_id/packages/generic/:package_name/:package_version/:filename I've added a couple of flags to support uploading binaries.
-
--upload-dir=./bin/-> only supports first level files and skips subdirectories -
--package-name=$CI_PROJECT_NAME-> this is required by the generic packages API
For now, when --upload-dir is defined:
- Ignore
--assets-link - Files need to exists, for example building in a prior stage and sharing them as artifacts in the release job
- Iterate over regular files inside the
--upload-dir - Skip subdirectories inside of
--upload-dir - Upload each file present in the directory and prepare a direct asset link to be passed to the releases API. (
typeis ignored as the default value isotherandfilepathis also ignored) - Use
--package-nameto match the API requirement, this is defaulting to the project name right now - Use each file inside
--upload-diras the:filename - Use a "lean" version of the
$CI_COMMIT_TAGto only keep the required format e.g. if$CI_COMMIT_TAG=v1.2.3-rcthen only1.2.3is used as the:package_version
Here is a sample project (requires staging access) with CI config. Using the release-cli directly:
release-from-tag:
#image: registry.gitlab.com/gitlab-org/release-cli
image: registry.gitlab.com/jaime/release-cli:edge
stage: release
needs:
- job: prepare
artifacts: true
- job: build # build job and artifacts required
artifacts: true
rules:
- if: $CI_COMMIT_TAG # Run this job when a tag is created manually
script:
- echo "running release from $CI_COMMIT_TAG"
- >
release-cli create --name "Release $CI_COMMIT_TAG" --description "Notes: $EXTRA_DESCRIPTION"
--tag-name $CI_COMMIT_TAG --ref $CI_COMMIT_TAG
--milestone "m1" --milestone "m2"
--upload-dir "bin/"
The created release with the list of assets https://staging.gitlab.com/jaimem88/hello/-/releases/v1.10.3-rc1
And the contents of the package registry
What's next
If we want to pursue this option I can create some follow-up issues.
-
Upload assets prior to creating a release (weight 3) #59 (closed)
- Add API call to generic packages to upload files.
- Add flags
--upload-dirand--package-name. Only support root level items and ignore subdirectories. - Update documentation and examples on the CI reference.
-
Extend the
release:keyword to supportupload_dirandpackage_name(unsure about weight) gitlab#255271. For examplerelease: name: "Release $CI_COMMIT_TAG" tag_name: "$CI_COMMIT_TAG" package_name: "myawesomepackage" upload_dir: "./bin/" -
Nice-to-have: Extend the packages API to allow using different versioning for
:package_versiongitlab#255234 (closed) -
Nice-to-have: Support subdirectories via
--upload-dir#60 (closed)
Issues found
- The generic packages API
:package_versiononly accepts text or versions of the format1.2.3. Values likev1.2.3or1.2.3-rc-1fail from the API. I'll post this feedback on gitlab#235492 (closed). - Because of the above, we can't use
$CI_COMMIT_TAGas the value of:package_versionright now because the git tag can be anything. - Could not test on
GitLab.comyet so did all my testing on staging. - Could not test using the GDK as the packages API returns a 500 error but I didn't investigate further as it works on staging and it's most likely related to my local setup.

