commit message #5
This file contains 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: CI | |
on: | |
push: | |
branches: | |
- main # 可根据实际情况调整分支名称 | |
jobs: | |
build-and-publish: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: '20.x' | |
registry-url: 'https://registry.npmjs.org' | |
- name: Install pnpm | |
run: | | |
npm install -g pnpm | |
- name: Install dependencies | |
run: pnpm install # 使用 pnpm 安装项目依赖 | |
- name: Build package | |
run: pnpm run build # 使用 pnpm 执行构建脚本 | |
- name: Publish to npm | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} # 在 GitHub 仓库的 Secrets 中设置 NPM_AUTH_TOKEN | |
run: pnpm publish --access public # 使用 pnpm 发布到 npm,确保 --access public 公开发布 | |
- name: Set DATE environment variable | |
run: echo "DATE=$(TZ='Asia/Shanghai' date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV | |
# 其他步骤... | |
- name: Translate job status to Chinese | |
id: translate-status | |
run: | | |
case "${{ job.status }}" in | |
success) translated_status="成功" ;; | |
failure) translated_status="失败" ;; | |
cancelled) translated_status="取消" ;; | |
*) translated_status="未知" ;; | |
esac | |
echo "translated_status=$translated_status" >> $GITHUB_ENV | |
- name: Notify job status | |
if: always() # 确保这一步始终运行,不管之前的步骤是否成功 | |
run: | | |
curl -X "POST" "${{ secrets.BARK_KEY }}" \ | |
-H 'Content-Type: application/json; charset=utf-8' \ | |
-d '{ | |
"body": "${{ github.repository }}于${{ env.DATE }}运行${{ env.translated_status }}", | |
"title": "Github Actions", | |
"badge": 1, | |
"category": "Github Actions", | |
"sound": "multiwayinvitation.caf", | |
"icon": "https://cdn.pixabay.com/photo/2022/01/30/13/33/github-6980894_1280.png", | |
"group": "Github Actions" | |
}' |