This file contains hidden or 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
name: Auto Release from Tags | |
on: | |
pull_request: | |
types: [closed] | |
branches: [main] | |
jobs: | |
release: | |
if: github.event.pull_request.merged == true | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Needed to fetch all tags | |
- name: Get PR labels | |
id: labels | |
run: | | |
echo "LABELS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels \ | |
| jq -r '.[].name' | tr '\n' ' ')" >> $GITHUB_OUTPUT | |
- name: Determine bump type | |
id: bump | |
run: | | |
LABELS="${{ steps.labels.outputs.LABELS }}" | |
if [[ "$LABELS" == *"feature"* ]]; then | |
echo "BUMP=X" >> $GITHUB_OUTPUT | |
elif [[ "$LABELS" == *"bug"* ]]; then | |
echo "BUMP=Y" >> $GITHUB_OUTPUT | |
else | |
echo "BUMP=Z" >> $GITHUB_OUTPUT | |
fi | |
- name: Get latest Git tag version | |
id: current_version | |
run: | | |
tag=$(git describe --tags `git rev-list --tags --max-count=1`) | |
if [[ -z "$tag" ]]; then | |
tag="0.0.0" | |
fi | |
echo "Latest tag: $tag" | |
echo "version=$tag" >> $GITHUB_OUTPUT | |
- name: Bump version | |
id: bump_version | |
run: | | |
IFS='.' read -r X Y Z <<< "${{ steps.current_version.outputs.version }}" | |
bump="${{ steps.bump.outputs.BUMP }}" | |
if [[ "$bump" == "X" ]]; then | |
X=$((X + 1)); Y=0; Z=0 | |
elif [[ "$bump" == "Y" ]]; then | |
Y=$((Y + 1)); Z=0 | |
else | |
Z=$((Z + 1)) | |
if [[ "$Z" -ge 100 ]]; then | |
Z=0 | |
Y=$((Y + 1)) | |
fi | |
fi | |
new_version="$X.$Y.$Z" | |
echo "new_version=$new_version" >> $GITHUB_OUTPUT | |
echo "Bumped to $new_version" | |
- name: Create Git tag and push | |
run: | | |
git config user.name "github-actions" | |
git config user.email "[email protected]" | |
git tag ${{ steps.bump_version.outputs.new_version }} | |
git push origin ${{ steps.bump_version.outputs.new_version }} | |
- name: Create GitHub Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
tag_name: ${{ steps.bump_version.outputs.new_version }} |