mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-12 15:21:09 +00:00
feat: enhance GitCode release workflow to handle bootstrap and matrix assets
This commit is contained in:
@@ -32,6 +32,8 @@ jobs:
|
|||||||
release_prerelease: ${{ steps.release.outputs.prerelease }}
|
release_prerelease: ${{ steps.release.outputs.prerelease }}
|
||||||
bootstrap_asset: ${{ steps.release.outputs.bootstrap_asset }}
|
bootstrap_asset: ${{ steps.release.outputs.bootstrap_asset }}
|
||||||
release_asset_matrix: ${{ steps.release.outputs.asset_matrix }}
|
release_asset_matrix: ${{ steps.release.outputs.asset_matrix }}
|
||||||
|
has_bootstrap_asset: ${{ steps.release.outputs.has_bootstrap_asset }}
|
||||||
|
has_matrix_assets: ${{ steps.release.outputs.has_matrix_assets }}
|
||||||
steps:
|
steps:
|
||||||
- name: Wait for GitHub release workflows
|
- name: Wait for GitHub release workflows
|
||||||
if: ${{ github.event_name == 'push' }}
|
if: ${{ github.event_name == 'push' }}
|
||||||
@@ -90,6 +92,8 @@ jobs:
|
|||||||
id: release
|
id: release
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
GITCODE_REPOSITORY: ${{ vars.GITCODE_REPOSITORY }}
|
||||||
|
GITCODE_TOKEN: ${{ secrets.GITCODE_TOKEN }}
|
||||||
RELEASE_TAG: ${{ inputs.tag_name || github.ref_name }}
|
RELEASE_TAG: ${{ inputs.tag_name || github.ref_name }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
@@ -124,24 +128,70 @@ jobs:
|
|||||||
|
|
||||||
find release-assets -maxdepth 1 -type f -print | sort
|
find release-assets -maxdepth 1 -type f -print | sort
|
||||||
|
|
||||||
bootstrap_asset="$(
|
local_assets="$(
|
||||||
find release-assets -maxdepth 1 -type f -printf '%s\t%f\n' \
|
find release-assets -maxdepth 1 -type f -printf '%s\t%f\n' \
|
||||||
| sort -n -k1,1 \
|
| sort -n -k1,1 \
|
||||||
| head -n 1 \
|
| cut -f2- \
|
||||||
| cut -f2-
|
| jq -Rsc 'split("\n") | map(select(length > 0))'
|
||||||
)"
|
)"
|
||||||
asset_matrix="$(
|
|
||||||
find release-assets -maxdepth 1 -type f -printf '%f\n' \
|
gitcode_release_json="$(mktemp)"
|
||||||
| sort \
|
gitcode_release_status="$(
|
||||||
| jq -Rsc --arg bootstrap "$bootstrap_asset" \
|
curl -L -sS -o "$gitcode_release_json" -w "%{http_code}" \
|
||||||
'split("\n") | map(select(length > 0 and . != $bootstrap))'
|
-H "PRIVATE-TOKEN: $GITCODE_TOKEN" \
|
||||||
|
-H "Accept: application/json" \
|
||||||
|
"https://api.gitcode.com/api/v5/repos/$GITCODE_REPOSITORY/releases/tags/$RELEASE_TAG"
|
||||||
)"
|
)"
|
||||||
|
|
||||||
|
case "$gitcode_release_status" in
|
||||||
|
200)
|
||||||
|
release_exists=true
|
||||||
|
existing_assets="$(jq -c '[.assets[]?.name]' "$gitcode_release_json")"
|
||||||
|
;;
|
||||||
|
404)
|
||||||
|
release_exists=false
|
||||||
|
existing_assets='[]'
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "::error::Failed to inspect GitCode release. Response code: $gitcode_release_status"
|
||||||
|
cat "$gitcode_release_json"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
missing_assets="$(
|
||||||
|
jq -cn \
|
||||||
|
--argjson local_assets "$local_assets" \
|
||||||
|
--argjson existing_assets "$existing_assets" \
|
||||||
|
'$local_assets - $existing_assets'
|
||||||
|
)"
|
||||||
|
jq -rn \
|
||||||
|
--argjson local_assets "$local_assets" \
|
||||||
|
--argjson missing_assets "$missing_assets" \
|
||||||
|
'$local_assets - $missing_assets | .[] | "Skipping existing GitCode asset: \(.)"'
|
||||||
|
|
||||||
|
if [[ "$release_exists" == "false" ]]; then
|
||||||
|
bootstrap_asset="$(jq -r '.[0] // ""' <<< "$missing_assets")"
|
||||||
|
asset_matrix="$(jq -c '.[1:]' <<< "$missing_assets")"
|
||||||
|
else
|
||||||
|
bootstrap_asset=""
|
||||||
|
asset_matrix="$missing_assets"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$bootstrap_asset" ]]; then
|
||||||
|
has_bootstrap_asset=true
|
||||||
|
else
|
||||||
|
has_bootstrap_asset=false
|
||||||
|
fi
|
||||||
|
has_matrix_assets="$(jq -r 'length > 0' <<< "$asset_matrix")"
|
||||||
|
|
||||||
delimiter="release-body-$(openssl rand -hex 16)"
|
delimiter="release-body-$(openssl rand -hex 16)"
|
||||||
{
|
{
|
||||||
echo "tag=$RELEASE_TAG"
|
echo "tag=$RELEASE_TAG"
|
||||||
echo "bootstrap_asset=$bootstrap_asset"
|
echo "bootstrap_asset=$bootstrap_asset"
|
||||||
echo "asset_matrix=$asset_matrix"
|
echo "asset_matrix=$asset_matrix"
|
||||||
|
echo "has_bootstrap_asset=$has_bootstrap_asset"
|
||||||
|
echo "has_matrix_assets=$has_matrix_assets"
|
||||||
echo "body<<$delimiter"
|
echo "body<<$delimiter"
|
||||||
# sync_to_gitcode embeds this input in a single-quoted shell string.
|
# sync_to_gitcode embeds this input in a single-quoted shell string.
|
||||||
# Replace ASCII apostrophes so release notes cannot break its script.
|
# Replace ASCII apostrophes so release notes cannot break its script.
|
||||||
@@ -158,10 +208,10 @@ jobs:
|
|||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
retention-days: 1
|
retention-days: 1
|
||||||
|
|
||||||
gitcode-release-metadata:
|
gitcode-release-bootstrap:
|
||||||
name: Publish GitCode release metadata
|
name: Create GitCode release
|
||||||
needs: prepare-release-assets
|
needs: prepare-release-assets
|
||||||
if: ${{ vars.GITCODE_REPOSITORY != '' }}
|
if: ${{ vars.GITCODE_REPOSITORY != '' && needs.prepare-release-assets.outputs.has_bootstrap_asset == 'true' }}
|
||||||
uses: nvdacn/sync_to_gitcode/.github/workflows/CreateReleaseOnGitCode.yaml@18b70112d0e62260bc54085028e5510bbc6323b2
|
uses: nvdacn/sync_to_gitcode/.github/workflows/CreateReleaseOnGitCode.yaml@18b70112d0e62260bc54085028e5510bbc6323b2
|
||||||
with:
|
with:
|
||||||
artifact_name: gitcode-release-assets
|
artifact_name: gitcode-release-assets
|
||||||
@@ -178,8 +228,8 @@ jobs:
|
|||||||
name: Publish GitCode asset (${{ matrix.file_name }})
|
name: Publish GitCode asset (${{ matrix.file_name }})
|
||||||
needs:
|
needs:
|
||||||
- prepare-release-assets
|
- prepare-release-assets
|
||||||
- gitcode-release-metadata
|
- gitcode-release-bootstrap
|
||||||
if: ${{ vars.GITCODE_REPOSITORY != '' }}
|
if: ${{ always() && vars.GITCODE_REPOSITORY != '' && needs.prepare-release-assets.result == 'success' && (needs.gitcode-release-bootstrap.result == 'success' || needs.gitcode-release-bootstrap.result == 'skipped') && needs.prepare-release-assets.outputs.has_matrix_assets == 'true' }}
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
max-parallel: 4
|
max-parallel: 4
|
||||||
|
|||||||
Reference in New Issue
Block a user