Last active
August 22, 2024 10:21
-
-
Save timwiel/9dfd3526c768efad4973254085e065ce to your computer and use it in GitHub Desktop.
Gitlab CI Pipeline config for generating a generic package from a npm build of a wordpress-plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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