Skip to content

Merge pull request #55 from nowscott/development #32

Merge pull request #55 from nowscott/development

Merge pull request #55 from nowscott/development #32

Workflow file for this run

name: Release
on:
push:
branches:
- main
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # 确保拉取所有历史记录和标签
- name: Get latest release tag
id: get_latest_release
run: |
LATEST_TAG=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r '.tag_name')
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
- name: Read package.json version
id: read_package_version
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV
- name: Compare versions
id: compare_versions
run: |
if [ -z "$LATEST_TAG" ]; then
echo "No previous tag found. Generating release notes from initial commit."
echo "RELEASE=true" >> $GITHUB_ENV
echo "PREVIOUS_TAG=$(git rev-list --max-parents=0 HEAD)" >> $GITHUB_ENV
elif [ "$LATEST_TAG" != "v${PACKAGE_VERSION}" ]; then
echo "Version has changed, proceeding with release."
echo "RELEASE=true" >> $GITHUB_ENV
echo "PREVIOUS_TAG=$LATEST_TAG" >> $GITHUB_ENV
else
echo "No version change detected."
echo "RELEASE=false" >> $GITHUB_ENV
fi
- name: Configure Git
if: env.RELEASE == 'true'
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
- name: Add package.json and commit changes
if: env.RELEASE == 'true'
run: |
git add package.json
git commit -m "Bump version to ${{ env.PACKAGE_VERSION }}" || echo "No changes to commit"
- name: Create and push tag
if: env.RELEASE == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git tag v${{ env.PACKAGE_VERSION }}
git push origin main --tags
- name: Create Release
if: env.RELEASE == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: actions/create-release@v1
with:
tag_name: v${{ env.PACKAGE_VERSION }}
release_name: v${{ env.PACKAGE_VERSION }}