-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
98 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
--- | ||
.configure-registry: &configure-registry | ||
- apk --quiet --no-progress --update --no-cache add git openssh | ||
- NODE_ENV=cicd yarn install --frozen-lockfile --cache-folder .npm --prefer-offline | ||
- | | ||
{ | ||
echo "//registry.npmjs.com/:_authToken=${NPM_TOKEN}" | ||
echo "@cloudgraph:registry=https://registry.npmjs.com/" | ||
} | tee -a .npmrc | ||
- | | ||
{ | ||
echo "\"@cloudgraph:registry\" \"https://registry.npmjs.com/\"" | ||
echo "\"//registry.npmjs.com/:_authToken\" \"${NPM_TOKEN}\"" | ||
} | tee -a .yarnrc | ||
default: | ||
image: node:16-alpine | ||
before_script: | ||
- *configure-registry | ||
cache: | ||
key: ${CI_COMMIT_REF_SLUG} | ||
paths: | ||
- .npm/ | ||
- dist/ | ||
|
||
workflow: | ||
rules: | ||
- if: '$CI_PIPELINE_SOURCE == "push"' | ||
|
||
variables: | ||
NPM_TOKEN: ${NPM_TOKEN} | ||
|
||
stages: | ||
- build | ||
- test | ||
- publish | ||
- notify | ||
|
||
build: | ||
image: node:16-alpine | ||
stage: build | ||
rules: | ||
- if: $CI_COMMIT_TAG | ||
when: never | ||
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_MESSAGE =~ /^chore\(release\)/' | ||
when: never | ||
- if: $CI_COMMIT_BRANCH | ||
when: always | ||
script: | ||
- yarn prepublish | ||
|
||
# test: | ||
# image: node:16-alpine | ||
# stage: test | ||
# rules: | ||
# - when: always | ||
# script: | ||
# - yarn test | ||
|
||
semantic release: | ||
image: node:16-alpine | ||
stage: publish | ||
rules: | ||
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_MESSAGE =~ /^chore\(release\)/' | ||
when: never | ||
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH | ||
variables: | ||
# Set git commit identity | ||
GIT_AUTHOR_NAME: "AutoCloud Deploy Bot" | ||
GIT_AUTHOR_EMAIL: "no-reply@loudcloud.dev" | ||
GIT_COMMITTER_NAME: "AutoCloud Deploy Bot" | ||
GIT_COMMITTER_EMAIL: "no-reply@loudcloud.dev" | ||
# Disable Husky for the git step of semantic release (handles all versions, env var name changed in v6) | ||
HUSKY_SKIP_HOOKS: 1 | ||
HUSKY: 0 | ||
before_script: | ||
- *configure-registry | ||
script: | ||
- npx semantic-release -r $CI_PROJECT_URL | ||
|
||
.curlcmd: &curlcmd > | ||
curl | ||
-sS | ||
-X POST | ||
--data-urlencode "payload={\"attachments\":[{\"fallback\":\"$GITLAB_USER_NAME released new $CI_PROJECT_TITLE version $CI_COMMIT_TAG\",\"color\":\"good\",\"author_name\":\"$GITLAB_USER_NAME ($GITLAB_USER_LOGIN)\",\"author_icon\":\"$GITLAB_USER_AVATAR\",\"author_link\":\"https://gitlab.com/$GITLAB_USER_LOGIN\",\"title\":\"Version $CI_COMMIT_TAG of $CI_PROJECT_NAME released\",\"title_link\":\"$CI_PROJECT_URL/-/tags/$CI_COMMIT_TAG\",\"fields\":[{\"title\":\"Tag\",\"value\":\"<$CI_PROJECT_URL/commits/$CI_COMMIT_TAG|$CI_COMMIT_TAG>\",\"short\":true},{\"title\":\"Commit\",\"value\":\"<$CI_PROJECT_URL/tree/$CI_COMMIT_SHA|$CI_COMMIT_TITLE>\",\"short\":true}],\"footer\":\"$CI_PROJECT_NAME\",\"ts\":$( date +%s )}]}" | ||
$SLACK_API_ENDPOINT | ||
|
||
notify: | ||
image: alpine:latest | ||
stage: notify | ||
rules: | ||
- if: $CI_COMMIT_TAG | ||
# Overwrite the default before script with a no-op action to disable the node specific actions | ||
before_script: | ||
- echo "noop" | ||
script: | ||
- apk add --no-cache curl | ||
- GITLAB_USER_AVATAR=$( echo $GITLAB_USER_EMAIL | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]' | md5sum | awk -F' ' '{print $1}' | xargs -I{} echo 'https://www.gravatar.com/avatar/{}?s=80&d=identicon' ) | ||
- *curlcmd |