Skip to content

Instantly share code, notes, and snippets.

@timwiel
Last active July 26, 2022 16:23
Embed
What would you like to do?
Gitlab CI Pipeline config for generating a generic package from a npm build of a wordpress-plugin
stages:
- build
- upload
- release
build:
stage: build
rules:
- if: $CI_COMMIT_TAG
before_script:
- npm install
script:
- |
npm run build:assets
npm run archive
echo 'Package created!'
artifacts:
paths:
- ${CI_PROJECT_NAME}.zip
expire_in: 1 day
# Refer to: https://gitlab.com/gitlab-org/release-cli/-/tree/master/docs/examples/release-assets-as-generic-package/
upload:
stage: upload
image: curlimages/curl:latest
rules:
- if: $CI_COMMIT_TAG
script:
- |
PACKAGE_VERSION=$(grep -Po "(?:^|\s)+(?:Version:)\K(?:\s)*\K((?:0|(?:[1-9]\d*))\.(?:0|(?:[1-9]\d*))\.(?:0|(?:[1-9]\d*)))" ${CI_PROJECT_NAME}.php)
PACKAGE_REGISTRY_URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}/${PACKAGE_VERSION}"
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file ${CI_PROJECT_NAME}.zip ${PACKAGE_REGISTRY_URL}/${CI_PROJECT_NAME}.zip
echo 'Package uploaded!'
# Refer to: https://gitlab.com/gitlab-org/release-cli/-/tree/master/docs#using-this-tool-in-gitlab-ci
release:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
rules:
- if: $CI_COMMIT_TAG
script:
- |
PACKAGE_VERSION=$(grep -Po "(?:^|\s)+(?:Version:)\K(?:\s)*\K((?:0|(?:[1-9]\d*))\.(?:0|(?:[1-9]\d*))\.(?:0|(?:[1-9]\d*)))" ${CI_PROJECT_NAME}.php)
PACKAGE_REGISTRY_URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}/${PACKAGE_VERSION}"
- >
release-cli create
--name "Release $CI_COMMIT_TAG"
--description "Release of $CI_COMMIT_TAG from $CI_PROJECT_NAME"
--tag-name "$CI_COMMIT_TAG"
--assets-link "{\"name\":\"${CI_PROJECT_NAME}.zip\",\"url\":\"${PACKAGE_REGISTRY_URL}/${CI_PROJECT_NAME}.zip\"}"
- |
echo 'Created released of ${CI_PROJECT_NAME}!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment