Compare commits
42 Commits
release-20
...
main
| Author | SHA1 | Date |
|---|---|---|
|
|
c3ceeefdcf | |
|
|
0f27becead | |
|
|
d7f4045fb7 | |
|
|
488c41e5fa | |
|
|
29ef1d894a | |
|
|
d3ef13266a | |
|
|
212b5c1a80 | |
|
|
b7aa1b5618 | |
|
|
992a6a5ef6 | |
|
|
e294974530 | |
|
|
97ca86b887 | |
|
|
f031f27863 | |
|
|
365a023fe0 | |
|
|
707432fcc3 | |
|
|
19d32355b2 | |
|
|
bbe7cdf4ba | |
|
|
cd43485d7b | |
|
|
369f83d401 | |
|
|
624480984e | |
|
|
3f1f73c8ee | |
|
|
d832728ad2 | |
|
|
5df98fb942 | |
|
|
c4470b41eb | |
|
|
a184a3d636 | |
|
|
bbb6ec199a | |
|
|
ceb5118fab | |
|
|
ca2085f118 | |
|
|
c65233e116 | |
|
|
886e371de6 | |
|
|
3ec5d5995a | |
|
|
f2585c955e | |
|
|
77a709e106 | |
|
|
d19808ea80 | |
|
|
02fc6822d1 | |
|
|
a9bd329ea3 | |
|
|
d368ad695f | |
|
|
1fc9c4c277 | |
|
|
519f71c213 | |
|
|
b0bba22efb | |
|
|
985f7078bb | |
|
|
94fdcbaa53 | |
|
|
52d26dd801 |
|
|
@ -6,6 +6,9 @@ on:
|
|||
types: [closed]
|
||||
push:
|
||||
branches: [ "main","releases/**" ]
|
||||
tags:
|
||||
#- '*' # 任意的tag都会触发
|
||||
- 'v*.*.*'
|
||||
# paths:
|
||||
# - 'sub-project/**'
|
||||
# - '!sub-project/docs/**' # !在正匹配之后匹配负模式(以 为前缀)将排除该路径。
|
||||
|
|
@ -82,7 +85,7 @@ jobs:
|
|||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '22'
|
||||
check-latest: true
|
||||
#check-latest: true
|
||||
# cache: 'npm'
|
||||
# cache-dependency-path: '**/package-lock.json'
|
||||
- name: 安装node依赖
|
||||
|
|
@ -114,6 +117,16 @@ jobs:
|
|||
echo 'docker build -t <dockerhub repository name>.'
|
||||
echo 'docker push <dockerhub repository name>:latest'
|
||||
docker info
|
||||
- name: 通过 SSH 复制文件
|
||||
uses: appleboy/scp-action@v1
|
||||
with:
|
||||
host: ${{ vars.DEPLOY_HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
password: ${{ secrets.PASSWORD }}
|
||||
port: ${{ vars.PORT }}
|
||||
#source: "tests/a.txt,tests/b.txt"
|
||||
source: "pom.xml"
|
||||
target: /tmp/
|
||||
deploy:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
|
|
@ -162,7 +175,7 @@ jobs:
|
|||
steps:
|
||||
- name: 生成制品
|
||||
# run: ./some-script --version=${{ matrix.version }} > my-binary
|
||||
run: echo "系统=${{ matrix.os }},version=${{ matrix.version }}" > my-binary-${{ matrix.os }}-${{ matrix.version }}
|
||||
run: echo "系统=${{ matrix.os }},version=${{ matrix.version }}" > my-binary-${{ matrix.os }}-${{ matrix.version }}
|
||||
- name: 安装上传制品插件
|
||||
uses: actions/upload-artifact@v3 #download-artifact@v4,v4版本不支持github企业服务[GitHub Enterprise Server(GHES)]v3支持
|
||||
id: artifact-upload-step-id
|
||||
|
|
@ -182,16 +195,18 @@ jobs:
|
|||
echo 'Artifact URL is ${{ steps.artifact-upload-step-id.artifact-url }}'
|
||||
echo 'Artifact SHA 256 is ${{ steps.artifact-upload-step-id.artifact-digest }}'
|
||||
upload:
|
||||
needs: check
|
||||
if: ${{ success() }}
|
||||
outputs:
|
||||
tag-name: ${{ steps.set-tag.outputs.tag }} # 设置一个输出标签。对外包露tag-name,值来自于当前job下steps下id叫set-tag的环境变量tag
|
||||
tag-name: ${{ steps.set-tag.outputs.tag }} #设置一个输出标签,对外包露tag-name,值来自于当前job下steps下id叫set-tag的环境变量tag
|
||||
strategy:
|
||||
matrix:
|
||||
runs-on: [ubuntu-latest] # [ubuntu-latest, macos-latest, windows-latest]
|
||||
runs-on: ${{ matrix.runs-on }}
|
||||
steps:
|
||||
- id: set-tag
|
||||
# run: echo "tag=release-$(TZ=+8 date '+%Y-%m-%d_%H_%M_%S')" >> $GITHUB_OUTPUT # 把变量输出到github的输出环境,上面的outputs就能获取到
|
||||
run: echo "tag=release-$(TZ='Asia/Shanghai' date '+%Y-%m-%d_%H_%M_%S')" >> $GITHUB_OUTPUT
|
||||
# run: echo "tag=release-$(TZ=+8 date '+%Y-%m-%d_%H_%M_%S')" >> $GITHUB_OUTPUT #把变量输出到github的输出环境,上面的outputs就能获取到
|
||||
run: echo "tag=v$(TZ='Asia/Shanghai' date '+%Y.%m.%d%H%M%S')" >> $GITHUB_OUTPUT
|
||||
- name: Create a File
|
||||
run: |
|
||||
echo "$(TZ='Asia/Shanghai' date '+%Y%m%d%H%M%S') hello from ${{ matrix.runs-on }}" > file-${{ matrix.runs-on }}.txt
|
||||
|
|
@ -206,18 +221,34 @@ jobs:
|
|||
download:
|
||||
needs: upload
|
||||
runs-on: ubuntu-latest
|
||||
env: # 设置job下全steps的环境变量
|
||||
GITEA_API_URL: https://git.ewancle.com/api/v1
|
||||
GITEA_USER1: xiehaijun
|
||||
GITEA_REPO1: study-plan
|
||||
ARTIFACT_FILE: dist/release.zip
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Set release tag as date
|
||||
id: vars
|
||||
run: echo "tag=release-$(TZ='Asia/Shanghai' date +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT # 包含$GITHUB_ENV 的作用域,全steps也可访问
|
||||
- name: 自定提交tag
|
||||
env:
|
||||
GITEA_USER: xiehaijun
|
||||
TAG: ${{ steps.vars.outputs.tag }}
|
||||
GITEA_PAT: ${{ secrets.MY_APP_TOKEN }}
|
||||
GITEA_REPO: xiehaijun/study-plan
|
||||
GITEA_HOST: git.ewancle.com
|
||||
run: |
|
||||
git config user.name "github-actions"
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "actions@github.com"
|
||||
git tag -a ${{ steps.vars.outputs.tag }} -m "Automated release"
|
||||
git push origin ${{ steps.vars.outputs.tag }}
|
||||
#git tag -a ${{ steps.vars.outputs.tag }} -m "Automated release"
|
||||
# git push origin ${{ steps.vars.outputs.tag }}
|
||||
# 前往你的 GitHub: https://github.com/settings/tokens;生成一个classic token-建议 或 fine-grained token;选择至少:repo 权限
|
||||
# git push https://x-access-token:${PAT_PUSH}@github.com/${REPO}.git "$TAG"
|
||||
#git push https://${GITEA_USER}:${GITEA_PAT}@${GITEA_HOST}/${GITEA_REPO}.git "$TAG"
|
||||
- name: 获取跨job上游job的输出变量值
|
||||
run: echo "The tag from previous job is ${{ needs.upload.outputs.tag-name }}"
|
||||
- name: Download All Artifacts
|
||||
|
|
@ -264,12 +295,13 @@ jobs:
|
|||
echo "获取gitea: ${{ gitea.repository }}"
|
||||
- name: release
|
||||
# uses: softprops/action-gh-release@v2这是github的.gitea官方的actions才支持.gitea官方的actions:https://gitea.com/actions
|
||||
uses: akkuman/gitea-release-action@v1
|
||||
uses: https://gitea.com/actions/gitea-release-action@v1.3.4 # akkuman/gitea-release-action@v1
|
||||
env:
|
||||
#GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # github版本专用
|
||||
NODE_OPTIONS: '--experimental-fetch' # if nodejs < 18[gitea版本]
|
||||
NODE_TLS_REJECT_UNAUTHORIZED: false # 忽略 ssl 验证错误[gitea版本]
|
||||
if: github.ref_type == 'tag'
|
||||
#if: startsWith(github.ref, 'refs/tags/') # 仅在tag时上传
|
||||
with:
|
||||
# body_path: ${{ github.workspace }}-CHANGELOG.txt #加载文本的路径,用于传达此版本中的显著变化
|
||||
# repository: my_gh_org/my_gh_repo
|
||||
|
|
@ -279,7 +311,7 @@ jobs:
|
|||
#tag_name: ${{ needs.upload.outputs.tag-name }}
|
||||
#tag_name: ${{ steps.vars.outputs.tag }}
|
||||
fail_on_unmatched_files: true
|
||||
name: Release ${{ steps.vars.outputs.tag }}
|
||||
name: Release ${{ github.ref_name }}
|
||||
make_latest: true # 指定是否将此版本设置为仓库的最新版本。草稿版和预发布版不能设置为最新版本。可以是true、false或legacy。
|
||||
draft: false # 指示此版本是否为草稿
|
||||
prerelease: false # 是否为预发布版本
|
||||
|
|
@ -290,5 +322,131 @@ jobs:
|
|||
# release/*.txt
|
||||
files: |-
|
||||
./release/**
|
||||
- run: ls -R ./release/
|
||||
- name: Build or prepare artifact (example only)
|
||||
run: |
|
||||
mkdir -p dist
|
||||
echo "Hello Gitea Release" > dist/README.txt
|
||||
zip -j dist/release.zip dist/README.txt
|
||||
- name: Extract tag name
|
||||
id: vars
|
||||
run: |
|
||||
# TAG_NAME="${GITHUB_REF##*/}"
|
||||
TAG_NAME="${{ needs.upload.outputs.tag-name }}"
|
||||
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
|
||||
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
|
||||
echo "标签名称:$TAG_NAME"
|
||||
#- name: "✏️ Generate release changelog"
|
||||
# uses: janheinrichmerker/action-github-changelog-generator@v2.3
|
||||
# with:
|
||||
# # token: ${{ secrets.GITHUB_TOKEN }}
|
||||
# token: 'ec5e01f597b42492c1c7a73f9997435fc83c1093'
|
||||
# output: CHANGELOG.md
|
||||
#- name: Extract current version changelog
|
||||
# id: extract
|
||||
# run: |
|
||||
# TAG_NAME1="${GITHUB_REF##*/}" # v1.2.3
|
||||
# cat CHANGELOG.md
|
||||
- name: Setup git tags
|
||||
run: git fetch --tags
|
||||
- name: 安装nodejs
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '22'
|
||||
- name: Install conventional-changelog-cli
|
||||
run: npm install -g conventional-changelog-cli
|
||||
- name: Generate changelog from commits
|
||||
id: changelog
|
||||
run: |
|
||||
#PREV_TAG=$(git tag --sort=-creatordate | grep '^v' | sed -n 2p)
|
||||
#CURR_TAG=$(git tag --sort=-creatordate | grep '^v' | sed -n 1p)
|
||||
#echo "## [$CURR_TAG] vs [$PREV_TAG] ($(date +%Y-%m-%d))" > CHANGELOG.md
|
||||
#conventional-changelog -p angular -r 1 >> CHANGELOG.md
|
||||
#cat CHANGELOG.md
|
||||
|
||||
CHANGELOG=$(conventional-changelog -p angular -r 2)
|
||||
echo "CHANGELOG<<EOF" >> "$GITHUB_OUTPUT"
|
||||
echo "$CHANGELOG 测试" >> "$GITHUB_OUTPUT"
|
||||
echo "EOF" >> "$GITHUB_OUTPUT"
|
||||
- name: Generate or update CHANGELOG.md
|
||||
run: |
|
||||
if [ ! -f CHANGELOG.md ]; then
|
||||
echo "# Changelog" > CHANGELOG.md
|
||||
fi
|
||||
#只生成最近一次提交HEAD对应的变更
|
||||
#conventional-changelog -p angular -r 0 -n node_modules/conventional-changelog-angular -i CHANGELOG.md -s
|
||||
conventional-changelog -p angular -r 0 -i CHANGELOG.md -s
|
||||
# https://juejin.cn/post/7053730154710827045
|
||||
conventional-changelog -p angular -i CHANGELOG.md -s -r 0
|
||||
# 提取本次 push 的 commit 列表
|
||||
#git log "${{ github.event.before }}..${{ github.sha }}" --pretty=format:"%s|%h"
|
||||
git log "${{ github.event.before }}..${{ github.sha }}" --pretty=format:"==SPLIT==%n%s%n%b%n==END=="
|
||||
- name: Commit & Push changelog (if changed)
|
||||
run: |
|
||||
git add CHANGELOG.md
|
||||
cat CHANGELOG.md
|
||||
if git diff --cached --quiet; then
|
||||
echo "No changelog changes to commit."
|
||||
else
|
||||
git commit -m "docs(changelog): update changelog after commit"
|
||||
git push
|
||||
fi
|
||||
|
||||
- name: Create Gitea Release
|
||||
id: create_release
|
||||
run: | #API接口:https://git.ewancle.com/api/swagger和https://docs.gitea.com/zh-cn/development/api-usage,EOF必须顶格写
|
||||
response=$(curl -s -X POST "${GITEA_API_URL}/repos/${GITEA_USER1}/${GITEA_REPO1}/releases" \
|
||||
-H "Authorization: token a94110b4fa993133ceb0e04fdabfd70626e02405" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d @- <<EOF
|
||||
{
|
||||
"tag_name": "${{ env.TAG_NAME }}",
|
||||
"name": "Release ${{ env.TAG_NAME }}",
|
||||
"body": "${{ steps.changelog.outputs.CHANGELOG }}",
|
||||
"draft": false,
|
||||
"prerelease": false
|
||||
}
|
||||
EOF
|
||||
)
|
||||
|
||||
echo "$response" | tee gitea-release-response.json
|
||||
RELEASE_ID=$(echo "$response" | jq -r '.id')
|
||||
|
||||
if [ "$RELEASE_ID" = "null" ]; then
|
||||
echo "❌ Failed to create release"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "RELEASE_ID=$RELEASE_ID" >> $GITHUB_ENV
|
||||
echo "release_id=$RELEASE_ID" >> $GITHUB_OUTPUT
|
||||
- name: Upload artifact to Gitea Release
|
||||
run: |
|
||||
FILE_NAME=$(basename $ARTIFACT_FILE)
|
||||
echo $FILE_NAME
|
||||
curl -X POST "${GITEA_API_URL}/repos/${GITEA_USER1}/${GITEA_REPO1}/releases/${{ env.RELEASE_ID }}/assets" \
|
||||
-H "Authorization: token a94110b4fa993133ceb0e04fdabfd70626e02405" \
|
||||
-H "accept: application/json" \
|
||||
-H "Content-Type: multipart/form-data" \
|
||||
-F "attachment=@$ARTIFACT_FILE"
|
||||
|
||||
- name: ✅ Done
|
||||
run: echo "🎉 Gitea release $TAG_NAME created and file uploaded!"
|
||||
#- name: setup go
|
||||
# uses: actions/setup-go@v5
|
||||
# with:
|
||||
#go-version: '>=1.20.1'
|
||||
# go-version: '^1.13.1'
|
||||
#- run: go version
|
||||
#- name: release-build
|
||||
# run: go build -ldflags="-s -w -X 'main.Version=${{ github.ref_name }}'" -o bin/reverse-${{ github.ref_name }}-linux-amd64
|
||||
#- name: release-build-windows
|
||||
# run: GOOS=windows GOARCH=amd64 go build -ldflags="-s -w -X 'main.Version=${{ github.ref_name }}'" -o bin/reverse-${{ github.ref_name }}-windows-amd64.exe
|
||||
#- name: release-build-darwin
|
||||
# run: GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w -X 'main.Version=${{ github.ref_name }}'" -o bin/reverse-${{ github.ref_name }}-darwin-amd64
|
||||
#- name: Use Go Action
|
||||
# id: use-go-action-test
|
||||
# uses: https://gitea.com/actions/release-action@main
|
||||
# with:
|
||||
# files: |-
|
||||
# release/**
|
||||
# #api_key: '${{secrets.RELEASE_TOKEN}}'
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
# (2025-07-30)
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,395 @@
|
|||
接口:https://git.ewancle.com/api/swagger 和使用教程:https://docs.gitea.com/zh-cn/development/api-usage
|
||||
# 全部作用列表https://docs.gitea.com/zh-cn/development/oauth2-provider
|
||||
```xml
|
||||
activitypub activitypub API routes: ActivityPub related operations.
|
||||
read:activitypub Grants read access for ActivityPub operations.
|
||||
write:activitypub Grants read/write/delete access for ActivityPub operations.
|
||||
admin /admin/* API routes: Site-wide administrative operations (hidden for non-admin accounts).
|
||||
read:admin Grants read access for admin operations, such as getting cron jobs or registered user emails.
|
||||
write:admin Grants read/write/delete access for admin operations, such as running cron jobs or updating user accounts.
|
||||
issue issues/*, labels/*, milestones/* API routes: Issue-related operations.
|
||||
read:issue Grants read access for issues operations, such as getting issue comments, issue attachments, and milestones.
|
||||
write:issue Grants read/write/delete access for issues operations, such as posting or editing an issue comment or attachment, and updating milestones.
|
||||
misc Reserved for future usage.
|
||||
read:misc Reserved for future usage.
|
||||
write:misc Reserved for future usage.
|
||||
notification notification/* API routes: user notification operations.
|
||||
read:notification Grants read access to user notifications, such as which notifications users are subscribed to and read new notifications.
|
||||
write:notification Grants read/write/delete access to user notifications, such as marking notifications as read.
|
||||
organization orgs/* and teams/* API routes: Organization and team management operations.
|
||||
read:organization Grants read access to org and team status, such as listing all orgs a user has visibility to, teams, and team members.
|
||||
write:organization Grants read/write/delete access to org and team status, such as creating and updating teams and updating org settings.
|
||||
package /packages/* API routes: Packages operations
|
||||
read:package Grants read access to package operations, such as reading and downloading available packages.
|
||||
write:package Grants read/write/delete access to package operations. Currently the same as read:package.
|
||||
repository /repos/* API routes except /repos/issues/*: Repository file, pull-request, and release operations.
|
||||
read:repository Grants read access to repository operations, such as getting repository files, releases, collaborators.
|
||||
write:repository Grants read/write/delete access to repository operations, such as getting updating repository files, creating pull requests, updating collaborators.
|
||||
user /user/* and /users/* API routes: User-related operations.
|
||||
read:user Grants read access to user operations, such as getting user repo subscriptions and user settings.
|
||||
write:user Grants read/write/delete access to user operations, such as updating user repo subscriptions, followed users, and user settings.
|
||||
```
|
||||
curl -X POST "https://git.ewancle.com/api/v1/users/xiehaijun/tokens" \
|
||||
-H "Authorization: token f5856ff0aecd675b72c1910bd4a19679927a6ba0" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"name": "full-access-token",
|
||||
"scopes": [
|
||||
"repo",
|
||||
"repo:status",
|
||||
"admin:repo_hook",
|
||||
"admin:org",
|
||||
"write:issue",
|
||||
"write:repository",
|
||||
"read:repository"
|
||||
]
|
||||
}'
|
||||
|
||||
# 管理员账号进行作用域token创建
|
||||
curl -X 'POST' \
|
||||
'https://git.ewancle.com/api/v1/users/xiehaijun/tokens' \
|
||||
-u 'xiehaijun:Xiehaijun945' \
|
||||
-H 'accept: application/json' \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{
|
||||
"name": "full-access-token",
|
||||
"scopes": [
|
||||
"write:repository",
|
||||
"read:repository",
|
||||
"read:user",
|
||||
"write:user",
|
||||
"read:organization",
|
||||
"write:organization"
|
||||
]
|
||||
}'
|
||||
|
||||
# 全部的权限token :"sha1":"ec5e01f597b42492c1c7a73f9997435fc83c1093"
|
||||
curl -X 'POST' \
|
||||
'https://git.ewancle.com/api/v1/users/xiehaijun/tokens' \
|
||||
-u 'xiehaijun:Xiehaijun945' \
|
||||
-H 'accept: application/json' \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{
|
||||
"name": "full-super-token",
|
||||
"scopes": [
|
||||
"read:activitypub",
|
||||
"write:activitypub",
|
||||
"read:admin",
|
||||
"write:admin",
|
||||
"read:issue",
|
||||
"write:issue",
|
||||
"read:misc",
|
||||
"write:misc",
|
||||
"read:admin",
|
||||
"write:admin",
|
||||
"read:notification",
|
||||
"write:notification",
|
||||
"read:package",
|
||||
"write:package",
|
||||
"write:repository",
|
||||
"read:repository",
|
||||
"read:user",
|
||||
"write:user",
|
||||
"read:organization",
|
||||
"write:organization"
|
||||
]
|
||||
}'
|
||||
|
||||
# 获取token,需要read:admin,write:admin
|
||||
curl -X 'GET' \
|
||||
'https://git.ewancle.com/api/v1/users/xiehaijun/tokens' \
|
||||
-H "Authorization: token a94110b4fa993133ceb0e04fdabfd70626e02405" \
|
||||
-H 'accept: application/json'
|
||||
|
||||
|
||||
|
||||
|
||||
EOF 前有空格或 Tab → 会导致闭合失败(命令行就和run: |下面的行平齐)
|
||||
你写的是 <<EOF,但忘了在最后一行独占写 EOF
|
||||
- name: Create Gitea Release
|
||||
run: |
|
||||
curl -s -X POST "${GITEA_API_URL}/repos/${GITEA_USER}/${GITEA_REPO}/releases" \
|
||||
-H "Authorization: token ${{ secrets.GITEA_PAT }}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d @- <<EOF
|
||||
{
|
||||
"tag_name": "${{ env.TAG_NAME }}",
|
||||
"name": "Release ${{ env.TAG_NAME }}",
|
||||
"body": "This is an automated release",
|
||||
"draft": false,
|
||||
"prerelease": false
|
||||
}
|
||||
EOF
|
||||
|
||||
|
||||
将 JSON 拆成变量拼接,避免复杂嵌套:
|
||||
- name: Create Gitea Release
|
||||
run: |
|
||||
JSON=$(jq -n --arg tag "$TAG_NAME" --arg name "Release $TAG_NAME" --arg body "Auto release" '{
|
||||
tag_name: $tag,
|
||||
name: $name,
|
||||
body: $body,
|
||||
draft: false,
|
||||
prerelease: false
|
||||
}')
|
||||
|
||||
echo "$JSON"
|
||||
|
||||
curl -s -X POST "${GITEA_API_URL}/repos/${GITEA_USER}/${GITEA_REPO}/releases" \
|
||||
-H "Authorization: token ${{ secrets.GITEA_PAT }}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$JSON"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
非常棒的问题!为了确保 **Gitea Release 上传附件正确识别 MIME 类型(`Content-Type`)**,你在使用 `curl` 上传文件时,应当为不同文件类型设置**合适的 Content-Type**。
|
||||
|
||||
---
|
||||
|
||||
## ✅ 常见类型对应的 `Content-Type` 设置
|
||||
|
||||
| 文件类型 | 示例文件名 | 推荐 Content-Type |
|
||||
| ------------------ | -------------------- | -------------------------------------------------------------------------------- |
|
||||
| `.txt` | `README.txt` | `text/plain` |
|
||||
| `.zip` | `release.zip` | `application/zip` |
|
||||
| `.tar.gz` / `.tgz` | `release.tar.gz` | `application/gzip` |
|
||||
| `.exe` | `app.exe` | `application/vnd.microsoft.portable-executable` 或 `application/octet-stream`(通用) |
|
||||
| `.md5` / `.sha256` | `release.zip.sha256` | `text/plain` 或 `application/octet-stream`(兼容性更好) |
|
||||
|
||||
---
|
||||
|
||||
### 💡 推荐策略
|
||||
|
||||
> ❗ **通用、安全的 fallback 类型:** `application/octet-stream` 可用于所有二进制文件上传,兼容性最强。
|
||||
|
||||
---
|
||||
|
||||
## 🧪 示例上传命令
|
||||
|
||||
```bash
|
||||
# 上传 zip 文件
|
||||
curl -X POST "$GITEA_API_URL/repos/$OWNER/$REPO/releases/$RELEASE_ID/assets?name=release.zip" \
|
||||
-H "Authorization: token $GITEA_PAT" \
|
||||
-H "Content-Type: application/zip" \
|
||||
--data-binary @"dist/release.zip"
|
||||
|
||||
# 上传 sha256 文件
|
||||
curl -X POST "$GITEA_API_URL/repos/$OWNER/$REPO/releases/$RELEASE_ID/assets?name=release.zip.sha256" \
|
||||
-H "Authorization: token $GITEA_PAT" \
|
||||
-H "Content-Type: text/plain" \
|
||||
--data-binary @"dist/release.zip.sha256"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ✅ 生成验证文件示例(Shell)
|
||||
|
||||
```bash
|
||||
# 生成 sha256 验证文件
|
||||
sha256sum dist/release.zip > dist/release.zip.sha256
|
||||
|
||||
# 可选:生成 md5 验证文件
|
||||
md5sum dist/release.zip > dist/release.zip.md5
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔄 自动 Content-Type 映射 Bash 函数(可嵌入 GitHub Actions)
|
||||
|
||||
```bash
|
||||
detect_content_type() {
|
||||
case "$1" in
|
||||
*.zip) echo "application/zip" ;;
|
||||
*.tar.gz|*.tgz) echo "application/gzip" ;;
|
||||
*.exe) echo "application/octet-stream" ;;
|
||||
*.txt) echo "text/plain" ;;
|
||||
*.md5|*.sha256) echo "text/plain" ;;
|
||||
*) echo "application/octet-stream" ;; # fallback
|
||||
esac
|
||||
}
|
||||
```
|
||||
|
||||
> 然后你就可以这样调用:
|
||||
|
||||
```bash
|
||||
CONTENT_TYPE=$(detect_content_type "$FILENAME")
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ✅ 总结
|
||||
|
||||
| 文件扩展名 | 推荐 Content-Type |
|
||||
| --------- | ----------------------------- |
|
||||
| `.zip` | `application/zip` |
|
||||
| `.tar.gz` | `application/gzip` |
|
||||
| `.exe` | `application/octet-stream` |
|
||||
| `.txt` | `text/plain` |
|
||||
| `.sha256` | `text/plain` 或 `octet-stream` |
|
||||
| 其他未知类型 | `application/octet-stream` |
|
||||
|
||||
---
|
||||
|
||||
如你希望我将这些自动识别上传逻辑封装为 GitHub Actions 步骤或脚本,并上传多个文件到 Gitea,我可以帮你生成一套模板。是否继续?
|
||||
|
||||
|
||||
|
||||
|
||||
你的问题分成两大部分,我们逐一系统回答:
|
||||
|
||||
---
|
||||
|
||||
# ✅ 一、`.xz`、`.pdf`、`.jpg`、`.mp4` 等常见文件的 Content-Type 设置
|
||||
|
||||
| 文件扩展名 | 示例文件 | 推荐 `Content-Type` |
|
||||
| ---------------- | ------------- | ------------------ |
|
||||
| `.xz` | `data.tar.xz` | `application/x-xz` |
|
||||
| `.pdf` | `manual.pdf` | `application/pdf` |
|
||||
| `.jpg` / `.jpeg` | `cover.jpg` | `image/jpeg` |
|
||||
| `.png` | `image.png` | `image/png` |
|
||||
| `.mp4` | `video.mp4` | `video/mp4` |
|
||||
| `.json` | `data.json` | `application/json` |
|
||||
| `.csv` | `data.csv` | `text/csv` |
|
||||
| `.xml` | `data.xml` | `application/xml` |
|
||||
|
||||
✅ 如果不确定,可使用通用 `application/octet-stream`,**但推荐精确设置 MIME 类型**,便于 Release 页面或浏览器识别。
|
||||
|
||||
---
|
||||
|
||||
# ✅ 二、GitHub 与 Gitee 发布 Release 并上传文件(API 对比)
|
||||
|
||||
---
|
||||
|
||||
## ✅ GitHub:创建 Release 并上传 Asset 附件
|
||||
|
||||
### 🔗 GitHub API 文档:
|
||||
|
||||
* [Create Release](https://docs.github.com/en/rest/releases/releases#create-a-release)
|
||||
* [Upload Release Asset](https://docs.github.com/en/rest/releases/assets?apiVersion=2022-11-28#upload-a-release-asset)
|
||||
|
||||
### 📦 步骤 1:创建 Release
|
||||
|
||||
```bash
|
||||
response=$(curl -s -X POST "https://api.github.com/repos/OWNER/REPO/releases" \
|
||||
-H "Authorization: token $GITHUB_PAT" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d @- <<EOF
|
||||
{
|
||||
"tag_name": "v1.2.3",
|
||||
"name": "Release v1.2.3",
|
||||
"body": "This is an automated release",
|
||||
"draft": false,
|
||||
"prerelease": false
|
||||
}
|
||||
EOF
|
||||
)
|
||||
|
||||
upload_url=$(echo "$response" | jq -r '.upload_url' | sed 's/{?name,label}//')
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 📦 步骤 2:上传附件
|
||||
|
||||
```bash
|
||||
curl -X POST "$upload_url?name=manual.pdf" \
|
||||
-H "Authorization: token $GITHUB_PAT" \
|
||||
-H "Content-Type: application/pdf" \
|
||||
--data-binary @"./build/manual.pdf"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ✅ Gitee:创建 Release 并上传文件(非标准,需曲线实现)
|
||||
|
||||
### 🔗 官方文档(不完善):
|
||||
|
||||
* [Gitee Releases API](https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoReleases)
|
||||
|
||||
Gitee 的限制:
|
||||
|
||||
* ✅ 可以创建 Release(相当于发布 Tag)
|
||||
* ❌ 不支持上传附件到 Release(没有像 GitHub 的 assets 接口)
|
||||
* ✅ 可上传文件到 repo 或 wiki,或额外建专用仓库存文件
|
||||
|
||||
---
|
||||
|
||||
### 🟡 Gitee 创建 Release 示例(只含 tag 和说明):
|
||||
|
||||
```bash
|
||||
curl -X POST "https://gitee.com/api/v5/repos/OWNER/REPO/releases" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d @- <<EOF
|
||||
{
|
||||
"access_token": "$GITEE_TOKEN",
|
||||
"tag_name": "v1.2.3",
|
||||
"name": "Release v1.2.3",
|
||||
"body": "Changelog here"
|
||||
}
|
||||
EOF
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 🔴 Gitee 上传文件:无直接 API 可传文件到 Release 页面
|
||||
|
||||
**替代方案:**
|
||||
|
||||
1. 把文件上传到仓库某个目录:
|
||||
|
||||
```bash
|
||||
curl -X POST https://gitee.com/api/v5/repos/OWNER/REPO/contents/path/to/file \
|
||||
-F access_token=$GITEE_TOKEN \
|
||||
-F content=$(base64 ./manual.pdf) \
|
||||
-F message="upload file"
|
||||
```
|
||||
|
||||
⚠️ 支持 txt, md 等文本文件(base64 转码后大小限制),不推荐上传大型二进制文件。
|
||||
|
||||
2. 使用专门的文件下载仓库或私有网盘存放链接,在 Release 中贴出 URL。
|
||||
|
||||
---
|
||||
|
||||
# ✅ 三、总结对比:GitHub vs Gitee 发布 Release 附件能力
|
||||
|
||||
| 操作 | GitHub | Gitee |
|
||||
| ---------------- | ----------------------- | --------------- |
|
||||
| 创建 Release | ✅ | ✅ |
|
||||
| 上传附件到 Release 页面 | ✅ `assets` 接口 | ❌ 不支持直接上传 |
|
||||
| 支持多附件 | ✅ | ❌(建议提供外链) |
|
||||
| 自动化支持 | ✅ GitHub Actions / curl | ❌ 需要 workaround |
|
||||
|
||||
---
|
||||
|
||||
## ✅ 补充建议:构建通用上传脚本
|
||||
|
||||
你可以用如下结构自动上传任意构建产物:
|
||||
|
||||
```bash
|
||||
file="release.tar.xz"
|
||||
mime_type=$(file --mime-type -b "$file")
|
||||
|
||||
curl -X POST "$upload_url?name=$(basename $file)" \
|
||||
-H "Authorization: token $TOKEN" \
|
||||
-H "Content-Type: $mime_type" \
|
||||
--data-binary @"$file"
|
||||
```
|
||||
|
||||
> `file --mime-type` 自动识别 MIME 类型,适合你上传 `.xz`, `.pdf`, `.mp4` 等任意格式。
|
||||
|
||||
---
|
||||
|
||||
## ✅ 可选扩展:GitHub Actions 中自动上传多个文件到 Release
|
||||
|
||||
如果你希望我写一份完整的 `matrix` + MIME 自动识别 + GitHub/Gitee 多仓同时发布的 Actions,我可以马上生成。
|
||||
|
||||
是否继续?你也可以告诉我具体构建产物目录和需要上传哪些类型,我直接帮你生成 YAML 或 Shell。
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
重新刷新交换空间使用:https://www.cnblogs.com/xiangbing123/p/17376517.html
|
||||
[root@localhost ~]# vim /etc/sysctl.conf (查看当前配置cat /proc/sys/vm/swappiness)
|
||||
vm.swappiness=5 #文件末尾追加此参数(设置成 0 表示尽可能使用内存)
|
||||
[root@localhost ~]# sysctl -p
|
||||
执行刷盘命令: sync
|
||||
释放所有缓存: sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'
|
||||
关闭swap,再开启swap:
|
||||
swapoff -a
|
||||
再开启
|
||||
swapon -a
|
||||
|
||||
Gitea关闭用户注册:
|
||||
找到 app.ini 配置文件,修改 service 条目下 DISABLE_REGISTRATION 为 true,意思为禁用注册,之后只有管理员可以为用户创建帐户。
|
||||
[service]
|
||||
DISABLE_REGISTRATION = true # 禁用注册
|
||||
|
||||
[openid]
|
||||
ENABLE_OPENID_SIGNIN = false # 禁用openid登录
|
||||
ENABLE_OPENID_SIGNUP = false # 禁用openid注册
|
||||
|
||||
Gitea 创建token:https://docs.gitea.com/zh-cn/development/api-usage【 gitea web 界面来创建 apiKey token: Settings | Applications | Generate New Token.】[b2f9dbed8d2a66c46881c9d1fe02b16b38cb418d]
|
||||
Gitea-runner:https://docs.gitea.com/zh-cn/runner/0.2.11/ (获取token在runners页面的【创建runners】)
|
||||
创建默认的配置文件:docker run --entrypoint="" --rm -it docker.io/gitea/act_runner:latest act_runner generate-config > act_runner-config.yaml
|
||||
使用 actions/cache 时没有进行额外的配置:vim act_runner-config.yaml
|
||||
cache:
|
||||
enabled: true
|
||||
dir: "/data/actions_cache"
|
||||
# 使用步骤 1. 获取的 LAN IP(获取 Runner 容器所在主机的 LAN(本地局域网) IP 地址)
|
||||
host: "10.0.0.16"
|
||||
# 使用步骤 2. 获取的端口号(获取一个 Runner 容器所在主机的空闲端口号。)
|
||||
port: 8088
|
||||
# 运行
|
||||
docker run -dit -p 8088:8088 \
|
||||
-e GITEA_INSTANCE_URL=https://git.ewancle.com -e GITEA_RUNNER_REGISTRATION_TOKEN=qWUc64Fqg9gRqLa7pMCilsV11hs7N7CqNUr7xHwg \
|
||||
-e GITEA_RUNNER_NAME=ewancle-gitea_runner -e GITEA_RUNNER_LABELS=oracle_cloud_gitea_runner -e CONFIG_FILE=/config.yaml \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock -v /home/ubuntu/gitea/act_runner-config.yaml:/config.yaml -v /home/ubuntu/gitea/act_runner_data:/data \
|
||||
--name gitea_runner gitea/act_runner:latest
|
||||
|
||||
docker run \
|
||||
-v $(pwd)/act_runner-config.yaml:/config.yaml \
|
||||
-v $(pwd)/data:/data \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
-v /etc/localtime:/etc/localtime:ro \
|
||||
-e TZ=Asia/Shanghai \
|
||||
-e CONFIG_FILE=/config.yaml \
|
||||
-e GITEA_INSTANCE_URL=<instance_url> \
|
||||
-e GITEA_RUNNER_REGISTRATION_TOKEN=<registration_token> \
|
||||
-e GITEA_RUNNER_NAME=<runner_name> \
|
||||
-e GITEA_RUNNER_LABELS=<runner_labels> \
|
||||
--name my_runner \
|
||||
-d gitea/act_runner:nightly
|
||||
创建配置变量后,它们将自动填充到 vars 上下文中。您可以在工作流中使用类似 ${{ vars.VARIABLE_NAME }} 这样的表达式来使用它们。
|
||||
变量名称只能包含字母数字字符 ([a-z], [A-Z], [0-9]) 或下划线 (_)。不允许使用空格。
|
||||
变量名称不能以 GITHUB_ 和 GITEA_ 前缀开头。
|
||||
变量名称不能以数字开头。
|
||||
变量名称不区分大小写。
|
||||
变量名称在创建它们的级别上必须是唯一的。
|
||||
变量名称不能为 CI。
|
||||
|
||||
|
||||
docker-compose.yml方式运行:https://docs.gitea.com/installation/install-with-docker
|
||||
version: "3"
|
||||
|
||||
networks:
|
||||
gitea:
|
||||
external: false
|
||||
|
||||
services:
|
||||
server:
|
||||
image: docker.gitea.com/gitea:1.24.3
|
||||
container_name: gitea
|
||||
environment:
|
||||
- USER_UID=1000
|
||||
- USER_GID=1000
|
||||
restart: always
|
||||
networks:
|
||||
- gitea
|
||||
volumes:
|
||||
- ./gitea:/data
|
||||
- /etc/timezone:/etc/timezone:ro
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
ports:
|
||||
- "3000:3000"
|
||||
- "222:22"
|
||||
runner:
|
||||
image: docker.io/gitea/act_runner:nightly
|
||||
environment:
|
||||
CONFIG_FILE: /config.yaml
|
||||
GITEA_INSTANCE_URL: "${INSTANCE_URL}"
|
||||
GITEA_RUNNER_REGISTRATION_TOKEN: "${REGISTRATION_TOKEN}"
|
||||
GITEA_RUNNER_NAME: "${RUNNER_NAME}"
|
||||
GITEA_RUNNER_LABELS: "${RUNNER_LABELS}"
|
||||
volumes:
|
||||
- ./config.yaml:/config.yaml
|
||||
- ./data:/data
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue