ci: 完全不依赖 GitHub 的 workflow
- 使用 git clone 代替 actions/checkout - 所有操作使用基础命令 - 不依赖任何 GitHub Actions 适用场景: - Gitea Actions 无法访问 GitHub - 完全离线环境 - 安全要求高的环境
This commit is contained in:
@@ -4,17 +4,22 @@ on:
|
|||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- 'v*'
|
- 'v*'
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-windows:
|
build:
|
||||||
name: Build Windows
|
name: Build Windows
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Clone repository
|
||||||
uses: actions/checkout@v4
|
run: |
|
||||||
|
git clone ${GITEA_SERVER_URL}/${GITEA_REPOSITORY}.git .
|
||||||
|
git checkout ${GITEA_REF_NAME}
|
||||||
|
env:
|
||||||
|
GITEA_SERVER_URL: http://192.168.120.110:4000
|
||||||
|
GITEA_REPOSITORY: damai/readflow
|
||||||
|
GITEA_REF_NAME: ${{ github.ref_name }}
|
||||||
|
|
||||||
- name: Install Rust
|
- name: Install Rust
|
||||||
run: |
|
run: |
|
||||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal
|
||||||
@@ -42,28 +47,25 @@ jobs:
|
|||||||
cp target/x86_64-pc-windows-gnu/release/readflow.exe dist/
|
cp target/x86_64-pc-windows-gnu/release/readflow.exe dist/
|
||||||
cd dist
|
cd dist
|
||||||
echo "ReadFlow for Windows" > README.txt
|
echo "ReadFlow for Windows" > README.txt
|
||||||
echo "Version: ${{ github.ref_name }}" >> README.txt
|
echo "Version: ${GITEA_REF_NAME}" >> README.txt
|
||||||
echo "" >> README.txt
|
|
||||||
echo "Usage: Double click readflow.exe" >> README.txt
|
|
||||||
zip -r readflow-windows-x86_64.zip readflow.exe README.txt
|
zip -r readflow-windows-x86_64.zip readflow.exe README.txt
|
||||||
|
|
||||||
- name: Upload to Release
|
- name: Upload to Release
|
||||||
env:
|
|
||||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
||||||
GITEA_URL: http://192.168.120.110:4000
|
|
||||||
REPO: damai/readflow
|
|
||||||
TAG: ${{ github.ref_name }}
|
|
||||||
run: |
|
run: |
|
||||||
# Get release by tag
|
TAG="${GITEA_REF_NAME}"
|
||||||
RELEASE=$(curl -s "${GITEA_URL}/api/v1/repos/${REPO}/releases/tags/${TAG}" \
|
TOKEN="${GITEA_TOKEN}"
|
||||||
-H "Authorization: token ${GITEA_TOKEN}")
|
URL="${GITEA_SERVER_URL}"
|
||||||
|
REPO="${GITEA_REPOSITORY}"
|
||||||
|
|
||||||
|
# Get or create release
|
||||||
|
RELEASE=$(curl -s "${URL}/api/v1/repos/${REPO}/releases/tags/${TAG}" \
|
||||||
|
-H "Authorization: token ${TOKEN}")
|
||||||
|
|
||||||
RELEASE_ID=$(echo $RELEASE | jq -r '.id')
|
RELEASE_ID=$(echo $RELEASE | jq -r '.id')
|
||||||
|
|
||||||
if [ "$RELEASE_ID" == "null" ]; then
|
if [ "$RELEASE_ID" == "null" ] || [ -z "$RELEASE_ID" ]; then
|
||||||
# Create release
|
RELEASE_ID=$(curl -s -X POST "${URL}/api/v1/repos/${REPO}/releases" \
|
||||||
RELEASE_ID=$(curl -s -X POST "${GITEA_URL}/api/v1/repos/${REPO}/releases" \
|
-H "Authorization: token ${TOKEN}" \
|
||||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "{\"tag_name\": \"${TAG}\", \"name\": \"ReadFlow ${TAG}\", \"body\": \"Release ${TAG}\", \"draft\": false}" \
|
-d "{\"tag_name\": \"${TAG}\", \"name\": \"ReadFlow ${TAG}\", \"body\": \"Release ${TAG}\", \"draft\": false}" \
|
||||||
| jq -r '.id')
|
| jq -r '.id')
|
||||||
@@ -72,9 +74,14 @@ jobs:
|
|||||||
echo "Release ID: ${RELEASE_ID}"
|
echo "Release ID: ${RELEASE_ID}"
|
||||||
|
|
||||||
# Upload asset
|
# Upload asset
|
||||||
curl -s -X POST "${GITEA_URL}/api/v1/repos/${REPO}/releases/${RELEASE_ID}/assets?name=readflow-windows-x86_64.zip" \
|
curl -s -X POST "${URL}/api/v1/repos/${REPO}/releases/${RELEASE_ID}/assets?name=readflow-windows-x86_64.zip" \
|
||||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
-H "Authorization: token ${TOKEN}" \
|
||||||
-H "Content-Type: application/zip" \
|
-H "Content-Type: application/zip" \
|
||||||
--data-binary @dist/readflow-windows-x86_64.zip
|
--data-binary @dist/readflow-windows-x86_64.zip
|
||||||
|
|
||||||
echo "Upload completed!"
|
echo "✅ Upload completed!"
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
|
GITEA_SERVER_URL: http://192.168.120.110:4000
|
||||||
|
GITEA_REPOSITORY: damai/readflow
|
||||||
|
GITEA_REF_NAME: ${{ github.ref_name }}
|
||||||
|
|||||||
Reference in New Issue
Block a user