Skip to content

Commit

Permalink
sync release to gitee
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengyangliu committed Jul 12, 2024
1 parent cf08093 commit 7cfe36e
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/sync_release_to_gitee.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Sync Release to Gitee

on:
release:
types: [published]

jobs:
sync_release:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Get release info
id: get_release_info
uses: actions/github-script@v6
with:
script: |
const release = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: context.payload.release.tag_name
});
return release.data;
- name: Download release assets
id: download_assets
uses: actions/github-script@v6
with:
script: |
const { exec } = require("@actions/exec");
const assets = ${steps.get_release_info.outputs.result.assets};
const downloadUrls = assets.map(asset => asset.browser_download_url);
for (const url of downloadUrls) {
await exec(`curl -L -o ${url.split('/').pop()} ${url}`);
}
- name: Create release on Gitee
env:
GITEE_TOKEN: ${{ secrets.GITEE_TOKEN }}
run: |
RELEASE_TAG=$(git describe --tags --abbrev=0)
RELEASE_NAME=$(git tag -l --format='%(tag)' --contains ${RELEASE_TAG})
RELEASE_BODY=$(git for-each-ref refs/tags/${RELEASE_TAG} --format='%(contents)')
# Create release on Gitee
RESPONSE=$(curl -X POST -H "Content-Type: application/json" \
-H "Authorization: token ${GITEE_TOKEN}" \
-d '{
"access_token": "'${GITEE_TOKEN}'",
"tag_name": "'${RELEASE_TAG}'",
"target_commitish": "main",
"name": "'${RELEASE_NAME}'",
"body": "'${RELEASE_BODY}'",
"draft": false,
"prerelease": false
}' \
https://gitee.com/api/v5/repos/openblockcc/external-resources-v3/releases)
RELEASE_ID=$(echo $RESPONSE | jq -r '.id')
# Upload assets to Gitee
for FILE in $(ls); do
if [ -f "$FILE" ]; then
curl -X POST -H "Authorization: token ${GITEE_TOKEN}" \
-F "access_token=${GITEE_TOKEN}" \
-F "file=@${FILE}" \
https://gitee.com/api/v5/repos/openblockcc/external-resources-v3/releases/${RELEASE_ID}/assets?name=${FILE}
fi
done

0 comments on commit 7cfe36e

Please sign in to comment.