2024-10-24 08:59:16 +00:00
|
|
|
name: Update Release
|
|
|
|
on:
|
|
|
|
workflow_call:
|
|
|
|
inputs:
|
|
|
|
tag:
|
|
|
|
required: true
|
|
|
|
type: string
|
|
|
|
milestoneName:
|
|
|
|
required: true
|
|
|
|
type: string
|
|
|
|
repo:
|
|
|
|
required: true
|
|
|
|
type: string
|
|
|
|
artifactName:
|
|
|
|
required: false
|
|
|
|
type: string
|
|
|
|
fileName:
|
|
|
|
required: false
|
|
|
|
type: string
|
|
|
|
jobs:
|
|
|
|
UpdateRelease:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- name: Load Artifact
|
2024-11-28 07:11:08 +00:00
|
|
|
if: ${{ inputs.artifactName != '' }}
|
2024-10-24 08:59:16 +00:00
|
|
|
uses: actions/download-artifact@v3
|
|
|
|
with:
|
|
|
|
name: ${{ inputs.artifactName }}
|
|
|
|
path: ./
|
|
|
|
|
|
|
|
- name: Get Release
|
|
|
|
run: |
|
|
|
|
GITEA_API_URL="https://gitea.greyhound-software.com/api/v1"
|
|
|
|
OWNER="greyhound"
|
|
|
|
API_TOKEN=${{ vars.PAT_TOKEN }}
|
|
|
|
|
|
|
|
# Fetch Release
|
|
|
|
tag=$(echo "${{ inputs.tag }}" | sed 's/\//%2F/g')
|
|
|
|
|
|
|
|
release=$(curl -s -H "Authorization: token $API_TOKEN" \
|
|
|
|
"$GITEA_API_URL/repos/$OWNER/${{ inputs.repo }}/releases/tags/$tag")
|
|
|
|
|
|
|
|
# Extract the ID of the Release
|
|
|
|
release_id=$(echo $release | jq -r '.id')
|
|
|
|
|
|
|
|
if [ "$release_id" == "null" ]; then
|
|
|
|
echo "No release for tag '${{ inputs.tag }}' found. Exiting."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Found tag '${{ inputs.tag }}' release with ID: $release_id"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
milestones=$(curl -s -H "Authorization: token $API_TOKEN" \
|
|
|
|
"$GITEA_API_URL/repos/$OWNER/${{ inputs.repo }}/milestones")
|
|
|
|
|
|
|
|
echo "Milestones: $milestones."
|
|
|
|
|
|
|
|
# Extract the ID of the ${{ inputs.milestoneName }} milestone
|
|
|
|
update_milestone_id=$(echo "$milestones" | jq '.[] | select(.title == "${{ inputs.milestoneName }}") | .id')
|
|
|
|
|
|
|
|
if [ "$update_milestone_id" != "null" ]; then
|
|
|
|
echo "Milestone named '${{ inputs.milestoneName }}' found with id $update_milestone_id."
|
|
|
|
|
|
|
|
description="https://gitea.greyhound-software.com/$OWNER/${{ inputs.repo }}/milestone/$update_milestone_id"
|
|
|
|
|
|
|
|
release_update=$(curl -s -X PATCH -H "Authorization: token $API_TOKEN" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
-d "{\"body\": \"$description\", \"name\": \"${{ inputs.milestoneName }}\"}" \
|
|
|
|
"$GITEA_API_URL/repos/$OWNER/${{ inputs.repo }}/releases/$release_id")
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${{ inputs.artifactName }}" != "null" ]; then
|
|
|
|
artifact_file="./${{ inputs.fileName }}"
|
|
|
|
artifact_name=$(basename "$artifact_file")
|
|
|
|
|
|
|
|
echo "Checking artifact '$artifact_file'"
|
|
|
|
if [ -f "$artifact_file" ]; then
|
|
|
|
echo "Uploading artifact '$artifact_name' to release $release_id..."
|
|
|
|
|
|
|
|
upload_response=$(curl -s -o response.json -w "%{http_code}" -X POST \
|
|
|
|
-H "Authorization: token $API_TOKEN" \
|
|
|
|
-H "Content-Type: multipart/form-data" \
|
|
|
|
-F "name=$artifact_name" \
|
|
|
|
-F "attachment=@$artifact_file" \
|
|
|
|
"$GITEA_API_URL/repos/$OWNER/${{ inputs.repo }}/releases/$release_id/assets")
|
|
|
|
|
|
|
|
http_code=$(echo "$upload_response" | tail -n1) # Last line is the HTTP code
|
|
|
|
if [ "$http_code" -ne 201 ]; then
|
|
|
|
echo "Artifact upload failed with HTTP code: $http_code"
|
|
|
|
echo "Response: $(cat response.json)"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "Artifact uploaded successfully."
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Artifact file '$artifact_file' not found. Exiting."
|
|
|
|
exit 0
|
|
|
|
fi
|
2024-10-18 06:46:44 +00:00
|
|
|
fi
|