From 423260bcde83930cc85b7aad9a98600fab25b1ec Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 5 Nov 2023 16:38:52 +0200 Subject: [PATCH] First version creating github action --- .gitignore | 1 + Dockerfile | 9 +++++ README.md | 57 +++++++++++++++++++++++++++ action.yml | 57 +++++++++++++++++++++++++++ entrypoint.sh | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 230 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 action.yml create mode 100755 entrypoint.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..757fee3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.idea \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8df19e1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM alpine:3.18.4 + +RUN apk update +RUN apk add --no-cache curl +RUN apk add --no-cache jq + +COPY entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..3f4e399 --- /dev/null +++ b/README.md @@ -0,0 +1,57 @@ +# Creating a release in Gitea + +This action will create a new release in the Gitea system using the API and output all debugging information to the log. +See from detail https://docs.gitea.com/api/1.20/#tag/repository/operation/repoCreateRelease + +## Inputs + +## `gitea_schema` +Gitea schema. + +## `gitea_host` +**Required** Gitea host. + +## `gitea_organization` +**Required** Gitea organization or user. + +## `gitea_repo` +**Required** Gitea repository. + +## `access_token` +**Required** Gitea access token for interacting with the API. + +## `release_body` +**Required** Option {body} in request to api. + +## `release_draft` +**Required** Option {draft} in request to api. + +## `release_name` +**Required** Option {name} in request to api. + +## `release_prerelease` +**Required** Option {prerelease} in request to api. + +## `release_tag_name` +**Required** Option {tag_name} in request to api. + +## `release_target_commitish` +**Required** Option {target_commitish} in request to api. + +## Example usage + +```yml +uses: actions/gitea_create_release_action@master +with: + gitea_schema: "https" + gitea_host: "gitea.example.org" + gitea_organization: "organization" + gitea_repo: "repository" + access_token: "${{ secrets.GITEA_ACCESS_TOKEN }}" + release_body: "" + release_draft: "true" + release_name: "release_name" + release_prerelease: "false" + release_tag_name: "1.0.0" + release_target_commitish: "" +``` \ No newline at end of file diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..8e4fede --- /dev/null +++ b/action.yml @@ -0,0 +1,57 @@ +name: "gitea release create" +description: "creating a new release through the API in the system gitea" +inputs: + gitea_schema: + description: "gitea schema" + default: "https" + gitea_host: + description: "gitea host" + required: true + gitea_organization: + description: "gitea organization or user" + required: true + gitea_repo: + description: "gitea repository" + required: true + access_token: + description: "access token" + required: true + release_body: + description: "option {body} in request to api" + required: true + default: "" + release_draft: + description: "option {draft} in request to api" + required: true + default: "true" + release_name: + description: "option {name} in request to api" + required: true + default: "" + release_prerelease: + description: "option {prerelease} in request to api" + required: true + default: "false" + release_tag_name: + description: "option {tag_name} in request to api" + required: true + default: "" + release_target_commitish: + description: "option {target_commitish} in request to api" + required: true + default: "" +runs: + using: "docker" + image: "Dockerfile" + args: + - ${{ inputs.gitea_schema }} + - ${{ inputs.gitea_host }} + - ${{ inputs.gitea_organization }} + - ${{ inputs.gitea_repo }} + - ${{ inputs.access_token }} + - ${{ inputs.release_body }} + - ${{ inputs.release_draft }} + - ${{ inputs.release_name }} + - ${{ inputs.release_prerelease }} + - ${{ inputs.release_tag_name }} + - ${{ inputs.release_target_commitish }} \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..c78b3cc --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,106 @@ +#!/bin/sh + +RED='\033[0;31m'; +GREEN='\033[1;32m'; +YELLOW='\033[1;33m'; +LITE_CYAN='\e[96m'; +NC='\033[0m'; + +if [ -z ${gitea_schema} ]; then + printf "${RED}FAILED${NC} \n" + printf "Error message: ${RED}Option {gitea_schema} is not set${NC} \n" + exit 1; +fi + +if [ ${gitea_schema} = '' ]; then + printf "${RED}FAILED${NC} \n" + printf "Error message: ${RED}Option {gitea_schema} must be a non-empty string${NC} \n" + exit 1; +fi + + +if [ -z ${gitea_host} ]; then + printf "${RED}FAILED${NC} \n" + printf "Error message: ${RED}Option {gitea_host} is not set${NC} \n" + exit 1; +fi + +if [ ${gitea_host} = '' ]; then + printf "${RED}FAILED${NC} \n" + printf "Error message: ${RED}Option {gitea_host} must be a non-empty string${NC} \n" + exit 1; +fi + + +if [ -z ${gitea_organization} ]; then + printf "${RED}FAILED${NC} \n" + printf "Error message: ${RED}Option {gitea_organization} is not set${NC} \n" + exit 1; +fi + +if [ ${gitea_organization} = '' ]; then + printf "${RED}FAILED${NC} \n" + printf "Error message: ${RED}Option {gitea_organization} must be a non-empty string${NC} \n" + exit 1; +fi + + +if [ -z ${gitea_repo} ]; then + printf "${RED}FAILED${NC} \n" + printf "Error message: ${RED}Option {gitea_repo} is not set${NC} \n" + exit 1; +fi + +if [ ${gitea_repo} = '' ]; then + printf "${RED}FAILED${NC} \n" + printf "Error message: ${RED}Option {gitea_repo} must be a non-empty string${NC} \n" + exit 1; +fi + + +if [ -z ${access_token} ]; then + printf "${RED}FAILED${NC} \n" + printf "Error message: ${RED}Option {access_token} is not set${NC} \n" + exit 1; +fi + +if [ ${access_token} = '' ]; then + printf "${RED}FAILED${NC} \n" + printf "Error message: ${RED}Option {access_token} must be a non-empty string${NC} \n" + exit 1; +fi + +printf "api request url=${YELLOW} ${gitea_schema}://${gitea_host}/api/v1/repos/${gitea_organization}/${gitea_repo}/releases ${NC} \n"; +printf "body=${YELLOW}${release_body}${NC} \n"; +printf "draft=${YELLOW}${release_draft}${NC} \n"; +printf "name=${YELLOW}${release_name}${NC} \n"; +printf "prerelease=${YELLOW}${release_prerelease}${NC} \n"; +printf "tag_name=${YELLOW}${release_tag_name}${NC} \n"; +printf "target_commitish=${YELLOW}${release_target_commitish}${NC} \n"; + +response=$( curl -X 'POST' \ + "${gitea_schema}://${gitea_host}/api/v1/repos/${gitea_organization}/${gitea_repo}/releases?access_token=${access_token}" \ + -H 'accept: application/json' \ + -H 'Content-Type: application/json' \ + -d "{ + \"body\": \"${release_body}\", + \"draft\": ${release_draft}, + \"name\": \"${release_name}\", + \"prerelease\": ${release_prerelease}, + \"tag_name\": \"${release_tag_name}\", + \"target_commitish\": \"${release_target_commitish}\" +}") + +id=$(echo $response | jq '.id'); +url=$(echo $response | jq '.html_url'); +message=$(echo $response | jq '.message'); + +if [ $id = 'null' ]; then + printf "${RED}FAILED${NC} \n" + printf "Create release error: Error message: ${RED}$message${NC} \n" + exit 1; +else + printf "${GREEN}SUCCESS${NC} \n" + printf "Created release: id: ${YELLOW}$id${NC} \nurl: ${YELLOW}$url${NC} \n" +fi +