mirror of
https://github.com/OpenListTeam/OpenList-Desktop.git
synced 2025-11-25 03:14:56 +08:00
135 lines
4.4 KiB
YAML
135 lines
4.4 KiB
YAML
name: 'Auto Version and Release'
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: write
|
|
packages: write
|
|
|
|
jobs:
|
|
check-commits:
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
should-release: ${{ steps.check.outputs.should-release }}
|
|
version-type: ${{ steps.check.outputs.version-type }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Check for conventional commits
|
|
id: check
|
|
run: |
|
|
# Get commits since last tag
|
|
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
|
|
|
|
if [ -z "$LAST_TAG" ]; then
|
|
echo "No previous tag found, will create initial release"
|
|
echo "should-release=true" >> $GITHUB_OUTPUT
|
|
echo "version-type=minor" >> $GITHUB_OUTPUT
|
|
exit 0
|
|
fi
|
|
|
|
COMMITS=$(git log $LAST_TAG..HEAD --oneline)
|
|
|
|
if echo "$COMMITS" | grep -qE "^[a-f0-9]+ (feat|fix|BREAKING CHANGE)"; then
|
|
echo "Found commits that warrant a release"
|
|
echo "should-release=true" >> $GITHUB_OUTPUT
|
|
|
|
# Determine version bump type
|
|
if echo "$COMMITS" | grep -q "BREAKING CHANGE"; then
|
|
echo "version-type=major" >> $GITHUB_OUTPUT
|
|
elif echo "$COMMITS" | grep -q "feat"; then
|
|
echo "version-type=minor" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "version-type=patch" >> $GITHUB_OUTPUT
|
|
fi
|
|
else
|
|
echo "No commits found that warrant a release"
|
|
echo "should-release=false" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
auto-release:
|
|
needs: check-commits
|
|
if: needs.check-commits.outputs.should-release == 'true'
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 'lts/*'
|
|
|
|
- name: Calculate new version
|
|
id: version
|
|
run: |
|
|
# Get current version from package.json
|
|
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
|
echo "Current version: $CURRENT_VERSION"
|
|
|
|
# Parse version
|
|
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
|
|
MAJOR=${VERSION_PARTS[0]}
|
|
MINOR=${VERSION_PARTS[1]}
|
|
PATCH=${VERSION_PARTS[2]}
|
|
|
|
# Bump version based on commit type
|
|
case "${{ needs.check-commits.outputs.version-type }}" in
|
|
major)
|
|
MAJOR=$((MAJOR + 1))
|
|
MINOR=0
|
|
PATCH=0
|
|
;;
|
|
minor)
|
|
MINOR=$((MINOR + 1))
|
|
PATCH=0
|
|
;;
|
|
patch)
|
|
PATCH=$((PATCH + 1))
|
|
;;
|
|
esac
|
|
|
|
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
|
|
echo "New version: $NEW_VERSION"
|
|
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
|
echo "tag=v$NEW_VERSION" >> $GITHUB_OUTPUT
|
|
|
|
- name: Update version in files
|
|
run: |
|
|
# Update package.json
|
|
npm version ${{ steps.version.outputs.version }} --no-git-tag-version
|
|
|
|
# Update Cargo.toml
|
|
sed -i 's/^version = "[^"]*"/version = "${{ steps.version.outputs.version }}"/' src-tauri/Cargo.toml
|
|
|
|
# Update tauri.conf.json
|
|
sed -i 's/"version": "[^"]*"/"version": "${{ steps.version.outputs.version }}"/' src-tauri/tauri.conf.json
|
|
|
|
- name: Commit version bump
|
|
run: |
|
|
git config --local user.email "action@github.com"
|
|
git config --local user.name "GitHub Action"
|
|
git add package.json src-tauri/Cargo.toml src-tauri/tauri.conf.json
|
|
git commit -m "chore: bump version to ${{ steps.version.outputs.version }} [skip ci]"
|
|
git push
|
|
|
|
- name: Create and push tag
|
|
run: |
|
|
git tag ${{ steps.version.outputs.tag }}
|
|
git push origin ${{ steps.version.outputs.tag }}
|
|
|
|
- name: Trigger release workflow
|
|
run: |
|
|
curl -X POST \
|
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
|
-H "Accept: application/vnd.github.v3+json" \
|
|
https://api.github.com/repos/${{ github.repository }}/actions/workflows/release.yml/dispatches \
|
|
-d '{"ref":"main","inputs":{"version":"${{ steps.version.outputs.tag }}"}}'
|