mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-12-16 20:17:10 +08:00
149 lines
5.7 KiB
YAML
149 lines
5.7 KiB
YAML
name: Update version.json from Release
|
|
|
|
on:
|
|
release:
|
|
types: [published, edited]
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
jobs:
|
|
update-version-json:
|
|
name: Update version.json with release information
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Extract version from tag
|
|
id: version
|
|
run: |
|
|
TAG_NAME="${{ github.event.release.tag_name }}"
|
|
VERSION_ONLY="${TAG_NAME#v}"
|
|
echo "TAG_NAME=${TAG_NAME}" >> $GITHUB_OUTPUT
|
|
echo "VERSION_ONLY=${VERSION_ONLY}" >> $GITHUB_OUTPUT
|
|
|
|
# Extract date from tag if available (format: v1.2.3-20251113-abc)
|
|
if [[ "${TAG_NAME}" =~ -([0-9]{8})- ]]; then
|
|
DATE_STR="${BASH_REMATCH[1]}"
|
|
BUILD_DATE_ISO="${DATE_STR:0:4}-${DATE_STR:4:2}-${DATE_STR:6:2}"
|
|
else
|
|
# Use release published date
|
|
BUILD_DATE_ISO=$(echo "${{ github.event.release.published_at }}" | cut -d'T' -f1)
|
|
fi
|
|
echo "BUILD_DATE_ISO=${BUILD_DATE_ISO}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Install jq
|
|
run: sudo apt-get update && sudo apt-get install -y jq
|
|
|
|
- name: Get release information
|
|
id: release_info
|
|
run: |
|
|
# Use jq to properly escape JSON
|
|
RELEASE_BODY="${{ github.event.release.body }}"
|
|
RELEASE_NAME="${{ github.event.release.name }}"
|
|
|
|
# Handle empty values
|
|
if [ -z "$RELEASE_BODY" ]; then
|
|
RELEASE_BODY=""
|
|
fi
|
|
if [ -z "$RELEASE_NAME" ]; then
|
|
RELEASE_NAME=""
|
|
fi
|
|
|
|
# Save to temporary files for proper handling
|
|
echo -n "$RELEASE_BODY" > /tmp/release_body.txt
|
|
echo -n "$RELEASE_NAME" > /tmp/release_name.txt
|
|
|
|
# Use jq to escape JSON strings
|
|
RELEASE_BODY_JSON=$(jq -Rs . < /tmp/release_body.txt)
|
|
RELEASE_NAME_JSON=$(jq -Rs . < /tmp/release_name.txt)
|
|
|
|
echo "RELEASE_BODY=${RELEASE_BODY_JSON}" >> $GITHUB_OUTPUT
|
|
echo "RELEASE_NAME=${RELEASE_NAME_JSON}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Download current version.json from server
|
|
id: download_version
|
|
continue-on-error: true
|
|
run: |
|
|
# Try to download current version.json from server
|
|
curl -f -s "https://version.crossdesk.cn/version.json" -o version.json || echo "Failed to download, will create new one"
|
|
|
|
- name: Generate or update version.json
|
|
shell: bash
|
|
run: |
|
|
TAG_NAME="${{ steps.version.outputs.TAG_NAME }}"
|
|
VERSION_ONLY="${{ steps.version.outputs.VERSION_ONLY }}"
|
|
BUILD_DATE_ISO="${{ steps.version.outputs.BUILD_DATE_ISO }}"
|
|
RELEASE_NAME_JSON="${{ steps.release_info.outputs.RELEASE_NAME }}"
|
|
RELEASE_BODY_JSON="${{ steps.release_info.outputs.RELEASE_BODY }}"
|
|
|
|
# Default downloads structure - use jq to build JSON safely
|
|
DEFAULT_DOWNLOADS=$(jq -n \
|
|
--arg tag "${TAG_NAME}" \
|
|
'{
|
|
"windows-x64": {
|
|
"url": ("https://downloads.crossdesk.cn/crossdesk-win-x64-" + $tag + ".exe"),
|
|
"filename": ("crossdesk-win-x64-" + $tag + ".exe")
|
|
},
|
|
"macos-x64": {
|
|
"url": ("https://downloads.crossdesk.cn/crossdesk-macos-x64-" + $tag + ".pkg"),
|
|
"filename": ("crossdesk-macos-x64-" + $tag + ".pkg")
|
|
},
|
|
"macos-arm64": {
|
|
"url": ("https://downloads.crossdesk.cn/crossdesk-macos-arm64-" + $tag + ".pkg"),
|
|
"filename": ("crossdesk-macos-arm64-" + $tag + ".pkg")
|
|
},
|
|
"linux-amd64": {
|
|
"url": ("https://downloads.crossdesk.cn/crossdesk-linux-amd64-" + $tag + ".deb"),
|
|
"filename": ("crossdesk-linux-amd64-" + $tag + ".deb")
|
|
},
|
|
"linux-arm64": {
|
|
"url": ("https://downloads.crossdesk.cn/crossdesk-linux-arm64-" + $tag + ".deb"),
|
|
"filename": ("crossdesk-linux-arm64-" + $tag + ".deb")
|
|
}
|
|
}')
|
|
|
|
# If version.json exists, try to preserve downloads section
|
|
if [ -f version.json ] && jq -e '.downloads' version.json > /dev/null 2>&1; then
|
|
EXISTING_DOWNLOADS=$(jq -c '.downloads' version.json)
|
|
if [ "$EXISTING_DOWNLOADS" != "null" ] && [ "$EXISTING_DOWNLOADS" != "{}" ]; then
|
|
DOWNLOADS="$EXISTING_DOWNLOADS"
|
|
else
|
|
DOWNLOADS="$DEFAULT_DOWNLOADS"
|
|
fi
|
|
else
|
|
DOWNLOADS="$DEFAULT_DOWNLOADS"
|
|
fi
|
|
|
|
# Create version.json using jq for proper JSON formatting
|
|
jq -n \
|
|
--arg version "$VERSION_ONLY" \
|
|
--arg releaseDate "$BUILD_DATE_ISO" \
|
|
--argjson releaseName "$RELEASE_NAME_JSON" \
|
|
--argjson releaseNotes "$RELEASE_BODY_JSON" \
|
|
--arg tagName "$TAG_NAME" \
|
|
--argjson downloads "$DOWNLOADS" \
|
|
'{
|
|
version: $version,
|
|
releaseDate: $releaseDate,
|
|
releaseName: $releaseName,
|
|
releaseNotes: $releaseNotes,
|
|
tagName: $tagName,
|
|
downloads: $downloads
|
|
}' > version.json
|
|
|
|
cat version.json
|
|
|
|
- name: Upload version.json to server
|
|
uses: burnett01/rsync-deployments@5.2
|
|
with:
|
|
switches: -avzr --delete
|
|
path: version.json
|
|
remote_path: /var/www/html/version/
|
|
remote_host: ${{ secrets.SERVER_HOST }}
|
|
remote_user: ${{ secrets.SERVER_USER }}
|
|
remote_key: ${{ secrets.SERVER_KEY }} |