Merge pull request #6 from nishizhen/fix/add-permissions-to-workflow

feat: Add GitHub Action for automated releases

This commit introduces a GitHub Action workflow to automate the creation of releases.

The workflow is triggered when a new tag matching the pattern 'v*.*.*' is pushed. It builds the application, creates a zip archive, and uploads it to the GitHub release.

The README.md has also been updated to include instructions on how to use this new automated release process.
This commit is contained in:
nishizhen 2025-08-15 21:38:10 +08:00 committed by GitHub
commit cb42f23cc4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 166 additions and 2 deletions

63
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,63 @@
name: Release
on:
push:
tags:
- 'v*.*.*'
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: mbstring, intl, gd, sqlite3, pdo_sqlite, zip, bcmath
coverage: none
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install Composer dependencies
run: composer install --no-interaction --no-progress --no-suggest --no-dev --optimize-autoloader
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
cache: 'yarn'
- name: Install Node.js dependencies
run: yarn install --frozen-lockfile
- name: Get version
id: get_version
run: echo "VERSION=$(grep -o '\"version\": \"[^\"]*' version.json | grep -o '[^"]*$')" >> $GITHUB_ENV
- name: Build release package
run: |
chmod +x release.sh
./release.sh
- name: Create Release and Upload Asset
uses: softprops/action-gh-release@v1
with:
files: "grocy_${{ env.VERSION }}.zip"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -61,13 +61,45 @@
### 方式二:手动安装
如果您熟悉网站搭建,可以按照以下步骤进行手动安装:
1. 下载 [最新发布版](https://releases.grocy.info/latest)。
对于熟悉网站环境搭建的用户,可以选择手动安装。
#### 1. 下载预编译包
您可以直接从本项目的 [GitHub Releases](https://github.com/nishizhen/AnticlockwiseGrocy/releases) 页面下载最新的 `grocy_x.x.x.zip` 包。这个包里已经包含了所有必需的依赖,开箱即用。
#### 2. 自行打包(适合开发者)
如果您想基于最新的源代码自行打包,可以按以下步骤操作:
1. 确保您的开发环境中已安装 `bash`, `zip`, `composer``yarn`
2. 在项目根目录下,运行打包脚本:
```bash
./release.sh
```
3. 脚本执行成功后,会在项目根目录下生成一个 `grocy_x.x.x.zip` 文件。
#### 3. 安装步骤
获取到 `zip` 包后,请按照以下步骤进行安装:
1. 将 `zip` 包解压到您的网站服务器的指定目录。
2. 将 `config-dist.php` 复制为 `data/config.php`,并根据您的需求进行修改。
3. 确保 `data` 目录具有写入权限。
4. 将您的网站服务器根目录指向 `public` 目录。
5. 默认登录用户为 `admin`,密码为 `admin`,请在登录后立即修改密码。
#### 4. 自动发布 (GitHub Actions)
本项目已配置 [GitHub Actions](https://github.com/features/actions),可以在您创建新的 release 时自动构建和上传安装包。
要触发自动发布,请按以下步骤操作:
1. 确保您的代码已提交到 `master` 分支。
2. 基于 `master` 分支创建一个新的 tag并推送到 GitHub。tag 的名字需要符合 `v*.*.*` 的格式,例如 `v1.2.3`
```bash
git tag v1.2.3
git push origin v1.2.3
```
3. 推送 tag 后GitHub Actions 会自动开始构建,并将生成的 `grocy_x.x.x.zip` 文件上传到您刚刚创建的 release 页面。
更多详细的安装说明和帮助,请参考原版 Grocy 的文档。我们正在努力编写更符合中国用户习惯的中文文档。
## 未来计划 (Roadmap)

69
release.sh Executable file
View File

@ -0,0 +1,69 @@
#!/bin/bash
# Exit on any error
set -e
# --- Config ---
# Get the version from version.json
VERSION=$(grep -o '"version": "[^"]*' version.json | grep -o '[^"]*$')
RELEASE_NAME="grocy"
RELEASE_FILE_NAME="${RELEASE_NAME}_${VERSION}.zip"
RELEASE_BUILD_DIR=".release"
RELEASE_APP_DIR="${RELEASE_BUILD_DIR}/${RELEASE_NAME}"
# ---
echo "▶️ Starting release creation of version ${VERSION}..."
# ---------------------------------------------------------------------------------------------------------
echo "▶️ 1. Initial cleanup..."
rm -f ${RELEASE_FILE_NAME}
rm -rf ${RELEASE_BUILD_DIR}
mkdir -p ${RELEASE_APP_DIR}
# ---------------------------------------------------------------------------------------------------------
echo "▶️ 2. Installing composer dependencies..."
composer install --no-dev --optimize-autoloader
# ---------------------------------------------------------------------------------------------------------
echo "▶️ 3. Installing npm dependencies..."
yarn install
# ---------------------------------------------------------------------------------------------------------
echo "▶️ 4. Copying all application files..."
rsync -av . ${RELEASE_APP_DIR} \
--exclude ".git" \
--exclude ".github" \
--exclude ".gitignore" \
--exclude ".gitattributes" \
--exclude ".devcontainer" \
--exclude ".release" \
--exclude "release.sh" \
--exclude "tests" \
--exclude ".editorconfig" \
--exclude ".php-cs-fixer.php" \
--exclude ".tx" \
--exclude ".vscode" \
--exclude ".yarnrc" \
--exclude "yarn.lock" \
--exclude "package.json" \
--exclude "composer.json" \
--exclude "composer.lock"
# ---------------------------------------------------------------------------------------------------------
echo "▶️ 5. Creating the release ZIP archive..."
cd ${RELEASE_BUILD_DIR}
zip -r ../${RELEASE_FILE_NAME} .
cd ..
# ---------------------------------------------------------------------------------------------------------
echo "▶️ 6. Final cleanup..."
rm -rf ${RELEASE_BUILD_DIR}
# ---------------------------------------------------------------------------------------------------------
echo "✅ Release successfully created: ${RELEASE_FILE_NAME}"