Skip to content

Commit 4f388f9

Browse files
author
Amir Moualem
authored
Merge pull request #103 from snyk/chore/semantic_release_after_tests
chore: semantic-release remake
2 parents 4b354db + fdf7ac7 commit 4f388f9

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

.travis.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ install:
2020
jobs:
2121
include:
2222
######################## PR TO STAGING ########################
23-
# PR tests for staging branch
2423
- stage: Test-PR-staging
2524
if: branch = staging AND type = pull_request
2625
script: npm run test
@@ -32,19 +31,20 @@ jobs:
3231
npm run build &&
3332
npm run test:unit &&
3433
docker login --username ${DOCKERHUB_USER} --password ${DOCKERHUB_PASSWORD} &&
35-
npx semantic-release &&
36-
NEW_VERSION=`cat ./package.json | jq -r '.version'` &&
37-
IMAGE_NAME_CANDIDATE=snyk/kubernetes-monitor:${NEW_VERSION}-candidate &&
34+
IMAGE_NAME_CANDIDATE=snyk/kubernetes-monitor:staging-candidate &&
3835
./scripts/build-image.sh ${IMAGE_NAME_CANDIDATE} &&
3936
docker push ${IMAGE_NAME_CANDIDATE} &&
4037
./scripts/slack-notify-push.sh ${IMAGE_NAME_CANDIDATE} &&
41-
KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG=${IMAGE_NAME_CANDIDATE} npm run test:integration &&
42-
IMAGE_NAME_APPROVED=snyk/kubernetes-monitor:${NEW_VERSION}-approved &&
43-
docker tag ${IMAGE_NAME_CANDIDATE} ${IMAGE_NAME_APPROVED} &&
44-
docker push ${IMAGE_NAME_APPROVED} &&
45-
./scripts/slack-notify-push.sh ${IMAGE_NAME_APPROVED} ||
46-
./scripts/slack-notify-failure.sh staging
38+
KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG=${IMAGE_NAME_CANDIDATE} npm run test:integration ||
39+
( ./scripts/slack-notify-failure.sh "staging-test" && false )
4740
name: Test and Build
41+
- stage: tag-and-push
42+
if: branch = staging AND type = push
43+
script: npx semantic-release &&
44+
NEW_VERSION=`cat ./package.json | jq -r '.version'` &&
45+
./scripts/approve-image.sh $NEW_VERSION ||
46+
( ./scripts/slack-notify-failure.sh "staging-release" && false )
47+
name: Tag and Push
4848
######################## PR TO MASTER ########################
4949
- stage: pre-publish
5050
if: branch = master AND type = pull_request AND head_branch = staging
@@ -65,7 +65,7 @@ jobs:
6565
docker tag ${IMAGE_NAME_APPROVED} snyk/kubernetes-monitor:latest &&
6666
docker push ${IMAGE_NAME_PUBLISHED} &&
6767
./scripts/slack-notify-push.sh snyk/kubernetes-monitor:latest ||
68-
./scripts/slack-notify-failure.sh master
68+
( ./scripts/slack-notify-failure.sh master && false )
6969
name: publish the kubernetes-monitor (npm, container, helm)
7070
branches:
7171
only:

scripts/approve-image.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#! /bin/bash
2+
3+
# $1 is the version from package.json
4+
# if semantic release chooses not to release (only chores for example)
5+
# then it would be null
6+
if [ $1 == "null" ]; then
7+
echo Semantic-Release did not create a new version, not pushing a new approved image
8+
else
9+
IMAGE_NAME_CANDIDATE=snyk/kubernetes-monitor:staging-candidate
10+
IMAGE_NAME_APPROVED=snyk/kubernetes-monitor:${1}-approved
11+
12+
docker tag ${IMAGE_NAME_CANDIDATE} ${IMAGE_NAME_APPROVED}
13+
docker push ${IMAGE_NAME_APPROVED}
14+
./scripts/slack-notify-push.sh ${IMAGE_NAME_APPROVED}
15+
fi

0 commit comments

Comments
 (0)