-
Notifications
You must be signed in to change notification settings - Fork 6
/
action.yml
77 lines (63 loc) · 2.72 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
name: Publish to Hackage
description: Publish Haskell packages to Hackage
branding:
icon: 'upload'
color: 'green'
inputs:
hackageServer:
description: 'URL to the Hackage server'
required: false
default: 'http://hackage.haskell.org'
hackageToken:
description: 'Authentication token for Hackage'
required: true
publish:
description: 'A flag indicating whether to publish the release on Hackage. Uploads a release candidate if set to false'
required: false
default: 'false'
packagesPath:
description: 'Path that contains packages tarbals'
required: false
default: dist-newstyle/sdist/
docsPath:
description: 'Path that contains packages documentation tarbals'
required: false
default: ''
runs:
using: 'composite'
steps:
- name: Publish packages
shell: bash
run: |
HACKAGE_AUTH_HEADER="Authorization: X-ApiKey ${{ inputs.hackageToken }}"
for PACKAGE_TARBALL in $(find "${{ inputs.packagesPath }}" -maxdepth 1 -name "*.tar.gz"); do
PACKAGE_NAME=$(basename ${PACKAGE_TARBALL%.*.*})
if [ "${{ inputs.publish }}" == "true" ];
then
TARGET_URL="${{ inputs.hackageServer }}/packages/upload";
PACKAGE_URL="${{ inputs.hackageServer }}/package/$PACKAGE_NAME"
HACKAGE_STATUS=$(curl --header "${HACKAGE_AUTH_HEADER}" --silent --head -w %{http_code} -XGET --anyauth ${{ inputs.hackageServer }}/package/${PACKAGE_NAME} -o /dev/null)
else
TARGET_URL="${{ inputs.hackageServer }}/packages/candidates";
PACKAGE_URL="${{ inputs.hackageServer }}/package/$PACKAGE_NAME/candidate"
HACKAGE_STATUS=404
fi
DOCS_URL="$PACKAGE_URL/docs"
if [ "$HACKAGE_STATUS" = "404" ]; then
echo "Uploading ${PACKAGE_NAME} to ${TARGET_URL}"
curl -X POST -f --header "${HACKAGE_AUTH_HEADER}" ${TARGET_URL} -F "package=@$PACKAGE_TARBALL"
echo "Uploaded ${PACKAGE_URL}"
DOC_FILE_NAME="${{ inputs.docsPath }}/${PACKAGE_NAME}-docs.tar.gz"
if [ -n "${{ inputs.docsPath }}" ] && [ -f "$DOC_FILE_NAME" ]; then
echo "Uploading documentation for ${PACKAGE_NAME} to ${DOCS_URL}"
curl -X PUT \
-H 'Content-Type: application/x-tar' \
-H 'Content-Encoding: gzip' \
-H "${HACKAGE_AUTH_HEADER}" \
--data-binary "@$DOC_FILE_NAME" \
"$DOCS_URL"
fi
else
echo "Package ${PACKAGE_NAME}" already exists on Hackage.
fi
done