Updated CI
This commit is contained in:
44
.github/workflows/sync-release.yml
vendored
44
.github/workflows/sync-release.yml
vendored
@@ -25,26 +25,25 @@ jobs:
|
||||
|
||||
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
|
||||
|
||||
# name defaults to tag when upstream leaves it empty
|
||||
if [ -z "$NAME" ]; then
|
||||
echo "name=$TAG" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "name=$NAME" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
# body via file to preserve newlines
|
||||
echo "$BODY" > /tmp/release_body.md
|
||||
|
||||
# collect asset download URLs
|
||||
echo "$RELEASE" | jq -r '.assets[].browser_download_url' > /tmp/asset_urls.txt
|
||||
|
||||
- name: Check if release already exists
|
||||
id: check
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
TAG="${{ steps.upstream.outputs.tag }}"
|
||||
if gh release view "$TAG" >/dev/null 2>&1; then
|
||||
API_URL="${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/tags/${TAG}"
|
||||
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
|
||||
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||
"$API_URL")
|
||||
if [ "$HTTP_CODE" = "200" ]; then
|
||||
echo "exists=true" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "exists=false" >> "$GITHUB_OUTPUT"
|
||||
@@ -61,18 +60,33 @@ jobs:
|
||||
|
||||
- name: Create release with assets
|
||||
if: steps.check.outputs.exists == 'false'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
TAG="${{ steps.upstream.outputs.tag }}"
|
||||
NAME="${{ steps.upstream.outputs.name }}"
|
||||
BODY=$(cat /tmp/release_body.md)
|
||||
API_URL="${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases"
|
||||
|
||||
RESPONSE=$(curl -sf \
|
||||
-X POST \
|
||||
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg tag "$TAG" --arg name "$NAME" --arg body "$BODY" \
|
||||
'{tag_name: $tag, name: $name, body: $body}')" \
|
||||
"$API_URL")
|
||||
|
||||
RELEASE_ID=$(echo "$RESPONSE" | jq -r '.id')
|
||||
echo "Created release $RELEASE_ID"
|
||||
|
||||
UPLOAD_URL="${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets"
|
||||
|
||||
ASSET_ARGS=""
|
||||
for f in /tmp/assets/*; do
|
||||
ASSET_ARGS="$ASSET_ARGS $f"
|
||||
FILENAME=$(basename "$f")
|
||||
echo "Uploading $FILENAME"
|
||||
curl -sf \
|
||||
-X POST \
|
||||
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||
-H "Content-Type: application/octet-stream" \
|
||||
--data-binary "@$f" \
|
||||
"${UPLOAD_URL}?name=${FILENAME}"
|
||||
echo " -> done"
|
||||
done
|
||||
|
||||
gh release create "$TAG" \
|
||||
--title "$NAME" \
|
||||
--notes-file /tmp/release_body.md \
|
||||
$ASSET_ARGS
|
||||
|
||||
Reference in New Issue
Block a user