init
This commit is contained in:
97
.gitea/workflows/updateRelease.yaml
Normal file
97
.gitea/workflows/updateRelease.yaml
Normal file
@@ -0,0 +1,97 @@
|
||||
name: Update Release
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
version:
|
||||
required: true
|
||||
type: string
|
||||
milestoneName:
|
||||
required: true
|
||||
type: string
|
||||
repo:
|
||||
required: true
|
||||
type: string
|
||||
artifactName:
|
||||
required: true
|
||||
type: string
|
||||
fileName:
|
||||
required: true
|
||||
type: string
|
||||
jobs:
|
||||
UpdateRelease:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Load Artifact
|
||||
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
|
||||
release=$(curl -s -H "Authorization: token $API_TOKEN" \
|
||||
"$GITEA_API_URL/repos/$OWNER/${{ inputs.repo }}/releases/tags/${{ inputs.version }}")
|
||||
|
||||
# Extract the ID of the Release
|
||||
release_id=$(echo $release | jq -r '.id')
|
||||
|
||||
if [ "$release_id" == "null" ]; then
|
||||
echo "No release for tag '${{ inputs.version }}' found. Exiting."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Found tag '${{ inputs.version }}' 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
|
||||
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user