-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
150 lines (135 loc) · 5.09 KB
/
action.yml
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
name: describe-docker
description: GitHub action to update docker description
inputs:
username:
description: Docker hub username
required: true
password:
description: Docker hub password
required: true
registry:
description: Docker hub registry URL
required: false
default: https://hub.docker.com/v2
repository:
description: Name of the docker image repository
required: true
summary:
description: Docker repository overview (100-character limit)
required: true
filename:
description: Filename to read the full description for the docker image.
required: true
branding:
icon: anchor
color: gray-dark
outputs: { }
runs:
using: composite
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate Inputs
run: |
if [[ -z "${{ inputs.username }}" ]]; then
echo "::error title=MissingInput::Docker hub username is not provided."
exit 1
fi
if [[ -z "${{ inputs.password }}" ]]; then
echo "::error title=MissingInput::Docker hub password is not provided."
exit 1
fi
if [[ -z "${{ inputs.registry }}" ]]; then
echo "::error title=MissingInput::Docker registry URL is not provided."
exit 1
fi
if [[ -z "${{ inputs.repository }}" ]]; then
echo "::error title=MissingInput::Repository name is not provided."
exit 1
fi
if [[ -z "${{ inputs.summary }}" ]]; then
echo "::warning title=MissingInput::Summary is not provided."
fi
if [[ -z "${{ inputs.filename }}" ]]; then
echo "::error title=MissingInput::Description file is not provided."
exit 1
fi
if [[ ! -f "${{ inputs.filename }}" ]]; then
echo "::error title=MissingInput::Description file '${{ inputs.filename }}' does not exist."
exit 1
fi
if [[ "${{ inputs.repository }}" == "${{ inputs.username }}/"* ]]; then
echo "REPOSITORY_NAME=${{ inputs.repository }}" >> $GITHUB_ENV
elif [[ "${{ inputs.repository }}" == */* ]]; then
echo "::error title=InvalidInput::Invalid repository name, it should either be 'username/repository' or just 'repository'."
exit 1
else
echo "REPOSITORY_NAME=${{ inputs.username }}/${{ inputs.repository }}" >> $GITHUB_ENV
fi
shell: bash
- name: Fetch API Token
run: |
payload=$(jq -n \
--arg username "${{ inputs.username }}" \
--arg password "${{ inputs.password }}" \
'{username: $username, password: $password}')
token=$(curl -s -X POST "${{ inputs.registry }}/users/login/" \
-H "Content-Type: application/json" \
-d "$payload" | jq -r '.token')
if [[ -n "${token}" ]]; then
echo "::debug title=Token Retriever::Retrieved token successfully"
echo "API_TOKEN=${token}" >> $GITHUB_ENV
else
echo "::error title=Token Retriever::Failed to get auth token"
exit 1
fi
shell: bash
- name: Check summary limit
run: |
summary_limit=100
warn="Summary exceeds DockerHub's limit and has been truncated to ${summary_limit} characters."
summary="${{ inputs.summary }}"
summary_length=${#summary}
if [[ "$summary_length" -gt "${summary_limit}" ]]; then
echo "::warning title=Summary Too Long::${warn}"
echo "SUMMARY=${summary:0:97}..." >> $GITHUB_ENV
else
echo "SUMMARY=${summary}" >> $GITHUB_ENV
fi
shell: bash
- name: Update description
run: |
full_description="$(cat "${{ inputs.filename }}")"
payload=$(jq -n \
--arg description "${{ env.SUMMARY }}" \
--arg full_description "$full_description" \
'{description: $description, full_description: $full_description}')
response=$(curl -s -o /tmp/desc -w "%{http_code}" -X PATCH \
"${{ inputs.registry }}/repositories/${{ env.REPOSITORY_NAME }}/" \
-H "Authorization: Bearer ${{ env.API_TOKEN }}" \
-H "Content-Type: application/json" \
-d "$payload")
status_code="${response: -3}"
if [[ "${status_code}" -eq 200 ]]; then
echo "::notice title=Updater::Updated description successfully"
exit 0
elif [[ -f "/tmp/desc" ]]; then
echo "::error title=Updater::Failed to update description"
response_payload="$(cat /tmp/desc)"
reason=$(echo "${response_payload}" | jq '.message')
info=$(echo "${response_payload}" | jq '.errinfo')
if [[ "$reason" != "null" ]]; then
echo "::error title=Updater::[${status_code}]: $reason"
else
echo "::error title=Updater::[${status_code}]: $(cat /tmp/desc)"
fi
if [[ "$info" != "null" ]]; then
echo "::error title=Updater::${info}"
fi
else
echo "::error title=Updater::Failed to update description - ${status_code}"
fi
exit 1
shell: bash