Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 41 additions & 40 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: Auto Release and Homebrew Update

on:
push:
pull_request:
types: [closed]
branches:
- main
workflow_dispatch:
Expand All @@ -22,59 +23,59 @@ jobs:
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Repository checkout
uses: actions/checkout@v4

- name: Get latest tag
- name: Get tag from PR title or latest tag
id: get_tag
run: |
git fetch --tags
latest=$(git tag --sort=-v:refname | head -n1)
if [[ -z "$latest" ]]; then
latest="v0.0.0"
TITLE="${{ github.event.pull_request.title }}"
if [[ "$TITLE" =~ (v[0-9]+\.[0-9]+\.[0-9]+) ]]; then
echo "new_tag=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
else
git fetch --tags
latest=$(git tag --sort=-v:refname | head -n1)
if [[ -z "$latest" ]]; then
latest="v0.0.0"
fi
IFS='.' read -r -a parts <<< "${latest#v}"
if [[ "${{ github.event_name }}" == "pull_request" || "${{ github.event.inputs.release-type }}" == "patch" ]]; then
major="${parts[0]}"
minor="${parts[1]}"
patch="${parts[2]}"
patch=$((patch + 1))
elif [[ "${{ github.event.inputs.release-type }}" == "minor" ]]; then
major="${parts[0]}"
minor="${parts[1]}"
minor=$((minor + 1))
patch=0
elif [[ "${{ github.event.inputs.release-type }}" == "major" ]]; then
major=$((parts[0] + 1))
minor=0
patch=0
fi
new_tag="v$major.$minor.$patch"
echo "new_tag=$new_tag" >> $GITHUB_OUTPUT
fi
echo "latest_tag=$latest" >> $GITHUB_OUTPUT

- name: Bump version
id: bump
run: |
latest="${{ steps.get_tag.outputs.latest_tag }}"
IFS='.' read -r -a parts <<< "${latest#v}"
if [[ "${{ github.event_name }}" == "push" || "${{ github.event.inputs.release-type }}" == "patch" ]]; then
major="${parts[0]}"
minor="${parts[1]}"
patch="${parts[2]}"
patch=$((patch + 1))
elif [[ "${{ github.event.inputs.release-type }}" == "minor" ]]; then
major="${parts[0]}"
minor="${parts[1]}"
minor=$((minor + 1))
patch=0
elif [[ "${{ github.event.inputs.release-type }}" == "major" ]]; then
major=$((parts[0] + 1))
minor=0
patch=0
fi
new_tag="v$major.$minor.$patch"
echo "new_tag=$new_tag" >> $GITHUB_OUTPUT

- name: Create and push tag
run: |
git config user.name "FinityFly"
git config user.email "daniel1211.lu@gmail.com"
git tag ${{ steps.bump.outputs.new_tag }}
git push origin ${{ steps.bump.outputs.new_tag }}
git tag ${{ steps.get_tag.outputs.new_tag }}
git push origin ${{ steps.get_tag.outputs.new_tag }}

- name: Create tarball
run: |
mkdir clitris-${{ steps.bump.outputs.new_tag }}
rsync -av --exclude "clitris-${{ steps.bump.outputs.new_tag }}" ./ clitris-${{ steps.bump.outputs.new_tag }}/
tar -czf clitris-${{ steps.bump.outputs.new_tag }}.tar.gz clitris-${{ steps.bump.outputs.new_tag }}
mkdir clitris-${{ steps.get_tag.outputs.new_tag }}
rsync -av --exclude "clitris-${{ steps.get_tag.outputs.new_tag }}" ./ clitris-${{ steps.get_tag.outputs.new_tag }}/
tar -czf clitris-${{ steps.get_tag.outputs.new_tag }}.tar.gz clitris-${{ steps.get_tag.outputs.new_tag }}

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.bump.outputs.new_tag }}
files: clitris-${{ steps.bump.outputs.new_tag }}.tar.gz
tag_name: ${{ steps.get_tag.outputs.new_tag }}
files: clitris-${{ steps.get_tag.outputs.new_tag }}.tar.gz

- name: Dispatch update to tap
uses: peter-evans/repository-dispatch@v3
Expand All @@ -84,6 +85,6 @@ jobs:
event-type: clitris_release
client-payload: |
{
"tarball_url": "https://github.com/FinityFly/clitris/releases/download/${{ steps.bump.outputs.new_tag }}/clitris-${{ steps.bump.outputs.new_tag }}.tar.gz",
"version": "${{ steps.bump.outputs.new_tag }}"
"tarball_url": "https://github.com/FinityFly/clitris/releases/download/${{ steps.get_tag.outputs.new_tag }}/clitris-${{ steps.get_tag.outputs.new_tag }}.tar.gz",
"version": "${{ steps.get_tag.outputs.new_tag }}"
}