forked from hipay/hipay-enterprise-sdk-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
138 lines (121 loc) · 3.54 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
variables:
NODE_VERSION: 18
.cache:
variables:
PATH_NODE_MODULES: src/node_modules/
PATH_NPMRC: src/.npmrc
PATH_SRC: src
include:
- project: common/templates/ci-microservices
ref: 1.7.1
file:
- library-ci.yaml
stages:
- build
- test
- release
- deploy
install:
script:
- cd $PATH_SRC/ && yarn install
# Job to get JIRA tickets of the release
get-jira-tickets:
stage: release
image: node:latest
needs:
- test-jest
rules:
- if: $CI_COMMIT_TAG
script:
- |
node <<EOF
(async () => {
try {
const gitlabResponse = await fetch("${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/merge_requests?state=merged&target_branch=develop&milestone=${CI_COMMIT_TAG}", {
method: "GET",
headers: {
"Private-Token": "$GITLAB_API_TOKEN"
}
});
if (!gitlabResponse.ok) {
const err = await gitlabResponse.json();
throw new Error("Failed to send GitLab request: " + JSON.stringify(err));
}
const mergeRequests = await gitlabResponse.json();
let tickets = [];
mergeRequests.forEach((mr) => {
const matches = mr.source_branch.match(/EC-\d+/i);
const matchesTitle = mr.title.match(/(EC-\d+)/ig);
if(matches?.length) {
tickets.push(matches[0].toUpperCase());
}
matchesTitle?.forEach((match) => {
tickets.push(match.toUpperCase());
});
});
tickets = [...new Set(tickets)];
console.log("tickets", tickets);
const payload = {
"event_type": "trigger-artifact-workflow",
"client_payload": {
"tickets": tickets
}
};
console.log("payload", JSON.stringify(payload));
const githubResponse = await fetch("https://api.github.com/repos/${GITHUB_ORGANIZATION}/${GITHUB_PROJECT}/dispatches", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer ${GITHUB_TOKEN}",
"User-Agent": "Node.js"
},
body: JSON.stringify(payload)
});
if (!githubResponse.ok) {
const err = await githubResponse.json();
throw new Error("Failed to send GitHub event: " + JSON.stringify(err));
}
} catch (error) {
throw new Error("Request error: " + error.message);
}
})();
EOF
# Release note job
release-job:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
needs:
- get-jira-tickets
variables:
TEMP_CHANGELOG_FILE: 'release_changelog.txt'
rules:
- if: $CI_COMMIT_TAG
script:
- |
# Extract changelog part according to tag version
CHANGELOG=$(awk -v version="## $CI_COMMIT_TAG" '
$0 ~ version {printit=1; next}
printit && /^## / {exit}
printit {print}
' CHANGELOG.md)
{
echo "# CHANGE LOG"
echo "$CHANGELOG"
} > "$TEMP_CHANGELOG_FILE"
- cat "$TEMP_CHANGELOG_FILE"
release:
tag_name: $CI_COMMIT_TAG
name: Version $CI_COMMIT_TAG
description: '$TEMP_CHANGELOG_FILE'
milestones:
- $CI_COMMIT_TAG
.npm-publish-template:
needs: [install]
before_script:
- cp *.md $PATH_SRC/
script:
- cd $PATH_SRC/
- echo $PKG_VERSION
- echo $PKG_TAG
- npm --no-git-tag-version --allow-same-version version $PKG_VERSION
- npm publish --access public --tag $PKG_TAG