yahoojapan / authorization-proxy

Moved to https://github.com/AthenZ/authorization-proxy
https://github.com/AthenZ/authorization-proxy
Apache License 2.0
35 stars 9 forks source link

[skip] Fixes to keep pipelines consistency #61

Closed kyfujisa closed 4 years ago

kyfujisa commented 4 years ago

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 commented 4 years ago

I think this issue has something to do with the failure of the pipeline. https://github.com/docker/cli/issues/2533

WindzCUHK commented 4 years ago

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

@kyfujisa please update the docker version in pipeline. referenece: https://github.com/yahoojapan/garm/pull/39/commits/79472244b64c251ac24111c104d2330b785c372f

codecov-commenter commented 4 years ago

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.

WindzCUHK commented 4 years ago

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
WindzCUHK commented 4 years ago

jq => jq -r fixed: https://github.com/yahoojapan/authorization-proxy/pull/61/files/23a3dbbd5a85ea33dc638f2f5e0ab51ca3fee278..ef95e570552a2b5c2296ae58ca9ace9dd7f8e037