-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodefresh.yaml
More file actions
204 lines (187 loc) · 5.31 KB
/
codefresh.yaml
File metadata and controls
204 lines (187 loc) · 5.31 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
version: '1.0'
mode: parallel
stages:
- clone
- prepare
- test
- build
- publish
steps:
main_clone:
stage: clone
type: git-clone
repo: '${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}'
revision: '${{CF_REVISION}}'
extract_package_version:
stage: prepare
title: 'Extract package version'
image: quay.io/codefresh/codefresh-shell:0.0.14
working_directory: ${{main_clone}}
shell: bash
commands:
- |
export PACKAGE_VERSION=$(jq -r '.version' package.json)
if [[ -n "${PACKAGE_VERSION}" ]]; then
echo "Package version is detected: ${PACKAGE_VERSION}"
else
echo "Package version was not detected. Please, make sure it's specified in 'package.json'." >&2
exit 1
fi
cf_export PACKAGE_VERSION
when:
steps:
- name: main_clone
validate_package_version:
stage: prepare
title: 'Validate package version'
image: quay.io/codefresh/codefresh-shell:0.0.14
working_directory: ${{main_clone}}
shell: bash
commands:
- |
git show origin/main:package.json > package.main.json
export UPSTREAM_PACKAGE_VERSION=$( jq -r '.version' package.main.json)
echo "Version to merge: $PACKAGE_VERSION"
echo "Upstream version: $UPSTREAM_PACKAGE_VERSION"
semver-cli greater $PACKAGE_VERSION $UPSTREAM_PACKAGE_VERSION
when:
steps:
- name: extract_package_version
branch:
ignore: [ main, alpha ]
export_github_token:
stage: prepare
image: quay.io/codefresh/codefresh-shell:0.0.14
shell: bash
commands:
- source /scripts/get-gh-token.sh
- cf_export GITHUB_TOKEN=$GITHUB_TOKEN --mask
when:
steps:
- name: main_clone
specify_node_image:
stage: prepare
image: quay.io/codefresh/codefresh-shell:0.0.14
shell: bash
working_directory: ${{main_clone}}
commands:
- |-
export NVMRC="$(cat .nvmrc | head -n 1)"
export NODE_VERSION="${NVMRC//v/}"
if [[ -n "${NODE_VERSION}" ]]; then
echo "Node version is detected from './.nvmrc': ${NODE_VERSION}"
else
echo "Node version was not detected. Please, make sure a valid './.nvmrc' file exists in the repo root." >&2
exit 1
fi
cf_export NODE_VERSION
export NODE_IMAGE="node:${NODE_VERSION}-alpine"
echo "Node image is: ${NODE_IMAGE}"
cf_export NODE_IMAGE
when:
steps:
- name: main_clone
install_dependencies:
stage: prepare
image: ${{NODE_IMAGE}}
working_directory: ${{main_clone}}
commands:
- corepack enable
- yarn install --frozen-lockfile
when:
steps:
- name: specify_node_image
check_linting:
title: 'Check linting'
stage: test
image: ${{NODE_IMAGE}}
working_directory: ${{main_clone}}
commands:
- corepack enable
- yarn lint
when:
steps:
- name: install_dependencies
unit_tests:
title: 'Run unit tests'
stage: test
image: node:${{NODE_VERSION}}-bullseye
working_directory: ${{main_clone}}
commands:
- corepack enable
- yarn install --frozen-lockfile
- yarn test
when:
steps:
- name: install_dependencies
build:
title: "Build and Push to quay"
type: build
stage: build
buildx: true
image_name: ${{IMAGE_NAME}}
registry: cf-quay
platform: linux/amd64,linux/arm64
tags:
- ${{CF_REVISION}}
- ${{CF_BRANCH_TAG_NORMALIZED_LOWER_CASE}}
- ${{CF_BRANCH_TAG_NORMALIZED_LOWER_CASE}}-${{CF_SHORT_REVISION}}
when:
steps:
- name: main_clone
- name: unit_tests
scale:
non-prod:
tag: ${{PACKAGE_VERSION}}-${{CF_BRANCH_TAG_NORMALIZED_LOWER_CASE}}
when:
branch:
ignore: [ main, alpha ]
prod:
tag: ${{PACKAGE_VERSION}}
when:
branch:
only: [ main, alpha ]
check_release_version:
stage: publish
image: codefresh/build-cli
working_directory: ${{main_clone}}
commands:
- |-
RELEASE_ID="$(curl --fail -s -H "Authorization: token ${{GITHUB_TOKEN}}" https://api.github.com/repos/codefresh-io/${{CF_REPO_NAME}}/releases/tags/v${{PACKAGE_VERSION}} | jq .id)"
echo "Release id: ${RELEASE_ID}"
if [[ -n "${RELEASE_ID}" ]]; then
echo "Release with name \"${{PACKAGE_VERSION}}\" already exists!" >&2
exit 1
else
echo "Package version is valid: ${{PACKAGE_VERSION}}"
fi
when:
steps:
all:
- name: extract_package_version
- name: export_github_token
create_github_release:
stage: publish
image: codefresh/build-cli
commands:
- |-
curl \
--fail \
-X POST \
-H "Authorization: token ${{GITHUB_TOKEN}}" \
-H "Content-Type: application/json" \
-d '{
"tag_name": "v${{PACKAGE_VERSION}}",
"target_commitish": "${{CF_REVISION}}",
"name": "v${{PACKAGE_VERSION}}"
}' \
https://api.github.com/repos/codefresh-io/${{CF_REPO_NAME}}/releases
when:
branch:
only: [ main, alpha ]
steps:
all:
- name: build
- name: check_linting
- name: unit_tests
- name: extract_package_version