-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (150 loc) · 6.07 KB
/
CreateReleaseOnGitCode.yaml
File metadata and controls
152 lines (150 loc) · 6.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: GitCode Release
on:
workflow_call:
inputs:
artifact_name:
description: 'Name of the artifact to download'
required: false
type: string
gitcode_repository:
description: 'GitCode repository path (e.g., username/repo)'
required: false
type: string
default: ${{ vars.GITCODE_REPOSITORY || github.repository }}
default_branch:
description: 'Default branch for the release'
required: false
type: string
default: 'master'
tag_name:
description: 'Tag name for release'
required: false
type: string
default: ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || '' }}
body:
description: 'Release body/content in markdown format'
required: false
type: string
default: ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || '' }}
prerelease:
description: 'Whether this is a prerelease (beta)'
required: false
type: boolean
default: false
file_name:
description: 'File name pattern to upload (supports wildcards)'
required: false
type: string
default: '*.*'
secrets:
GITCODE_TOKEN:
description: 'GitCode access token'
required: true
jobs:
gitcode_release:
name: Create Release on GitCode
runs-on: ubuntu-latest
steps:
- name: Download artifact
if: ${{ inputs.artifact_name }}
uses: actions/download-artifact@v8
with:
pattern: '${{ inputs.artifact_name }}'
path: .
merge-multiple: true
- name: Check if Release exists on GitCode
id: check_release
run: |
RESPONSE=$(curl -L -sS -o /dev/null -w "%{http_code}" \
-H 'PRIVATE-TOKEN: ${{ secrets.GITCODE_TOKEN }}' \
-H "Accept: application/json" \
"https://api.gitcode.com/api/v5/repos/${{ inputs.gitcode_repository }}/releases/tags/${{ inputs.tag_name }}")
if [ "$RESPONSE" = "200" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "Release already exists on GitCode"
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "Release does not exist on GitCode"
fi
- name: Create Release on GitCode
if: steps.check_release.outputs.exists == 'false'
id: create_release
run: |
echo "Creating new release on GitCode..."
TEMP_RESPONSE="/tmp/release_create_${GITHUB_RUN_ID}_${GITHUB_RUN_ATTEMPT}.json"
RESPONSE=$(curl -L -o "$TEMP_RESPONSE" -sS -w "%{http_code}" \
-X POST \
-H 'PRIVATE-TOKEN: ${{ secrets.GITCODE_TOKEN }}' \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"tag_name": "${{ inputs.tag_name }}",
"target_commitish": "${{ inputs.default_branch }}",
"name": "${{ inputs.tag_name }}",
"body": ${{ toJSON(inputs.body) }},
"release_status": "${{ inputs.prerelease && 'pre' || 'latest' }}"
}' \
"https://api.gitcode.com/api/v5/repos/${{ inputs.gitcode_repository }}/releases")
if [ "$RESPONSE" = "200" ]; then
echo "✅ Release created successfully on GitCode"
else
echo "❌ Failed to create release. Response code: $RESPONSE"
cat "$TEMP_RESPONSE"
exit 1
fi
- name: Update Release on GitCode
if: steps.check_release.outputs.exists == 'true'
id: update_release
run: |
echo "Updating existing release on GitCode..."
TEMP_RESPONSE="/tmp/release_update_${GITHUB_RUN_ID}_${GITHUB_RUN_ATTEMPT}.json"
RESPONSE=$(curl -L -o "$TEMP_RESPONSE" -sS -w "%{http_code}" \
-X PATCH \
-H 'PRIVATE-TOKEN: ${{ secrets.GITCODE_TOKEN }}' \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"tag_name": "${{ inputs.tag_name }}",
"name": "${{ inputs.tag_name }}",
"body": ${{ toJSON(inputs.body) }},
"release_status": "${{ inputs.prerelease && 'pre' || 'latest' }}"
}' \
"https://api.gitcode.com/api/v5/repos/${{ inputs.gitcode_repository }}/releases/${{ inputs.tag_name }}")
if [ "$RESPONSE" = "200" ]; then
echo "✅ Release updated successfully on GitCode"
else
echo "❌ Failed to update release. Response code: $RESPONSE"
cat "$TEMP_RESPONSE"
exit 1
fi
- name: Upload Build Artifacts to Release
run: |
for file in ${{ inputs.file_name }}; do
echo "Uploading $file..."
UPLOAD_INFO=$(curl -sS \
-H 'PRIVATE-TOKEN: ${{ secrets.GITCODE_TOKEN }}' \
-H "Accept: application/json" \
"https://api.gitcode.com/api/v5/repos/${{ inputs.gitcode_repository }}/releases/${{ inputs.tag_name }}/upload_url?file_name=$file")
UPLOAD_URL=$(echo "$UPLOAD_INFO" | jq -r '.url')
CURL_HEADERS=()
HEADERS_JSON=$(echo "$UPLOAD_INFO" | jq -r '.headers // empty')
if [ -n "$HEADERS_JSON" ] && [ "$HEADERS_JSON" != "null" ]; then
while IFS='' read -r line; do
if [ -n "$line" ]; then
CURL_HEADERS+=("-H" "$line")
fi
done < <(echo "$HEADERS_JSON" | jq -r 'to_entries[] | "\(.key): \(.value)"')
fi
TEMP_RESPONSE="/tmp/upload_${file}_${GITHUB_RUN_ID}_${GITHUB_RUN_ATTEMPT}.json"
RESPONSE=$(curl -X PUT -w "%{http_code}" -o "$TEMP_RESPONSE" --retry 3 \
-T "$file" \
"${CURL_HEADERS[@]}" \
"$UPLOAD_URL")
if [ "$RESPONSE" = "200" ]; then
echo "✅ Uploaded $file successfully"
else
echo "❌ Failed to upload $file. Response code: $RESPONSE"
cat "$TEMP_RESPONSE"
exit 1
fi
done