You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
3.9 KiB
117 lines
3.9 KiB
name: _version |
|
run-name: Calculate Version |
|
|
|
on: |
|
workflow_call: |
|
inputs: |
|
is-release: |
|
type: boolean |
|
required: true |
|
outputs: |
|
version: |
|
description: "version to be built" |
|
value: ${{ jobs.version.outputs.version }} |
|
|
|
permissions: |
|
contents: read |
|
pull-requests: read |
|
issues: read |
|
|
|
jobs: |
|
version: |
|
name: Calculate Version |
|
runs-on: ubuntu-22.04 |
|
outputs: |
|
version: ${{ steps.calculate.outputs.version }} |
|
steps: |
|
- name: Checkout Repo |
|
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
|
with: |
|
fetch-depth: 0 |
|
persist-credentials: false |
|
|
|
- name: Get PR ID |
|
id: pr |
|
env: |
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
|
run: | |
|
commit_message=$( |
|
curl -s -L \ |
|
-H "Accept: application/vnd.github+json" \ |
|
-H "Authorization: Bearer $GH_TOKEN" \ |
|
-H "X-GitHub-Api-Version: 2022-11-28" \ |
|
"https://api.github.com/repos/${{ github.repository }}/commits/${{ github.sha }}" | \ |
|
jq -r ".commit.message" |
|
) |
|
ID=$(echo "$commit_message" | head -1 | grep -o "(#.*)" | grep -o "[0-9]*") |
|
echo "id=$ID" >> "$GITHUB_OUTPUT" |
|
|
|
- name: Get version bump type |
|
if: ${{ inputs.is-release }} |
|
id: bump-type |
|
env: |
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
|
PR_NUMBER: ${{ steps.pr.outputs.id }} |
|
run: | |
|
version_tag=$( |
|
curl -s -L \ |
|
-H "Accept: application/vnd.github+json" \ |
|
-H "Authorization: Bearer $GH_TOKEN" \ |
|
-H "X-GitHub-Api-Version: 2022-11-28" \ |
|
"https://api.github.com/repos/${{ github.repository }}/issues/$PR_NUMBER/labels" | \ |
|
jq -r '.[].name' | grep "version" |
|
) |
|
|
|
# Single Version label Enforcement (should go in CI...) |
|
tag_count=$(wc -w <<<"$version_tag") |
|
if [[ $tag_count -gt 1 ]]; then |
|
echo "[!] multiple version labels found!" |
|
exit 1 |
|
fi |
|
|
|
version_type=$(cut -d ":" -f 2 <<<"$version_tag") |
|
|
|
echo "Version Bump Type: $version_type" |
|
echo "type=$version_type" >> "$GITHUB_OUTPUT" |
|
|
|
- name: Calculate next version |
|
id: calculate |
|
env: |
|
VERSION_TYPE: ${{ steps.bump-type.outputs.type }} |
|
PR_ID: ${{ steps.pr.outputs.id }} |
|
run: | |
|
echo -e "\nCalculating next version..." |
|
|
|
latest_tag_version=$(git tag --sort=committerdate --list | tail -1) |
|
latest_version=${latest_tag_version:1} # remove 'v' from tag version |
|
|
|
if [[ "${{ inputs.is-release }}" == "true" ]]; then |
|
latest_major_version=$(cut -d "." -f 1 <<<"$latest_version") |
|
latest_minor_version=$(cut -d "." -f 2 <<<"$latest_version") |
|
latest_patch_version=$(cut -d "." -f 3 <<<"$latest_version") |
|
|
|
echo " latest_version: $latest_version" |
|
echo " latest_major_version: $latest_major_version" |
|
echo " latest_minor_version: $latest_minor_version" |
|
echo " latest_patch_version: $latest_patch_version" |
|
|
|
case "$VERSION_TYPE" in |
|
major) |
|
next_version="$((latest_major_version + 1)).0.0" |
|
;; |
|
minor) |
|
next_version="${latest_major_version}.$((latest_minor_version + 1)).0" |
|
;; |
|
patch) |
|
next_version="${latest_major_version}.${latest_minor_version}.$((latest_patch_version + 1))" |
|
;; |
|
*) |
|
next_version="${latest_version}+${PR_ID}" |
|
;; |
|
esac |
|
|
|
echo "Next Version: $next_version" |
|
echo "version=$next_version" >> "$GITHUB_OUTPUT" |
|
else |
|
echo "version=$latest_version+$PR_ID" >> "$GITHUB_OUTPUT" |
|
fi
|
|
|