ci: add release workflow
This commit is contained in:
parent
5d1c8ca255
commit
e9e1483a3a
75
.github/workflows/release.yml
vendored
Normal file
75
.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
name: Automatic Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- release
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Set up Node.js 16.15.1
|
||||||
|
uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: 16.15.1
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: npm run build:prod
|
||||||
|
|
||||||
|
- name: Extract project version from package.json
|
||||||
|
run: |
|
||||||
|
VERSION=$(node -p "require('./package.json').version")
|
||||||
|
echo "PROJECT_VERSION=$VERSION" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Generate Release Notes
|
||||||
|
id: generate_release_notes
|
||||||
|
run: |
|
||||||
|
git fetch --prune --unshallow
|
||||||
|
LATEST_TAG=$(git describe --tags --abbrev=0)
|
||||||
|
FEAT_MSGS=$(git log $LATEST_TAG..HEAD --grep 'feat:' --pretty=format:"- %s%n")
|
||||||
|
FIX_MSGS=$(git log $LATEST_TAG..HEAD --grep 'fix:' --pretty=format:"- %s%n")
|
||||||
|
PERF_MSGS=$(git log $LATEST_TAG..HEAD --grep 'perf:' --pretty=format:"- %s%n")
|
||||||
|
RELEASE_NOTES="### 新功能 ✨\n${FEAT_MSGS}\n### 修复 🐛\n${FIX_MSGS}\n### 优化 🎨\n${PERF_MSGS}"
|
||||||
|
echo -e "RELEASE_NOTES<<EOF\n$RELEASE_NOTES\nEOF" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Create Git tag
|
||||||
|
run: |
|
||||||
|
git config user.name "GitHub Actions"
|
||||||
|
git config user.email "github-actions@users.noreply.github.com"
|
||||||
|
git tag -a v${{ env.PROJECT_VERSION }} -m "v${{ env.PROJECT_VERSION }}"
|
||||||
|
git push origin v${{ env.PROJECT_VERSION }}
|
||||||
|
|
||||||
|
- name: Create Release
|
||||||
|
id: create_release
|
||||||
|
uses: actions/create-release@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
tag_name: v${{ env.PROJECT_VERSION }}
|
||||||
|
release_name: v${{ env.PROJECT_VERSION }}
|
||||||
|
body: |
|
||||||
|
Changes in this release:
|
||||||
|
${{ env.RELEASE_NOTES }}
|
||||||
|
draft: false
|
||||||
|
prerelease: false
|
||||||
|
|
||||||
|
- name: Package dist directory
|
||||||
|
run: tar czf dist.tar.gz dist
|
||||||
|
|
||||||
|
- name: Upload dist.tar.gz to Release
|
||||||
|
uses: actions/upload-release-asset@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
|
asset_path: ./dist.tar.gz
|
||||||
|
asset_name: dist.tar.gz
|
||||||
|
asset_content_type: application/gzip
|
||||||
Loading…
x
Reference in New Issue
Block a user