更新 .gitea/workflows/demo.yaml

发布生产
This commit is contained in:
xiehaijun 2025-07-28 15:49:52 +00:00
parent bbb6ec199a
commit a184a3d636
1 changed files with 44 additions and 0 deletions

View File

@ -220,6 +220,11 @@ jobs:
download: download:
needs: upload needs: upload
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: # 设置job下全steps的环境变量
GITEA_API_URL: https://gitea.example.com/api/v1
GITEA_USER: youruser
GITEA_REPO: yourrepo
ARTIFACT_FILE: dist/release.zip
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
@ -240,6 +245,7 @@ jobs:
git config user.email "actions@github.com" git config user.email "actions@github.com"
git tag -a ${{ steps.vars.outputs.tag }} -m "Automated release" git tag -a ${{ steps.vars.outputs.tag }} -m "Automated release"
# git push origin ${{ steps.vars.outputs.tag }} # 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://x-access-token:${PAT_PUSH}@github.com/${REPO}.git "$TAG"
git push https://${GITEA_USER}:${GITEA_PAT}@${GITEA_HOST}/${GITEA_REPO}.git "$TAG" git push https://${GITEA_USER}:${GITEA_PAT}@${GITEA_HOST}/${GITEA_REPO}.git "$TAG"
- name: 获取跨job上游job的输出变量值 - name: 获取跨job上游job的输出变量值
@ -316,6 +322,44 @@ jobs:
files: |- files: |-
./release/** ./release/**
- run: ls -R ./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##*/}"
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
- name: Create Gitea Release
id: create_release
run: |
response=$(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 release was created automatically by GitHub Actions.",
"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: setup go #- name: setup go
# uses: actions/setup-go@v5 # uses: actions/setup-go@v5
# with: # with: