-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add version reusable workflow * Add PR version to enforce version label
- Loading branch information
1 parent
f670f35
commit 60e6af5
Showing
2 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
name: Enforce PR labels | ||
|
||
on: | ||
workflow_call: | ||
|
||
jobs: | ||
enforce-label: | ||
if: ${{ contains(github.event.*.labels.*.name, 'hold') || contains(github.event.*.labels.*.name, 'needs-qa') }} | ||
name: Enforce label | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Check for label | ||
run: | | ||
echo "PRs with the hold or needs-qa labels cannot be merged" | ||
echo "### :x: PRs with the hold or needs-qa labels cannot be merged" >> $GITHUB_STEP_SUMMARY | ||
exit 1 | ||
enforce-version-label: | ||
if: ${{ contains(github.event.*.labels.*.name, 'version') }} | ||
name: Enforce version label | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- name: Check for label | ||
run: | | ||
echo "PR without the version label cannot be merged." | ||
echo "### :x: PR without the version label cannot be merged" >> $GITHUB_STEP_SUMMARY | ||
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
--- | ||
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 }} | ||
|
||
jobs: | ||
version: | ||
name: Calculate Version | ||
runs-on: ubuntu-22.04 | ||
outputs: | ||
version: ${{ steps.calculate.outputs.version }} | ||
steps: | ||
- name: Checkout Repo | ||
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- 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...) | ||
if [[ $(echo $version_tag | wc -w) -gt 1 ]]; then | ||
echo "[!] multiple version labels found!" | ||
exit 1 | ||
fi | ||
version_type=$(echo $version_tag | cut -d ":" -f 2) | ||
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 }} | ||
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=$(echo $latest_version | cut -d "." -f 1) | ||
latest_minor_version=$(echo $latest_version | cut -d "." -f 2) | ||
latest_patch_version=$(echo $latest_version | cut -d "." -f 3) | ||
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" | ||
if [[ "$VERSION_TYPE" == "major" ]]; then | ||
next_version="$(($latest_major_version + 1)).0.0" | ||
elif [[ "$VERSION_TYPE" == "minor" ]]; then | ||
next_version="${latest_major_version}.$(($latest_minor_version + 1)).0" | ||
elif [[ "$VERSION_TYPE" == "patch" ]]; then | ||
next_version="${latest_major_version}.${latest_minor_version}.$(($latest_patch_version + 1))" | ||
else | ||
next_version="$latest_version+${{ steps.pr.outputs.id }}" | ||
fi | ||
echo "Next Version: $next_version" | ||
echo "version=$next_version" >> $GITHUB_OUTPUT | ||
else | ||
echo "version=$latest_version+${{ steps.pr.outputs.id }}" >> $GITHUB_OUTPUT | ||
fi |