From 7cfe36e65595907eecb4d4839df1fdbb0139230d Mon Sep 17 00:00:00 2001 From: ArthurZheng <869705086@qq.com> Date: Fri, 12 Jul 2024 14:00:23 +0800 Subject: [PATCH] sync release to gitee --- .github/workflows/sync_release_to_gitee.yml | 71 +++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 .github/workflows/sync_release_to_gitee.yml diff --git a/.github/workflows/sync_release_to_gitee.yml b/.github/workflows/sync_release_to_gitee.yml new file mode 100644 index 0000000..bb89134 --- /dev/null +++ b/.github/workflows/sync_release_to_gitee.yml @@ -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