Skip to content
This repository has been archived by the owner on Dec 20, 2022. It is now read-only.

[skip] Fixes to keep pipelines consistency #61

Merged
merged 10 commits into from
May 29, 2020
Merged

Conversation

kyfujisa
Copy link
Contributor

@kyfujisa kyfujisa commented May 25, 2020

As a fix to keep pipelines consistent, the first step.

confirmation

test.sh

#mkdir -p $HOME/.ssh/ && echo -e "Host github.com\n\tStrictHostKeyChecking no\n" > ~/.ssh/config
#LAST_COMMIT=`git log -1 --pretty=%B`
LAST_COMMIT=$1
#if [ ! -z $CIRCLE_PULL_REQUEST ]; then
#  PR_NUM="${CIRCLE_PULL_REQUEST##*/}"
#  LAST_COMMIT=`curl -s ${GITHUB_API}repos/${REPO_NAME}/${IMAGE_NAME}/pulls/${PR_NUM} | jq .title`
#fi
touch ./.tag
# Diff to prevent pipeline re-runs.
#if VERSION=`git describe --abbrev=0 --tags` && [ ! -z "`git diff $VERSION`" -o -z "$VERSION" ]; then
#VERSION=`git describe --abbrev=0 --tags`
VERSION=$2
#if [ ! -z "`git diff $VERSION`" -o -z "$VERSION" ]; then
if [ -n "$3" ]; then
  VERSION=${VERSION:-'0.0.0'}
  MAJOR="${VERSION%%.*}"; MAJOR="${MAJOR#v}"; VERSION="${VERSION#*.}"
  MINOR="${VERSION%%.*}"; VERSION="${VERSION#*.}"
  PATCH="${VERSION%%.*}"; VERSION="${VERSION#*.}"
  case "$LAST_COMMIT" in
  '[patch]'* | '[PATCH]'*)
    PATCH=$((PATCH+1))
    echo "v$MAJOR.$MINOR.$PATCH" > ./.tag
    ;;
  '[minor]'* | '[MINOR]'*)
    MINOR=$((MINOR+1))
    echo "v$MAJOR.$MINOR.0" > ./.tag
    ;;
  '[major]'* | '[MAJOR]'*)
    MAJOR=$((MAJOR+1))
    echo "v$MAJOR.0.0" > ./.tag
    ;;
  # Don't release (nightly images only)
  '[skip]'* | '[SKIP]'*)
    echo "Skip release..."
    ;;
  # Don't want to run CI.
  '[skip ci]'* | '[ci skip]'*)
    echo "Will skip CI..."
    ;;
  *)
    echo "Required prefixes: [major]/[minor]/[patch]/[skip]/[skip ci]"
    exit 1
    ;;
  esac
else
  if [ -n "$VERSION" ]; then
    echo "No diff, skip tagging..."
  else
    echo "No diff, No tag. Tag it as \"v0.0.0\"."
    echo "v0.0.0" > ./.tag
  fi
fi

# print tag
cat ./.tag
rm ./.tag

exit 0

check

$ # tag check
$ sh test.sh '[patch] commit' v1.1.1 diff
v1.1.2
$ sh test.sh '[minor] commit' v1.1.1 diff
v1.2.0
$ sh test.sh '[major] commit' v1.1.1 diff
v2.0.0
$ sh test.sh '[skip] commit' v1.1.1 diff
Skip release...
$ sh test.sh '[skip ci] commit' v1.1.1 diff
Will skip CI...
$ sh test.sh 'no tag commit' v1.1.1 diff
Required prefixes: [major]/[minor]/[patch]/[skip]/[skip ci]
$ echo $?
1
$ # no version
$ sh test.sh '[patch] commit' '' 'diff'
v0.0.1
$ sh test.sh '[minor] commit' '' 'diff'
v0.1.0
$ sh test.sh '[major] commit' '' 'diff'
v1.0.0
$ # no diff
$ sh test.sh '[major] commit' 'v2.0.0' ''
No diff, skip tagging...
$ sh test.sh '[major] commit' '' ''
No diff, No tag. Tag it as "v0.0.0".
v0.0.0
$ sh test.sh 'no tag commit' 'v2.0.0' ''
No diff, skip tagging...
$ sh test.sh 'no tag commit' '' ''
No diff, No tag. Tag it as "v0.0.0".
v0.0.0

@kyfujisa kyfujisa changed the title Fixes to keep pipelines consistency [skip] Fixes to keep pipelines consistency May 25, 2020
@kyfujisa
Copy link
Contributor Author

I think this issue has something to do with the failure of the pipeline.
docker/cli#2533

@WindzCUHK
Copy link
Contributor

I think this issue has something to do with the failure of the pipeline.

@kyfujisa please update the docker version in pipeline.
referenece: yahoojapan/garm@7947224

@codecov-commenter
Copy link

codecov-commenter commented May 25, 2020

Codecov Report

Merging #61 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #61   +/-   ##
=======================================
  Coverage   87.02%   87.02%           
=======================================
  Files          14       14           
  Lines         655      655           
=======================================
  Hits          570      570           
  Misses         75       75           
  Partials       10       10           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4dfc749...1a683e2. Read the comment docs.

.circleci/config.yml Outdated Show resolved Hide resolved
.circleci/config.yml Outdated Show resolved Hide resolved
@WindzCUHK
Copy link
Contributor

try to simply the logic as below

case.sh

#!/bin/sh

# LAST_COMMIT="$(git log -1 --pretty=%B)"
LAST_COMMIT="$1"
# if [ ! -z $CIRCLE_PULL_REQUEST ]; then
#   PR_NUM="${CIRCLE_PULL_REQUEST##*/}"
#   LAST_COMMIT=`curl -s ${GITHUB_API}repos/${REPO_NAME}/${IMAGE_NAME}/pulls/${PR_NUM} | jq .title`
# fi
touch ./.tag

# VERSION="$(git describe --abbrev=0 --tags)"
VERSION="$2"
# if [ -n "$(git diff $VERSION)" ]; then
if [ -n "$3" ]; then
  VERSION=${VERSION:-'v0.0.0'}
  MAJOR="${VERSION%%.*}"; MAJOR="${MAJOR#v}"; VERSION="${VERSION#*.}"
  MINOR="${VERSION%%.*}"; VERSION="${VERSION#*.}"
  PATCH="${VERSION%%.*}"; VERSION="${VERSION#*.}"

  case "$LAST_COMMIT" in
    '[patch]'*)
      PATCH=$((PATCH+1))
      echo "v$MAJOR.$MINOR.$PATCH" > ./.tag
      ;;
    '[minor]'*)
      MINOR=$((MINOR+1))
      echo "v$MAJOR.$MINOR.0" > ./.tag
      ;;
    '[major]'*)
      MAJOR=$((MAJOR+1))
      echo "v$MAJOR.0.0" > ./.tag
      ;;
    '[skip]'*)
      echo "Skip release..."
      ;;
    '[skip ci]'* | '[ci skip]'*)
      echo "Will skip CI..."
      ;;
    *)
      echo "Required prefixes: [major]/[minor]/[patch]/[skip]/[skip ci]"
      exit 1
  esac
else
  echo "NO diff, skip tagging..."
fi

cat ./.tag
rm ./.tag

exit 0

output

$ sh case.sh '[patch] commit' v1.1.1 diff
v1.1.2
$ sh case.sh '[minor] commit' v1.1.1 diff
v1.2.0
$ sh case.sh '[major] commit' v1.1.1 diff
v2.0.0
$ sh case.sh '[skip] commit' v1.1.1 diff
Skip release...
$ sh case.sh '[skip ci] commit' v1.1.1 diff
Will skip CI...
$ sh case.sh '[-] commit' v1.1.1 diff
Required prefixes: [major]/[minor]/[patch]/[skip]/[skip ci]
$ echo $?
1
$ sh case.sh '[patch] commit' v1.1.1 ""
NO diff, skip tagging...
$ sh case.sh '[patch] commit' '' 'diff'
v0.0.1
$ sh case.sh '[minor] commit' '' 'diff'
v0.1.0
$ sh case.sh '[major] commit' '' 'diff'
v1.0.0
$ sh case.sh '[major] commit' 'v2.0.2' 'diff'
v3.0.0
$ sh case.sh '[minor] commit' 'v2.0.2' 'diff'
v2.1.0
$ sh case.sh '[patch] commit' 'v2.0.2' 'diff'
v2.0.3

@kyfujisa kyfujisa changed the title [skip] Fixes to keep pipelines consistency [patch] Fixes to keep pipelines consistency May 28, 2020
@WindzCUHK
Copy link
Contributor

WindzCUHK and others added 2 commits May 28, 2020 17:26
@kyfujisa kyfujisa changed the title [patch] Fixes to keep pipelines consistency [skip] Fixes to keep pipelines consistency May 28, 2020
@WindzCUHK WindzCUHK changed the title [skip] Fixes to keep pipelines consistency [fail] Fixes to keep pipelines consistency May 29, 2020
@WindzCUHK WindzCUHK changed the title [fail] Fixes to keep pipelines consistency [skip ci] Fixes to keep pipelines consistency May 29, 2020
@WindzCUHK WindzCUHK changed the title [skip ci] Fixes to keep pipelines consistency [SKIP] Fixes to keep pipelines consistency May 29, 2020
@WindzCUHK WindzCUHK changed the title [SKIP] Fixes to keep pipelines consistency [major] Fixes to keep pipelines consistency May 29, 2020
@WindzCUHK WindzCUHK changed the title [major] Fixes to keep pipelines consistency [skip] Fixes to keep pipelines consistency May 29, 2020
Copy link
Contributor

@WindzCUHK WindzCUHK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@WindzCUHK WindzCUHK merged commit d5e4587 into master May 29, 2020
@WindzCUHK WindzCUHK deleted the pipeline-consistency branch May 29, 2020 02:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants