diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e69de29 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..1fff8db --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,13 @@ +# Contributing + +- Feedback, wishes and suggestions can be sent by email. +- Constructive criticism, bug descriptions and other reports are welcome. +- Email: mail@ihub.to + +## Sources + +- [**GitHub**](https://github.com/ghastore) +- [GitLab](https://gitlab.com/ghastore) (MIRROR) +- [Codeberg](https://codeberg.org/ghastore) (MIRROR) +- [MosHub](https://hub.mos.ru/ghastore) (MIRROR) +- [Git.Org.Ru](https://git.org.ru/ghastore) (MIRROR) diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..57c8f52 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM alpine + +LABEL "name"="GPG Builder" +LABEL "description"="GitHub Action for build GPG files." +LABEL "maintainer"="iHub TO " +LABEL "repository"="https://github.com/ghastore/build-gpg.git" +LABEL "homepage"="https://github.com/ghastore" + +COPY *.sh / +RUN apk add --no-cache bash curl git git-lfs gpg + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/LICENSE b/LICENSE index f819c39..62a7665 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 GitHub Actions Store +Copyright (c) 2023 iHub TO Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 3270ecd..13d5518 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# build-gpg \ No newline at end of file +# gpgstore-gpg-build \ No newline at end of file diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..753948a --- /dev/null +++ b/action.yml @@ -0,0 +1,38 @@ +name: "GPG Builder" +author: "iHub TO " +description: "GitHub Action for build GPG files." +branding: + icon: "" + color: "" +inputs: + git_repo: + description: "Git Repository" + required: true + git_user: + description: "Git User" + required: true + git_email: + description: "Git E-mail" + required: true + git_token: + description: "Git Token" + required: true + gpg_url: + description: "GPG URL" + required: true + gpg_name: + description: "GPG Name" + required: true + gpg_cmd: + description: "GPG Command" + required: false +runs: + using: "docker" + image: "Dockerfile" + args: + - ${{ inputs.git_repo }} + - ${{ inputs.git_user }} + - ${{ inputs.git_email }} + - ${{ inputs.git_token }} + - ${{ inputs.gpg_url }} + - ${{ inputs.gpg_name }} diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..1512c27 --- /dev/null +++ b/build.sh @@ -0,0 +1,114 @@ +#!/bin/bash -e + +# -------------------------------------------------------------------------------------------------------------------- # +# CONFIGURATION. +# -------------------------------------------------------------------------------------------------------------------- # + +# Vars. +GIT_REPO="${1}" +GIT_USER="${2}" +GIT_EMAIL="${3}" +GIT_TOKEN="${4}" +GPG_URL="${5}" +GPG_NAME="${6}" +GPG_CMD="${7}" +USER_AGENT="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36" + +# Apps. +date="$( command -v date )" +git="$( command -v git )" +curl="$( command -v curl )" +gpg="$( command -v gpg )" + +# Dirs. +d_src="/root/git/repo" + +# Git. +${git} config --global user.name "${GIT_USER}" +${git} config --global user.email "${GIT_EMAIL}" +${git} config --global init.defaultBranch 'main' + +# -------------------------------------------------------------------------------------------------------------------- # +# INITIALIZATION. +# -------------------------------------------------------------------------------------------------------------------- # + +init() { + ts="$( _timestamp )" + + clone \ + && build \ + && push +} + +# -------------------------------------------------------------------------------------------------------------------- # +# GIT: CLONE REPOSITORY. +# -------------------------------------------------------------------------------------------------------------------- # + +clone() { + echo "--- [GIT] CLONE: ${GIT_REPO#https://}" + + local src="https://${GIT_USER}:${GIT_TOKEN}@${GIT_REPO#https://}" + ${git} clone "${src}" "${d_src}" + + echo "--- [GIT] LIST: '${d_src}'" + ls -1 "${d_src}" +} + +# -------------------------------------------------------------------------------------------------------------------- # +# GPG: BUILD FILES. +# -------------------------------------------------------------------------------------------------------------------- # + +build() { + echo "--- [GPG] BUILD" + _pushd "${d_src}" || exit 1 + + if [[ "${GPG_CMD}" == "dearmor" ]]; then + ${curl} -X GET -A "${USER_AGENT}" -fsSL "${GPG_URL}" | ${gpg} --batch --yes --dearmor -o "${GPG_NAME}" + else + ${curl} -X GET -A "${USER_AGENT}" -fsSL -o "${GPG_NAME}" "${GPG_URL}" + fi + + _popd || exit 1 +} + +# -------------------------------------------------------------------------------------------------------------------- # +# GIT: PUSH GPG TO GPG STORE REPOSITORY. +# -------------------------------------------------------------------------------------------------------------------- # + +push() { + echo "--- [GIT] PUSH: '${d_src}' -> '${GIT_REPO#https://}'" + _pushd "${d_src}" || exit 1 + + # Commit build files & push. + echo "Commit build files & push..." + ${git} add . \ + && ${git} commit -a -m "BUILD: ${ts}" \ + && ${git} push + + _popd || exit 1 +} + +# -------------------------------------------------------------------------------------------------------------------- # +# ------------------------------------------------< COMMON FUNCTIONS >------------------------------------------------ # +# -------------------------------------------------------------------------------------------------------------------- # + +# Pushd. +_pushd() { + command pushd "$@" > /dev/null || exit 1 +} + +# Popd. +_popd() { + command popd > /dev/null || exit 1 +} + +# Timestamp. +_timestamp() { + ${date} -u '+%Y-%m-%d %T' +} + +# -------------------------------------------------------------------------------------------------------------------- # +# -------------------------------------------------< INIT FUNCTIONS >------------------------------------------------- # +# -------------------------------------------------------------------------------------------------------------------- # + +init "$@"; exit 0 diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..6773b3b --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/bash -e + +bash -c "/build.sh $*" + +exit 0