You've already forked composer-build-action
feat: Initial Versioning 🐛
This commit is contained in:
0
.dockerignore
Normal file
0
.dockerignore
Normal file
5
.env.example
Normal file
5
.env.example
Normal file
@@ -0,0 +1,5 @@
|
||||
GITEA_INSTANCE_BASE_URL="https://gitea.example.com"
|
||||
GITEA_ACCESS_TOKEN="access_token"
|
||||
GITEA_OWNER="owner"
|
||||
GITEA_REPOSITORY="repository"
|
||||
GITEA_PACKAGE_REGISTRY="composer"
|
||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
.idea
|
||||
/.env
|
||||
6
Dockerfile
Normal file
6
Dockerfile
Normal file
@@ -0,0 +1,6 @@
|
||||
FROM cybercinch/base-alpine-bash:latest
|
||||
|
||||
COPY scripts/docker-entrypoint.sh /entrypoint.sh
|
||||
|
||||
ENV upload_file=build/Package.zip
|
||||
CMD ["/entrypoint.sh"]
|
||||
16
README.md
16
README.md
@@ -1,2 +1,16 @@
|
||||
# composer-build-action
|
||||
<p align="center">
|
||||
<img width="560" height="260" src="docs/image/github_gitea_actions.jpg" alt="github gitea actions">
|
||||
</p>
|
||||
|
||||
# Build Composer package
|
||||
|
||||
[](https://github.com/rosven9856/gitea-package-action/blob/master/LICENSE)
|
||||
|
||||
This action will create a .zip archive to upload to Packagist repo.
|
||||
|
||||
|
||||
## Example usage
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: https://hub.cybercinch.nz/cybercinch/composer-build-action@mains
|
||||
|
||||
8
action.yml
Normal file
8
action.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
name: "Gitea Composer Build package"
|
||||
description: "Create a composer package from source"
|
||||
runs:
|
||||
using: "docker"
|
||||
image: "Dockerfile"
|
||||
branding:
|
||||
icon: 'package'
|
||||
color: 'green'
|
||||
9
compose.yml
Normal file
9
compose.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
services:
|
||||
composer-uploader:
|
||||
container_name: composer-build-package
|
||||
build:
|
||||
context: ./
|
||||
dockerfile: Dockerfile
|
||||
working_dir: /build
|
||||
volumes:
|
||||
- ./:/build
|
||||
155
scripts/docker-entrypoint.sh
Executable file
155
scripts/docker-entrypoint.sh
Executable file
@@ -0,0 +1,155 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This is to serve as a Plugin for Drone to enable uploading of generic packages to Gitea e.g Ansible Roles
|
||||
|
||||
set -eo pipefail
|
||||
shopt -s nullglob
|
||||
|
||||
# check to see if this file is being run or sourced from another script
|
||||
_is_sourced() {
|
||||
# https://unix.stackexchange.com/a/215279
|
||||
[ "${#FUNCNAME[@]}" -ge 2 ] &&
|
||||
[ "${FUNCNAME[0]}" = '_is_sourced' ] &&
|
||||
[ "${FUNCNAME[1]}" = 'source' ]
|
||||
}
|
||||
|
||||
# logging functions
|
||||
action_log() {
|
||||
local type="$1"
|
||||
shift
|
||||
# accept argument string or stdin
|
||||
local text="$*"
|
||||
if [ "$#" -eq 0 ]; then text="$(cat)"; fi
|
||||
local dt
|
||||
dt="$(date -D 'YYYY-MM-DD hh:mm[:ss]')"
|
||||
printf '%s [%s] [gitea-composer-uploader]: %s\n' "$dt" "$type" "$text"
|
||||
}
|
||||
action_note() {
|
||||
action_log INF "$@"
|
||||
}
|
||||
action_warn() {
|
||||
action_log WRN "$@" >&2
|
||||
}
|
||||
action_error() {
|
||||
action_log ERR "$@" >&2
|
||||
}
|
||||
|
||||
# Verify that the minimally required password settings are set for operation.
|
||||
function verify_minimum_env {
|
||||
if [ -z "$username" ]; then
|
||||
action_warn "username is required for plugin operation"
|
||||
fi
|
||||
if [ -z "$baseurl" ]; then
|
||||
action_warn "gitea_baseurl setting is required for plugin operation"
|
||||
fi
|
||||
if [ -z "$owner" ]; then
|
||||
action_warn "gitea_owner setting is required for plugin operation"
|
||||
fi
|
||||
if [ -z "$access_token" ]; then
|
||||
action_warn "gitea_token setting is required for plugin operation"
|
||||
fi
|
||||
if [ -z "$version" ]; then
|
||||
action_warn "gitea_version setting is required for plugin operation"
|
||||
fi
|
||||
if [ -z "$username" ] ||
|
||||
[ -z "$baseurl" ] ||
|
||||
[ -z "$version" ] ||
|
||||
[ -z "$access_token" ]; then
|
||||
action_error <<-'EOF'
|
||||
You need to specify one/all of the following settings:
|
||||
- username
|
||||
- access_token
|
||||
- baseurl
|
||||
EOF
|
||||
fi
|
||||
action_note "Sufficient configuration"
|
||||
|
||||
}
|
||||
|
||||
function delete_file {
|
||||
no_prefix_version="${version##v}"
|
||||
for file in ${upload_file}; do
|
||||
#action_note "curl -s -o /dev/null -w '%{http_code}' --user \"${username}:${access_token}\" -X DELETE ${baseurl}/api/packages/${owner:-$username}/composer/${owner:-$username}%2F${repo_name}/${no_prefix_version}"
|
||||
response=$(curl -s -o /dev/null -w "%{http_code}" --user "${username}:${access_token}" -X DELETE "${baseurl}/api/v1/packages/${owner:-$username}/composer/${owner:-$username}%2F${repo_name}/${no_prefix_version}")
|
||||
if [ "${response}" == 204 ] || [ "${response}" == 200 ]; then
|
||||
action_note "Deleted package version ${version} for ${owner:-$username}/${repo_name}"
|
||||
elif [ "${response}" == 404 ]; then
|
||||
action_error "Not Found: Odd I cannot locate your package! [bug]"
|
||||
else
|
||||
action_error "Response code was ${response}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function process_upload_file {
|
||||
for file in ${upload_file}; do
|
||||
#action_note "curl -s -o /dev/null -w '%{http_code}' --user \"${username}:${access_token}\" --upload-file ${file} \"${baseurl}/api/packages/${owner:-$username}/composer?version=${version}\""
|
||||
response=$(curl -s -o /dev/null -w "%{http_code}" --user "${username}:${access_token}" --upload-file "${file}" "${baseurl}/api/packages/${owner:-$username}/composer?version=${version}")
|
||||
if [ "${response}" == 409 ]; then
|
||||
action_error "Conflict: File already exists"
|
||||
if [ "${FILE_OVERWRITE:=$overwrite_files}" == 'true' ]; then
|
||||
# Delete file as already exists
|
||||
delete_file
|
||||
response=$(curl -s -o /dev/null -w "%{http_code}" --user "${username}:${access_token}" --upload-file "${file}" "${baseurl}/api/packages/${owner:-$username}/composer?version=${version}")
|
||||
if [ "${response}" == 409 ]; then
|
||||
action_error "Conflict: File already exists"
|
||||
elif [ "${response}" == 201 ]; then
|
||||
action_note "File uploaded successfully"
|
||||
elif [ "${response}" == 400 ]; then
|
||||
action_error "Bad Request: Version likely already exists"
|
||||
fi
|
||||
else
|
||||
action_error 'Unable to upload file. Maybe toggle overwrite_files setting to true :)'
|
||||
exit 1
|
||||
fi
|
||||
elif [ "${response}" == 201 ]; then
|
||||
action_note "File uploaded successfully"
|
||||
elif [ "${response}" == 400 ]; then
|
||||
action_warn "Bad Request: Version likely already exists"
|
||||
if [ "${FILE_OVERWRITE:=$overwrite_files}" == 'true' ]; then
|
||||
# Delete file as already exists
|
||||
delete_file
|
||||
response=$(curl -s -o /dev/null -w "%{http_code}" --user "${username}:${access_token}" --upload-file "${file}" "${baseurl}/api/packages/${owner:-$username}/composer?version=${version}")
|
||||
if [ "${response}" == 409 ]; then
|
||||
action_error "Conflict: File already exists"
|
||||
elif [ "${response}" == 201 ]; then
|
||||
action_note "File uploaded successfully"
|
||||
elif [ "${response}" == 400 ]; then
|
||||
action_error "Bad Request: Version likely already exists"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
action_error 'Unable to upload file. Maybe toggle overwrite_files setting to true :)'
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
function build_package(){
|
||||
mkdir -p build
|
||||
zip -r "build/Package.zip" \
|
||||
. \
|
||||
-x '.semrel/*' \
|
||||
-x '.generated-go-semantic-release-changelog.md' \
|
||||
-x './vendor/*' \
|
||||
-x './tests/*' \
|
||||
-x './build/*' \
|
||||
-x './.git/*' \
|
||||
-x './.idea/*' \
|
||||
-x './.github/*' \
|
||||
-x './scripts/*'
|
||||
}
|
||||
|
||||
_main() {
|
||||
action_note "Starting"
|
||||
# verify_minimum_env "$@"
|
||||
# process_upload_file "$@"
|
||||
build_package "$@"
|
||||
}
|
||||
|
||||
# If we are sourced from elsewhere, don't perform any further actions
|
||||
if ! _is_sourced; then
|
||||
_main "$@"
|
||||
fi
|
||||
Reference in New Issue
Block a user