Skip to content

chore(project): 更新项目版本号 #63

chore(project): 更新项目版本号

chore(project): 更新项目版本号 #63

Workflow file for this run

name: 构建并发布 PHP 项目
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch: # 允许手动触发
permissions: write-all
concurrency:
group: "${{ github.workflow }} - ${{ github.head_ref || github.ref }}"
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
build-release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
# 检出代码
- name: 检出代码
uses: actions/checkout@v4
# 设置 PHP 环境
- name: 设置 PHP 环境
uses: shivammathur/setup-php@v2
with:
php-version: '8.0' # 可根据 ThinkPHP 版本调整
extensions: mbstring, curl, json, openssl, fileinfo
tools: composer
# 缓存 Composer 依赖
- name: 缓存 Composer 依赖
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
cache-on-failure: true # 即使步骤失败也缓存
# 安装 Composer 依赖
- name: 安装依赖
run: composer install --prefer-dist --no-progress --no-dev --optimize-autoloader
# 获取版本号
- name: 获取版本号
run: |
sudo apt-get update
sudo apt-get install -y jq
echo "VERSION=$(jq -r '.version' composer.json)" >> $GITHUB_ENV
echo "BUILDTIME=$(TZ=Asia/Shanghai date)" >> $GITHUB_ENV
# 创建构建产物
- name: 创建构建产物
run: |
zip -r release-${{ env.VERSION }}-${{ github.run_id }}.zip . -x "runtime/*" ".git/*" ".github/*"
# 列出打包文件
- name: 列出打包文件
run: unzip -l release-${{ env.VERSION }}-${{ github.run_id }}.zip
if: always() # 即使失败也运行,便于调试
# 上传构建产物
- name: 上传构建产物
uses: actions/upload-artifact@v4
with:
name: php-release-${{ env.VERSION }}-${{ github.run_id }}
path: release-${{ env.VERSION }}-${{ github.run_id }}.zip
# 创建 GitHub 发布
- name: 创建 GitHub 发布
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ env.VERSION }}
name: DeltaForce API v${{ env.VERSION }}
body: |
自动构建提交版 ${{ github.sha }} 构建时间:${{ env.BUILDTIME }}.
draft: false
prerelease: false
files: release-${{ env.VERSION }}-${{ github.run_id }}.zip
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN || github.token }}