init repo
This commit is contained in:
5
Dockerfile
Normal file
5
Dockerfile
Normal file
@@ -0,0 +1,5 @@
|
||||
FROM alpine
|
||||
ADD script.sh /bin/
|
||||
RUN chmod +x /bin/script.sh
|
||||
RUN apk -Uuv add curl ca-certificates
|
||||
ENTRYPOINT /bin/script.sh
|
||||
26
README.md
Normal file
26
README.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# drone-gitea-package
|
||||
|
||||
---
|
||||
|
||||
A Drone plugin for uploading files as generic package to Gitea package registry.
|
||||
|
||||
|
||||
### Example
|
||||
|
||||
```yaml
|
||||
pipeline:
|
||||
build:
|
||||
image: alpine
|
||||
commands:
|
||||
- touch example.md
|
||||
|
||||
artifacts:
|
||||
image: gurken2108/drone-gitea-package
|
||||
settings:
|
||||
user:
|
||||
from_secret: gitea_user
|
||||
token:
|
||||
from_secret: gitea_token
|
||||
file: ./example.md
|
||||
version: dev
|
||||
```
|
||||
50
script.sh
Normal file
50
script.sh
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/bin/ash
|
||||
|
||||
if [ -z "$PLUGIN_USER" ]; then
|
||||
echo "ERR: user variable is empty"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$PLUGIN_TOKEN" ]; then
|
||||
echo "ERR: token variable is empty"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$PLUGIN_FILE" ]; then
|
||||
echo "ERR: file variable is empty"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
HASH=`echo "$DRONE_COMMIT" | cut -c-10`
|
||||
if [ -z "$PLUGIN_VERSION" ]; then
|
||||
echo "INFO: version variable is empty defaulting to $HASH"
|
||||
fi
|
||||
|
||||
API_URL=`echo "$DRONE_REPO_LINK" | grep -Eo '^http[s]?://[^/]+'`
|
||||
PACKAGE_SUBPATH=packages/${DRONE_REPO_OWNER}/generic/${DRONE_REPO_NAME}/${PLUGIN_VERSION:-$HASH}
|
||||
PACKAGE_URL=${API_URL}/api/$PACKAGE_SUBPATH
|
||||
PACKAGE_API_URL=${API_URL}/api/v1/$PACKAGE_SUBPATH
|
||||
echo "DEBUG: destination $PACKAGE_URL"
|
||||
|
||||
curl \
|
||||
--location \
|
||||
--user ${PLUGIN_USER}:${PLUGIN_TOKEN} \
|
||||
-X 'DELETE' \
|
||||
--silent --output /dev/null \
|
||||
$PACKAGE_API_URL
|
||||
|
||||
# requires https://github.com/go-gitea/gitea/pull/20661
|
||||
for f in $PLUGIN_FILE; do
|
||||
BASE_FILENAME=`basename $f`
|
||||
echo "INFO: uploading $BASE_FILENAME to $API_URL"
|
||||
status_code=`curl --location --user ${PLUGIN_USER}:${PLUGIN_TOKEN} --upload-file $f --write-out %{http_code} --silent --output /dev/null $PACKAGE_URL/$BASE_FILENAME`
|
||||
|
||||
if [ $status_code -ne 201 ]; then
|
||||
echo "ERR: failed to upload file ($status_code)"
|
||||
exit 1
|
||||
else
|
||||
echo "INFO: upload of $BASE_FILENAME successful to $PACKAGE_URL/${BASE_FILENAME}"
|
||||
fi
|
||||
done
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user