-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
99 lines (97 loc) · 3.5 KB
/
action.yml
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
name: Get next semantic version
description: |
Calculate the next semantic version
This action calculates the next semantic version based on labels of pull-requests merged between the latest git tag and the current SHA
It needs the checkout action to run first because it uses git log for calculating time range
inputs:
token:
description: 'A Github PAT'
required: true
git_default_branch:
description: 'Default git branch'
required: false
default: "master"
outputs:
version:
description: "Git base branch"
value: ${{ steps.version_check.outputs.version }}
previous_version:
description: "Previous tagged version"
value: ${{ steps.tag_info.outputs.last_tag }}
next_version:
description: "Next version tag name"
value: ${{ steps.calcaulate-version.outputs.next_version }}
continue_release:
description: "true if it is ok to continue the release process"
value: ${{ steps.version_check.outputs.continue_release }}
runs:
using: "composite"
steps:
- name: Calculate PR filters
id: tag_info
shell: bash
run: |
last_tag_commit="$(git log -1 --exclude="*alpha*" --tags --no-walk --pretty="format:%H")"
last_tag="$(git describe --tags --abbrev=0 "$last_tag_commit")"
last_tag_date="$(git log -1 --exclude="*alpha*" --no-walk --pretty="format:%cI" "$last_tag_commit")"
start_date=$(date -Is -d "$last_tag_date")
{
echo "start_date=$start_date"
echo "last_tag=$last_tag"
echo "last_tag_commit=$last_tag_commit"
} >> "$GITHUB_OUTPUT"
- name: Get PR labels
uses: octokit/graphql-action@v2.x
id: get_latest_prs
with:
query: |
query($filter:String!) {
search(query:$filter, type: ISSUE, last: 100) {
edges {
node {
... on PullRequest {
number
mergedAt
labels (first: 100) {
nodes {
name
}
}
}
}
}
}
}
filter: repo:${{ github.repository }} is:pr base:${{ inputs.git_default_branch }} merged:>${{ steps.tag_info.outputs.start_date }}
env:
GITHUB_TOKEN: "${{ inputs.token }}"
- name: Get version being bumped
id: version_check
env:
PR_DATA: "${{ steps.get_latest_prs.outputs.data }}"
shell: bash
run: |
echo "$PR_DATA"
version=$(echo "$PR_DATA" | grep -m1 -oi major || echo "$PR_DATA" | grep -m1 -oi minor || echo "$PR_DATA" | grep -m1 -oi patch || echo "")
version_lower="${version,,}"
{
echo "version=$version_lower"
if [ -z "$version" ]; then
echo "continue_release=false"
else
echo "continue_release=true"
fi
} >> "$GITHUB_OUTPUT"
- name: Show version being bumped
if: steps.version_check.outputs.continue_release == 'true'
shell: bash
run: echo "Based on tags, we're updating ${{ steps.version_check.outputs.VERSION }} version!"
- name: Calculate version
id: calcaulate-version
shell: bash
env:
BUMP: ${{ steps.version_check.outputs.VERSION }}
PREVIOUS_VERSION: ${{ steps.tag_info.outputs.last_tag }}
run: |
NEXT_VERSION="$("${GITHUB_ACTION_PATH}/calculate-version.sh" "$BUMP" "$PREVIOUS_VERSION")"
echo "next_version=$NEXT_VERSION" >> "$GITHUB_OUTPUT"