forked from ml-archive/ci-bitrise-changelog-step
-
Notifications
You must be signed in to change notification settings - Fork 1
/
step.sh
executable file
·64 lines (54 loc) · 2.22 KB
/
step.sh
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
#!/bin/bash
# Fail if any command fails
set -e
# Read all tags, separate them into an array
all_tags=`git tag -l | wc -l`
if [ $all_tags = 0 ]; then
# No tags, exit.
echo "Repository contains no tags. Please make a tag first."
exit 1
elif [ $all_tags = 1 ]; then
echo "Fetching commits since first commit."
# We have first tag, fetch since first commit (ie. don't specify previous tag)
if [ -n "${markdown_output}" -a "${markdown_output}" == "true" ]; then
changelog="$(git log --pretty=format:" - %s (%cd) _<%ce>_") --date=format:"%Y-%m-%d %H:%M:%S""
else
changelog="$(git log --pretty=format:" - %s (%cd) _<%ce>_") --date=format:"%Y-%m-%d %H:%M:%S""
fi
else
echo "Fetching commits since last tag."
# We have many tags, fetch since last one
latest_tag=`git describe --tags`
previous_tag="$(git describe --abbrev=0 --tags $(git rev-list --tags --skip=1 --max-count=1))"
# Get commit messages since previous tag
if [ -n "${markdown_output}" -a "${markdown_output}" == "true" ]; then
changelog="$(git log --pretty=format:" - %s (%cd) _<%ce>_" --date=format:"%Y-%m-%d %H:%M:%S" $latest_tag...$previous_tag)"
else
changelog="$(git log --pretty=format:"%s (%cd) _<%ce>_" --date=format:"%Y-%m-%d %H:%M:%S" $latest_tag...$previous_tag)"
fi
fi
# Add branch info
branch="$(git branch --contains ${GIT_CLONE_COMMIT_HASH})"
branch=${branch:2}
NEWLINE=$'\n'
if [ -n "$branch" ]; then
if [[ "$branch" == *"feature"* ]]; then
branchinfo="*_WARNING_*: This is a _FEATURE_ build on *${branch}*${NEWLINE}${NEWLINE}"
changelog=$branchinfo$changelog
elif [[ "$branch" == *"hotfix"* ]]; then
branchinfo="*_WARNING_*: This is a _HOTFIX_ build on *${branch}*${NEWLINE}${NEWLINE}"
changelog=$branchinfo$changelog
else
branchinfo="Built on *${branch}*${NEWLINE}${NEWLINE}"
changelog=$branchinfo$changelog
fi
fi
# Output collected information
echo "Committer: $(git log --pretty=format:"%ce" HEAD^..HEAD)"
echo "Latest tag: $latest_tag"
echo "Previous tag: $previous_tag"
echo "Changelog:"
echo "$changelog"
# Set environment variable for bitrise
envman add --key COMMIT_CHANGELOG --value "$changelog"
exit 0